@atlaskit/collab-provider 9.6.4 → 9.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/disconnected-reason-mapper.js +8 -17
- package/dist/cjs/errors/error-code-mapper.js +13 -12
- package/dist/cjs/errors/error-types.js +2 -95
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/provider/index.js +88 -69
- package/dist/cjs/types.js +1 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/disconnected-reason-mapper.js +2 -9
- package/dist/es2019/errors/error-code-mapper.js +2 -1
- package/dist/es2019/errors/error-types.js +0 -94
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/provider/index.js +77 -57
- package/dist/es2019/types.js +1 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/disconnected-reason-mapper.js +2 -9
- package/dist/esm/errors/error-code-mapper.js +2 -1
- package/dist/esm/errors/error-types.js +0 -94
- package/dist/esm/index.js +1 -1
- package/dist/esm/provider/index.js +88 -69
- package/dist/esm/types.js +1 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/channel.d.ts +2 -1
- package/dist/types/disconnected-reason-mapper.d.ts +1 -8
- package/dist/types/document/document-service.d.ts +3 -2
- package/dist/types/errors/error-code-mapper.d.ts +2 -1
- package/dist/types/errors/error-types.d.ts +0 -190
- package/dist/types/helpers/const.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/metadata/metadata-service.d.ts +1 -1
- package/dist/types/participants/participants-helper.d.ts +2 -6
- package/dist/types/participants/participants-service.d.ts +3 -2
- package/dist/types/participants/participants-state.d.ts +2 -1
- package/dist/types/participants/telepointers-helper.d.ts +2 -2
- package/dist/types/provider/commit-step.d.ts +2 -1
- package/dist/types/provider/index.d.ts +11 -5
- package/dist/types/socket-io-provider.d.ts +1 -1
- package/dist/types/types.d.ts +2 -149
- package/dist/types-ts4.5/channel.d.ts +2 -1
- package/dist/types-ts4.5/disconnected-reason-mapper.d.ts +1 -8
- package/dist/types-ts4.5/document/document-service.d.ts +3 -2
- package/dist/types-ts4.5/errors/error-code-mapper.d.ts +2 -1
- package/dist/types-ts4.5/errors/error-types.d.ts +0 -190
- package/dist/types-ts4.5/helpers/const.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +3 -3
- package/dist/types-ts4.5/metadata/metadata-service.d.ts +1 -1
- package/dist/types-ts4.5/participants/participants-helper.d.ts +2 -6
- package/dist/types-ts4.5/participants/participants-service.d.ts +3 -2
- package/dist/types-ts4.5/participants/participants-state.d.ts +2 -1
- package/dist/types-ts4.5/participants/telepointers-helper.d.ts +2 -2
- package/dist/types-ts4.5/provider/commit-step.d.ts +2 -1
- package/dist/types-ts4.5/provider/index.d.ts +11 -5
- package/dist/types-ts4.5/socket-io-provider.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +2 -149
- package/package.json +2 -1
- package/report.api.md +51 -392
- package/tmp/api-report-tmp.d.ts +51 -375
package/dist/cjs/version.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DisconnectReason } from '@atlaskit/editor-common/collab';
|
|
2
|
+
|
|
1
3
|
// See https://socket.io/docs/v3/client-socket-instance#disconnect for emitted reasons
|
|
2
4
|
export const socketIOReasons = {
|
|
3
5
|
IO_CLIENT_DISCONNECT: 'io client disconnect',
|
|
@@ -11,15 +13,6 @@ export const socketIOReasons = {
|
|
|
11
13
|
PING_TIMEOUT: 'ping timeout' // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
export let DisconnectReason = /*#__PURE__*/function (DisconnectReason) {
|
|
15
|
-
DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT";
|
|
16
|
-
DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT";
|
|
17
|
-
DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED";
|
|
18
|
-
DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR";
|
|
19
|
-
DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT";
|
|
20
|
-
DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT";
|
|
21
|
-
return DisconnectReason;
|
|
22
|
-
}({});
|
|
23
16
|
export const disconnectedReasonMapper = reason => {
|
|
24
17
|
switch (reason) {
|
|
25
18
|
case socketIOReasons.IO_CLIENT_DISCONNECT:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NCS_ERROR_CODE } from './error-types';
|
|
2
|
-
import { INTERNAL_ERROR_CODE
|
|
2
|
+
import { INTERNAL_ERROR_CODE } from './error-types';
|
|
3
|
+
import { PROVIDER_ERROR_CODE } from '@atlaskit/editor-common/collab';
|
|
3
4
|
|
|
4
5
|
/*
|
|
5
6
|
* Maps internal collab provider errors to an emitted error format
|
|
@@ -52,22 +52,6 @@ export let NCS_ERROR_CODE = /*#__PURE__*/function (NCS_ERROR_CODE) {
|
|
|
52
52
|
/**
|
|
53
53
|
* A union of all possible internal errors, that are mapped to another error if being emitted to the editor.
|
|
54
54
|
*/
|
|
55
|
-
// Emitted errors
|
|
56
|
-
export let PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
|
|
57
|
-
PROVIDER_ERROR_CODE["NO_PERMISSION_ERROR"] = "NO_PERMISSION_ERROR";
|
|
58
|
-
PROVIDER_ERROR_CODE["INVALID_USER_TOKEN"] = "INVALID_USER_TOKEN";
|
|
59
|
-
PROVIDER_ERROR_CODE["DOCUMENT_NOT_FOUND"] = "DOCUMENT_NOT_FOUND";
|
|
60
|
-
PROVIDER_ERROR_CODE["LOCKED"] = "LOCKED";
|
|
61
|
-
PROVIDER_ERROR_CODE["FAIL_TO_SAVE"] = "FAIL_TO_SAVE";
|
|
62
|
-
PROVIDER_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
|
|
63
|
-
PROVIDER_ERROR_CODE["INITIALISATION_ERROR"] = "INITIALISATION_ERROR";
|
|
64
|
-
PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE";
|
|
65
|
-
PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION";
|
|
66
|
-
PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR";
|
|
67
|
-
PROVIDER_ERROR_CODE["DOCUMENT_UPDATE_ERROR"] = "DOCUMENT_UPDATE_ERROR";
|
|
68
|
-
return PROVIDER_ERROR_CODE;
|
|
69
|
-
}({});
|
|
70
|
-
|
|
71
55
|
/*
|
|
72
56
|
* This is what a generic ProviderError type would look like:
|
|
73
57
|
* type ProviderError = {
|
|
@@ -83,84 +67,6 @@ export let PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
|
|
|
83
67
|
* reason?: string;
|
|
84
68
|
* }
|
|
85
69
|
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* This occurs when the provided user token is considered invalid for the given document ARI.
|
|
89
|
-
* It happens during initialisation of the provider.
|
|
90
|
-
* It could mean the document has been deleted (hence not found).
|
|
91
|
-
* @message Message returned to editor, i.e User does not have permissions to access this document or document is not found
|
|
92
|
-
* @recoverable It is recoverable, as we will try to refresh the token.
|
|
93
|
-
*/
|
|
94
|
-
/**
|
|
95
|
-
* Similiar to InsufficientEditingPermission, but the user token is invalid because it has expired or been revoked.
|
|
96
|
-
* It may also be an invalid token format.
|
|
97
|
-
* This error is given to the provider by NCS.
|
|
98
|
-
* @message Message returned to editor, i.e. The user token was invalid
|
|
99
|
-
* @recoverable It is recoverable, as we will try to refresh the token.
|
|
100
|
-
*/
|
|
101
|
-
/**
|
|
102
|
-
* Document not found error, thrown when the provider is unable to find a document with the given ARI and user token.
|
|
103
|
-
* It occurs during fetchCatchup, a function that fetches the latest document state during catchup.
|
|
104
|
-
* We need to recieve a 404 from the document service to throw this error.
|
|
105
|
-
* @message Message returned to editor, i.e. The requested document is not found
|
|
106
|
-
* @recoverable It is recoverable, as the provider can try again later.
|
|
107
|
-
*/
|
|
108
|
-
/**
|
|
109
|
-
* This error is thrown when the document is locked by another user.
|
|
110
|
-
* The error is passed to us by NCS.
|
|
111
|
-
* @message Message returned to editor, i.e. The document is currently not available, please try again later
|
|
112
|
-
* @recoverable It is recoverable, as the provider can try again later.
|
|
113
|
-
*/
|
|
114
|
-
/**
|
|
115
|
-
* This error is thrown when the provider is unable to save the document.
|
|
116
|
-
* This can happen when the connection to dynamoDB is lost, or when we do not have sufficient permissions (DYNAMO ERROR).
|
|
117
|
-
* This error is given to us by NCS.
|
|
118
|
-
* @message Message returned to editor, i.e. Collab service is not able to save changes
|
|
119
|
-
* @recoverable It is not recoverable, as we don't want the user to continue editing a document that is not being saved.
|
|
120
|
-
*/
|
|
121
|
-
/**
|
|
122
|
-
* This error is thrown when the provider is unable to restore the document.
|
|
123
|
-
* It occurs during onRestore, a function that restores the document to a previous version and reapplies unconfirmed steps.
|
|
124
|
-
* onRestore is called when page recovery has emitted an 'init' event on a page client is currently connected to.
|
|
125
|
-
* It could mean we failed to update the page metadata, or we failed to reapply unconfirmed steps.
|
|
126
|
-
* @message Message returned to editor, i.e. Collab service unable to restore document
|
|
127
|
-
* @recoverable It is not recoverable, as the provider has no further options after this.
|
|
128
|
-
* The user will need to refresh the page to try again.
|
|
129
|
-
*/
|
|
130
|
-
/**
|
|
131
|
-
* The initial document couldn't be loaded from the collab service.
|
|
132
|
-
* This error is given to us by NCS.
|
|
133
|
-
* It could indicate either a network issue, or an internal service error in NCS.
|
|
134
|
-
* @message Message returned to editor, i.e. The initial document couldn't be loaded from the collab service
|
|
135
|
-
* @recoverable It is not recoverable, as the provider cannot do anything to fix it.
|
|
136
|
-
* The user will need to refresh the page to try again.
|
|
137
|
-
*/
|
|
138
|
-
/**
|
|
139
|
-
* Couldn't reconnect to the collab service (NCS) due to network issues.
|
|
140
|
-
* 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.
|
|
141
|
-
* Fired upon a reconnection attempt error (from Socket.IO Manager)
|
|
142
|
-
* @message Message returned to editor, i.e. Couldn't reconnect to the collab service due to network issues
|
|
143
|
-
* @recoverable It is recoverable, as the provider will try to reconnect.
|
|
144
|
-
*/
|
|
145
|
-
/**
|
|
146
|
-
* This error is thrown when the provider has an invalid configuration.
|
|
147
|
-
* It could happen due to these errors from NCS:
|
|
148
|
-
* NAMESPACE_INVALID
|
|
149
|
-
INVALID_ACTIVATION_ID
|
|
150
|
-
INVALID_DOCUMENT_ARI
|
|
151
|
-
INVALID_CLOUD_ID
|
|
152
|
-
* @message Message returned to editor, i.e. Invalid provider configuration
|
|
153
|
-
* @recoverable It is not recoverable, as the provider cannot do anything to fix it.
|
|
154
|
-
* The service using the provider will need to fix the configuration.
|
|
155
|
-
*/
|
|
156
|
-
/**
|
|
157
|
-
* This error is thrown when the provider encounters an internal service error, not otherwise accounted for.
|
|
158
|
-
* @message Message returned to editor, i.e. Collab Provider experienced an unrecoverable error
|
|
159
|
-
* @recoverable It is not recoverable, as the provider cannot do anything to fix it.
|
|
160
|
-
*/
|
|
161
|
-
/**
|
|
162
|
-
* A union of all possible provider errors that can be emitted back to the editor.
|
|
163
|
-
*/
|
|
164
70
|
// Custom Errors
|
|
165
71
|
export class CustomError extends Error {
|
|
166
72
|
constructor(message, error, extraEventAttributes) {
|
package/dist/es2019/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Provider } from './provider';
|
|
2
|
-
export { PROVIDER_ERROR_CODE } from '
|
|
2
|
+
export { PROVIDER_ERROR_CODE } from '@atlaskit/editor-common/collab';
|
|
@@ -30,14 +30,39 @@ export class Provider extends Emitter {
|
|
|
30
30
|
* @param data - Event data to emit to subscribers
|
|
31
31
|
*/
|
|
32
32
|
_defineProperty(this, "emitCallback", (evt, data) => {
|
|
33
|
-
// When the provider is initialized early, we want the editor state
|
|
33
|
+
// When the provider is initialized early, we want to ensure the editor state exists after setup is called before emitting events
|
|
34
34
|
// to ensure that it is ready to listen to the events fired by NCS
|
|
35
35
|
if (this.isPreinitializing) {
|
|
36
|
-
this.
|
|
36
|
+
this.onSetupPromise.then(() => this.emit(evt, data));
|
|
37
37
|
} else {
|
|
38
38
|
this.emit(evt, data);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
+
/**
|
|
42
|
+
* Wrapper to update document and metadata.
|
|
43
|
+
* Catches and logs any errors thrown by document service's updateDocument and updateMetadata methods and destroys the provider in case of errors.
|
|
44
|
+
* Passing the document, metadata, version (either from the initial draft or from collab service)
|
|
45
|
+
*/
|
|
46
|
+
_defineProperty(this, "updateDocumentAndMetadata", ({
|
|
47
|
+
doc,
|
|
48
|
+
version,
|
|
49
|
+
metadata
|
|
50
|
+
}) => {
|
|
51
|
+
try {
|
|
52
|
+
this.documentService.updateDocument({
|
|
53
|
+
doc,
|
|
54
|
+
version,
|
|
55
|
+
metadata
|
|
56
|
+
});
|
|
57
|
+
this.metadataService.updateMetadata(metadata);
|
|
58
|
+
this.isProviderInitialized = true;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
var _this$analyticsHelper;
|
|
61
|
+
(_this$analyticsHelper = this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(e, 'Failed to update with the init document, destroying provider');
|
|
62
|
+
// Stop events and connections to step us trying to talk to the backend with an invalid state.
|
|
63
|
+
this.destroy();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
41
66
|
_defineProperty(this, "initializeChannel", () => {
|
|
42
67
|
this.emit('connecting', {
|
|
43
68
|
initial: true
|
|
@@ -66,22 +91,24 @@ export class Provider extends Emitter {
|
|
|
66
91
|
version,
|
|
67
92
|
metadata
|
|
68
93
|
} = this.initialDraft;
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
94
|
+
if (this.isPreinitializing) {
|
|
95
|
+
// When the provider is initialized early, we wait until setup is called with a defined getState before the document is updated to ensure that the editor state exists
|
|
96
|
+
// The `isPreinitializing` check is an extra precaution behind a FF - if the state is already resolved, onSetupPromise will resolve immediately
|
|
97
|
+
this.onSetupPromise.then(() => {
|
|
98
|
+
this.updateDocumentAndMetadata({
|
|
99
|
+
doc: document,
|
|
100
|
+
version,
|
|
101
|
+
metadata
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
this.updateDocumentAndMetadata({
|
|
72
106
|
doc: document,
|
|
73
107
|
version,
|
|
74
108
|
metadata
|
|
75
109
|
});
|
|
76
|
-
} catch (e) {
|
|
77
|
-
var _this$analyticsHelper;
|
|
78
|
-
(_this$analyticsHelper = this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(e, 'Failed to update the document on reconnect, destroying provider');
|
|
79
|
-
// Stop events and connections to step us trying to talk to the backend with an invalid state.
|
|
80
|
-
this.destroy();
|
|
81
110
|
}
|
|
82
|
-
this.metadataService.updateMetadata(metadata);
|
|
83
111
|
}
|
|
84
|
-
this.isProviderInitialized = true;
|
|
85
112
|
}
|
|
86
113
|
// If already initialized, `connected` means reconnected
|
|
87
114
|
if (initialized && this.disconnectedAt &&
|
|
@@ -97,20 +124,11 @@ export class Provider extends Emitter {
|
|
|
97
124
|
metadata
|
|
98
125
|
}) => {
|
|
99
126
|
// Initial document and version
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
this.metadataService.updateMetadata(metadata);
|
|
107
|
-
this.isProviderInitialized = true;
|
|
108
|
-
} catch (e) {
|
|
109
|
-
var _this$analyticsHelper2;
|
|
110
|
-
(_this$analyticsHelper2 = this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(e, 'Failed to update with the init document, destroying provider');
|
|
111
|
-
// Stop events and connections to step us trying to talk to the backend with an invalid state.
|
|
112
|
-
this.destroy();
|
|
113
|
-
}
|
|
127
|
+
this.updateDocumentAndMetadata({
|
|
128
|
+
doc,
|
|
129
|
+
version,
|
|
130
|
+
metadata
|
|
131
|
+
});
|
|
114
132
|
}).on('restore', this.documentService.onRestore).on('steps:added', this.documentService.onStepsAdded).on('metadata:changed', this.metadataService.onMetadataChanged).on('participant:telepointer', payload => this.participantsService.onParticipantTelepointer(payload, this.sessionId)).on('presence:joined', this.participantsService.onPresenceJoined).on('presence', this.participantsService.onPresence).on('participant:left', this.participantsService.onParticipantLeft).on('participant:updated', this.participantsService.onParticipantUpdated).on('disconnect', this.onDisconnected.bind(this)).on('error', this.onErrorHandled).on('status', this.namespaceService.onNamespaceStatusChanged).connect(shouldInitialize);
|
|
115
133
|
});
|
|
116
134
|
_defineProperty(this, "setUserId", id => {
|
|
@@ -134,13 +152,13 @@ export class Provider extends Emitter {
|
|
|
134
152
|
if (((_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.code) === NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED || ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.code) === NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS) {
|
|
135
153
|
this.documentService.onStepRejectedError();
|
|
136
154
|
} else {
|
|
137
|
-
var _this$
|
|
138
|
-
(_this$
|
|
155
|
+
var _this$analyticsHelper2;
|
|
156
|
+
(_this$analyticsHelper2 = this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(error, 'Error handled');
|
|
139
157
|
const mappedError = errorCodeMapper(error);
|
|
140
158
|
// Temporarily only emit errors to Confluence very intentionally because they will disconnect the collab provider
|
|
141
159
|
if (mappedError) {
|
|
142
|
-
var _this$
|
|
143
|
-
(_this$
|
|
160
|
+
var _this$analyticsHelper3;
|
|
161
|
+
(_this$analyticsHelper3 = this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(mappedError, 'Error emitted');
|
|
144
162
|
this.emitCallback('error', mappedError);
|
|
145
163
|
}
|
|
146
164
|
}
|
|
@@ -167,8 +185,8 @@ export class Provider extends Emitter {
|
|
|
167
185
|
try {
|
|
168
186
|
return await this.documentService.getCurrentState();
|
|
169
187
|
} catch (error) {
|
|
170
|
-
var _this$
|
|
171
|
-
(_this$
|
|
188
|
+
var _this$analyticsHelper4;
|
|
189
|
+
(_this$analyticsHelper4 = this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(error, 'Error while returning ADF version of current draft document');
|
|
172
190
|
throw new GetCurrentStateError('Error while returning the current state of the draft document', error); // Reject the promise so the consumer can react to it failing
|
|
173
191
|
}
|
|
174
192
|
});
|
|
@@ -181,8 +199,8 @@ export class Provider extends Emitter {
|
|
|
181
199
|
try {
|
|
182
200
|
return await this.documentService.getFinalAcknowledgedState();
|
|
183
201
|
} catch (error) {
|
|
184
|
-
var _this$
|
|
185
|
-
(_this$
|
|
202
|
+
var _this$analyticsHelper5;
|
|
203
|
+
(_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(error, 'Error while returning ADF version of the final draft document');
|
|
186
204
|
throw new GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', error); // Reject the promise so the consumer can react to it failing
|
|
187
205
|
}
|
|
188
206
|
});
|
|
@@ -212,8 +230,8 @@ export class Provider extends Emitter {
|
|
|
212
230
|
this.participantsService = new ParticipantsService(this.analyticsHelper, undefined, this.emitCallback, this.config.getUser, this.channel.broadcast, this.channel.sendPresenceJoined, this.getPresenceData, this.setUserId);
|
|
213
231
|
this.metadataService = new MetadataService(this.emitCallback, this.channel.sendMetadata);
|
|
214
232
|
this.documentService = new DocumentService(this.participantsService, this.analyticsHelper, this.channel.fetchCatchup, this.emitCallback, this.channel.broadcast, () => this.userId, this.onErrorHandled, this.metadataService, this.config.failedStepLimitBeforeCatchupOnPublish, this.config.enableErrorOnFailedDocumentApply);
|
|
215
|
-
this.
|
|
216
|
-
this.
|
|
233
|
+
this.onSetupPromise = new Promise(resolve => {
|
|
234
|
+
this.resolveOnSetupPromise = resolve;
|
|
217
235
|
});
|
|
218
236
|
this.namespaceService = new NamespaceService();
|
|
219
237
|
}
|
|
@@ -247,16 +265,12 @@ export class Provider extends Emitter {
|
|
|
247
265
|
}) {
|
|
248
266
|
this.checkForCookies();
|
|
249
267
|
try {
|
|
250
|
-
// if setup is called with no
|
|
268
|
+
// if setup is called with no getState and the initial draft is already provided
|
|
251
269
|
// set a flag to mark early provider setup
|
|
252
270
|
if (!getState && this.initialDraft) {
|
|
253
271
|
this.isPreinitializing = true;
|
|
254
272
|
}
|
|
255
273
|
if (getState) {
|
|
256
|
-
// if provider has already been initialized earlier, resolve the state once it is available
|
|
257
|
-
if (this.isPreinitializing) {
|
|
258
|
-
this.getStatePromiseResolve();
|
|
259
|
-
}
|
|
260
274
|
const collabPlugin = getState().plugins.find(p => p.key === 'collab$');
|
|
261
275
|
if (collabPlugin === undefined) {
|
|
262
276
|
throw new ProviderInitialisationError('Collab provider attempted to initialise, but Editor state is missing collab plugin');
|
|
@@ -267,14 +281,20 @@ export class Provider extends Emitter {
|
|
|
267
281
|
onSyncUpError,
|
|
268
282
|
clientId: this.clientId
|
|
269
283
|
});
|
|
284
|
+
|
|
285
|
+
// if provider has already been initialized earlier, resolve the setup promise once setup has been called with
|
|
286
|
+
// a defined getState (ie editor state is ready) AND after documentService sets the editor state
|
|
287
|
+
if (this.isPreinitializing) {
|
|
288
|
+
this.resolveOnSetupPromise();
|
|
289
|
+
}
|
|
270
290
|
}
|
|
271
291
|
if (!this.isChannelInitialized) {
|
|
272
292
|
this.initializeChannel();
|
|
273
293
|
this.isChannelInitialized = true;
|
|
274
294
|
}
|
|
275
295
|
} catch (initError) {
|
|
276
|
-
var _this$
|
|
277
|
-
(_this$
|
|
296
|
+
var _this$analyticsHelper6;
|
|
297
|
+
(_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(initError, 'Error while initialising the provider');
|
|
278
298
|
// Throw error so consumers are aware the initialisation failed when initialising themselves
|
|
279
299
|
throw new ProviderInitialisationError('Provider initialisation error', initError);
|
|
280
300
|
}
|
|
@@ -282,9 +302,9 @@ export class Provider extends Emitter {
|
|
|
282
302
|
}
|
|
283
303
|
checkForCookies() {
|
|
284
304
|
if (!global.navigator.cookieEnabled) {
|
|
285
|
-
var _this$
|
|
305
|
+
var _this$analyticsHelper7;
|
|
286
306
|
const initError = new ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
|
|
287
|
-
(_this$
|
|
307
|
+
(_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
|
|
288
308
|
throw new ProviderInitialisationError('Provider initialisation error - cookies disabled', initError);
|
|
289
309
|
}
|
|
290
310
|
}
|
|
@@ -318,8 +338,8 @@ export class Provider extends Emitter {
|
|
|
318
338
|
}
|
|
319
339
|
this.documentService.send(_tr, _oldState, newState);
|
|
320
340
|
} catch (error) {
|
|
321
|
-
var _this$
|
|
322
|
-
(_this$
|
|
341
|
+
var _this$analyticsHelper8;
|
|
342
|
+
(_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(error, 'Error while sending steps for a transaction');
|
|
323
343
|
throw new SendTransactionError('Error while sending steps for a transaction', error);
|
|
324
344
|
}
|
|
325
345
|
}
|
|
@@ -344,9 +364,9 @@ export class Provider extends Emitter {
|
|
|
344
364
|
this.channel.broadcast('participant:telepointer', payload, callback);
|
|
345
365
|
}
|
|
346
366
|
} catch (error) {
|
|
347
|
-
var _this$
|
|
367
|
+
var _this$analyticsHelper9;
|
|
348
368
|
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
349
|
-
(_this$
|
|
369
|
+
(_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while sending message - telepointer');
|
|
350
370
|
}
|
|
351
371
|
}
|
|
352
372
|
/**
|
|
@@ -378,8 +398,8 @@ export class Provider extends Emitter {
|
|
|
378
398
|
super.unsubscribeAll();
|
|
379
399
|
this.channel.disconnect();
|
|
380
400
|
} catch (error) {
|
|
381
|
-
var _this$
|
|
382
|
-
(_this$
|
|
401
|
+
var _this$analyticsHelper10;
|
|
402
|
+
(_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, 'Error while shutting down the collab provider');
|
|
383
403
|
throw new DestroyError('Error while shutting down the collab provider', error);
|
|
384
404
|
}
|
|
385
405
|
this.clearTimers();
|
|
@@ -397,8 +417,8 @@ export class Provider extends Emitter {
|
|
|
397
417
|
try {
|
|
398
418
|
this.metadataService.setTitle(title, broadcast);
|
|
399
419
|
} catch (error) {
|
|
400
|
-
var _this$
|
|
401
|
-
(_this$
|
|
420
|
+
var _this$analyticsHelper11;
|
|
421
|
+
(_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while setting title');
|
|
402
422
|
throw new SetTitleError('Error while setting title', error);
|
|
403
423
|
}
|
|
404
424
|
}
|
|
@@ -414,8 +434,8 @@ export class Provider extends Emitter {
|
|
|
414
434
|
try {
|
|
415
435
|
this.metadataService.setEditorWidth(editorWidth, broadcast);
|
|
416
436
|
} catch (error) {
|
|
417
|
-
var _this$
|
|
418
|
-
(_this$
|
|
437
|
+
var _this$analyticsHelper12;
|
|
438
|
+
(_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while setting editor width');
|
|
419
439
|
throw new SetEditorWidthError('Error while setting editor width', error);
|
|
420
440
|
}
|
|
421
441
|
}
|
|
@@ -429,8 +449,8 @@ export class Provider extends Emitter {
|
|
|
429
449
|
try {
|
|
430
450
|
this.metadataService.setMetadata(metadata);
|
|
431
451
|
} catch (error) {
|
|
432
|
-
var _this$
|
|
433
|
-
(_this$
|
|
452
|
+
var _this$analyticsHelper13;
|
|
453
|
+
(_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while setting metadata');
|
|
434
454
|
throw new SetMetadataError('Error while setting metadata', error);
|
|
435
455
|
}
|
|
436
456
|
}
|
package/dist/es2019/types.js
CHANGED
package/dist/es2019/version.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DisconnectReason } from '@atlaskit/editor-common/collab';
|
|
2
|
+
|
|
1
3
|
// See https://socket.io/docs/v3/client-socket-instance#disconnect for emitted reasons
|
|
2
4
|
export var socketIOReasons = {
|
|
3
5
|
IO_CLIENT_DISCONNECT: 'io client disconnect',
|
|
@@ -11,15 +13,6 @@ export var socketIOReasons = {
|
|
|
11
13
|
PING_TIMEOUT: 'ping timeout' // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
export var DisconnectReason = /*#__PURE__*/function (DisconnectReason) {
|
|
15
|
-
DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT";
|
|
16
|
-
DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT";
|
|
17
|
-
DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED";
|
|
18
|
-
DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR";
|
|
19
|
-
DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT";
|
|
20
|
-
DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT";
|
|
21
|
-
return DisconnectReason;
|
|
22
|
-
}({});
|
|
23
16
|
export var disconnectedReasonMapper = function disconnectedReasonMapper(reason) {
|
|
24
17
|
switch (reason) {
|
|
25
18
|
case socketIOReasons.IO_CLIENT_DISCONNECT:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NCS_ERROR_CODE } from './error-types';
|
|
2
|
-
import { INTERNAL_ERROR_CODE
|
|
2
|
+
import { INTERNAL_ERROR_CODE } from './error-types';
|
|
3
|
+
import { PROVIDER_ERROR_CODE } from '@atlaskit/editor-common/collab';
|
|
3
4
|
|
|
4
5
|
/*
|
|
5
6
|
* Maps internal collab provider errors to an emitted error format
|
|
@@ -61,22 +61,6 @@ export var NCS_ERROR_CODE = /*#__PURE__*/function (NCS_ERROR_CODE) {
|
|
|
61
61
|
/**
|
|
62
62
|
* A union of all possible internal errors, that are mapped to another error if being emitted to the editor.
|
|
63
63
|
*/
|
|
64
|
-
// Emitted errors
|
|
65
|
-
export var PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
|
|
66
|
-
PROVIDER_ERROR_CODE["NO_PERMISSION_ERROR"] = "NO_PERMISSION_ERROR";
|
|
67
|
-
PROVIDER_ERROR_CODE["INVALID_USER_TOKEN"] = "INVALID_USER_TOKEN";
|
|
68
|
-
PROVIDER_ERROR_CODE["DOCUMENT_NOT_FOUND"] = "DOCUMENT_NOT_FOUND";
|
|
69
|
-
PROVIDER_ERROR_CODE["LOCKED"] = "LOCKED";
|
|
70
|
-
PROVIDER_ERROR_CODE["FAIL_TO_SAVE"] = "FAIL_TO_SAVE";
|
|
71
|
-
PROVIDER_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
|
|
72
|
-
PROVIDER_ERROR_CODE["INITIALISATION_ERROR"] = "INITIALISATION_ERROR";
|
|
73
|
-
PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE";
|
|
74
|
-
PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION";
|
|
75
|
-
PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR";
|
|
76
|
-
PROVIDER_ERROR_CODE["DOCUMENT_UPDATE_ERROR"] = "DOCUMENT_UPDATE_ERROR";
|
|
77
|
-
return PROVIDER_ERROR_CODE;
|
|
78
|
-
}({});
|
|
79
|
-
|
|
80
64
|
/*
|
|
81
65
|
* This is what a generic ProviderError type would look like:
|
|
82
66
|
* type ProviderError = {
|
|
@@ -92,84 +76,6 @@ export var PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
|
|
|
92
76
|
* reason?: string;
|
|
93
77
|
* }
|
|
94
78
|
*/
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* This occurs when the provided user token is considered invalid for the given document ARI.
|
|
98
|
-
* It happens during initialisation of the provider.
|
|
99
|
-
* It could mean the document has been deleted (hence not found).
|
|
100
|
-
* @message Message returned to editor, i.e User does not have permissions to access this document or document is not found
|
|
101
|
-
* @recoverable It is recoverable, as we will try to refresh the token.
|
|
102
|
-
*/
|
|
103
|
-
/**
|
|
104
|
-
* Similiar to InsufficientEditingPermission, but the user token is invalid because it has expired or been revoked.
|
|
105
|
-
* It may also be an invalid token format.
|
|
106
|
-
* This error is given to the provider by NCS.
|
|
107
|
-
* @message Message returned to editor, i.e. The user token was invalid
|
|
108
|
-
* @recoverable It is recoverable, as we will try to refresh the token.
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* Document not found error, thrown when the provider is unable to find a document with the given ARI and user token.
|
|
112
|
-
* It occurs during fetchCatchup, a function that fetches the latest document state during catchup.
|
|
113
|
-
* We need to recieve a 404 from the document service to throw this error.
|
|
114
|
-
* @message Message returned to editor, i.e. The requested document is not found
|
|
115
|
-
* @recoverable It is recoverable, as the provider can try again later.
|
|
116
|
-
*/
|
|
117
|
-
/**
|
|
118
|
-
* This error is thrown when the document is locked by another user.
|
|
119
|
-
* The error is passed to us by NCS.
|
|
120
|
-
* @message Message returned to editor, i.e. The document is currently not available, please try again later
|
|
121
|
-
* @recoverable It is recoverable, as the provider can try again later.
|
|
122
|
-
*/
|
|
123
|
-
/**
|
|
124
|
-
* This error is thrown when the provider is unable to save the document.
|
|
125
|
-
* This can happen when the connection to dynamoDB is lost, or when we do not have sufficient permissions (DYNAMO ERROR).
|
|
126
|
-
* This error is given to us by NCS.
|
|
127
|
-
* @message Message returned to editor, i.e. Collab service is not able to save changes
|
|
128
|
-
* @recoverable It is not recoverable, as we don't want the user to continue editing a document that is not being saved.
|
|
129
|
-
*/
|
|
130
|
-
/**
|
|
131
|
-
* This error is thrown when the provider is unable to restore the document.
|
|
132
|
-
* It occurs during onRestore, a function that restores the document to a previous version and reapplies unconfirmed steps.
|
|
133
|
-
* onRestore is called when page recovery has emitted an 'init' event on a page client is currently connected to.
|
|
134
|
-
* It could mean we failed to update the page metadata, or we failed to reapply unconfirmed steps.
|
|
135
|
-
* @message Message returned to editor, i.e. Collab service unable to restore document
|
|
136
|
-
* @recoverable It is not recoverable, as the provider has no further options after this.
|
|
137
|
-
* The user will need to refresh the page to try again.
|
|
138
|
-
*/
|
|
139
|
-
/**
|
|
140
|
-
* The initial document couldn't be loaded from the collab service.
|
|
141
|
-
* This error is given to us by NCS.
|
|
142
|
-
* It could indicate either a network issue, or an internal service error in NCS.
|
|
143
|
-
* @message Message returned to editor, i.e. The initial document couldn't be loaded from the collab service
|
|
144
|
-
* @recoverable It is not recoverable, as the provider cannot do anything to fix it.
|
|
145
|
-
* The user will need to refresh the page to try again.
|
|
146
|
-
*/
|
|
147
|
-
/**
|
|
148
|
-
* Couldn't reconnect to the collab service (NCS) due to network issues.
|
|
149
|
-
* 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.
|
|
150
|
-
* Fired upon a reconnection attempt error (from Socket.IO Manager)
|
|
151
|
-
* @message Message returned to editor, i.e. Couldn't reconnect to the collab service due to network issues
|
|
152
|
-
* @recoverable It is recoverable, as the provider will try to reconnect.
|
|
153
|
-
*/
|
|
154
|
-
/**
|
|
155
|
-
* This error is thrown when the provider has an invalid configuration.
|
|
156
|
-
* It could happen due to these errors from NCS:
|
|
157
|
-
* NAMESPACE_INVALID
|
|
158
|
-
INVALID_ACTIVATION_ID
|
|
159
|
-
INVALID_DOCUMENT_ARI
|
|
160
|
-
INVALID_CLOUD_ID
|
|
161
|
-
* @message Message returned to editor, i.e. Invalid provider configuration
|
|
162
|
-
* @recoverable It is not recoverable, as the provider cannot do anything to fix it.
|
|
163
|
-
* The service using the provider will need to fix the configuration.
|
|
164
|
-
*/
|
|
165
|
-
/**
|
|
166
|
-
* This error is thrown when the provider encounters an internal service error, not otherwise accounted for.
|
|
167
|
-
* @message Message returned to editor, i.e. Collab Provider experienced an unrecoverable error
|
|
168
|
-
* @recoverable It is not recoverable, as the provider cannot do anything to fix it.
|
|
169
|
-
*/
|
|
170
|
-
/**
|
|
171
|
-
* A union of all possible provider errors that can be emitted back to the editor.
|
|
172
|
-
*/
|
|
173
79
|
// Custom Errors
|
|
174
80
|
export var CustomError = /*#__PURE__*/function (_Error) {
|
|
175
81
|
_inherits(CustomError, _Error);
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Provider } from './provider';
|
|
2
|
-
export { PROVIDER_ERROR_CODE } from '
|
|
2
|
+
export { PROVIDER_ERROR_CODE } from '@atlaskit/editor-common/collab';
|