@atlaskit/collab-provider 9.1.0 → 9.2.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.
@@ -23,6 +23,7 @@ import { ParticipantsService } from '../participants/participants-service';
23
23
  import { errorCodeMapper } from '../errors/error-code-mapper';
24
24
  var logger = createLogger('Provider', 'black');
25
25
  var OUT_OF_SYNC_PERIOD = 3 * 1000; // 3 seconds
26
+ var PRELOAD_DRAFT_SYNC_PERIOD = 15 * 1000; // 15 seconds
26
27
 
27
28
  export var MAX_STEP_REJECTED_ERROR = 15;
28
29
  export var Provider = /*#__PURE__*/function (_Emitter) {
@@ -67,20 +68,27 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
67
68
  sid: sid,
68
69
  initial: !initialized
69
70
  });
70
- // If initial draft is already present and the channel is initialized,
71
- // fire the provider's init event with initial draft document and version
71
+
72
+ // Early initialization with initial draft passed via provider
72
73
  if (_this.initialDraft && initialized && !_this.isProviderInitialized) {
73
- var _this$initialDraft = _this.initialDraft,
74
- document = _this$initialDraft.document,
75
- version = _this$initialDraft.version,
76
- metadata = _this$initialDraft.metadata;
77
- // Initial document, version, metadata from initial draft
78
- _this.documentService.updateDocument({
79
- doc: document,
80
- version: version,
81
- metadata: metadata
82
- });
83
- _this.metadataService.updateMetadata(metadata);
74
+ // Call catchup if the draft has become stale since being passed to provider
75
+ if (_this.isDraftTimestampStale()) {
76
+ _this.documentService.throttledCatchup();
77
+ }
78
+ // If the initial draft is already up to date, update the document with that of the initial draft
79
+ else {
80
+ var _this$initialDraft = _this.initialDraft,
81
+ document = _this$initialDraft.document,
82
+ version = _this$initialDraft.version,
83
+ metadata = _this$initialDraft.metadata;
84
+ // Initial document, version, metadata from initial draft
85
+ _this.documentService.updateDocument({
86
+ doc: document,
87
+ version: version,
88
+ metadata: metadata
89
+ });
90
+ _this.metadataService.updateMetadata(metadata);
91
+ }
84
92
  _this.isProviderInitialized = true;
85
93
  }
86
94
  // If already initialized, `connected` means reconnected
@@ -308,6 +316,21 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
308
316
  }
309
317
  }
310
318
 
319
+ /**
320
+ * Checks the provider's initial draft timestamp to determine if it is stale.
321
+ * Returns true only if the time elapsed since the draft timestamp is greater than or
322
+ * equal to a predetermined timeout. Returns false in all other cases.
323
+ */
324
+ }, {
325
+ key: "isDraftTimestampStale",
326
+ value: function isDraftTimestampStale() {
327
+ var _this$initialDraft2;
328
+ if (!((_this$initialDraft2 = this.initialDraft) !== null && _this$initialDraft2 !== void 0 && _this$initialDraft2.timestamp)) {
329
+ return false;
330
+ }
331
+ return Date.now() - this.initialDraft.timestamp >= PRELOAD_DRAFT_SYNC_PERIOD;
332
+ }
333
+
311
334
  /**
312
335
  * Send steps from transaction to NCS (and as a consequence to other participants), called from the collab-edit plugin in the editor
313
336
  * @param {Transaction} _tr Deprecated, included to keep API consistent with Synchrony provider
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/collab-provider";
2
- export var version = "9.1.0";
2
+ export var version = "9.2.1";
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": "9.1.0",
3
+ "version": "9.2.1",
4
4
  "sideEffects": false
5
5
  }
@@ -192,7 +192,7 @@ type SendStepsRetryAnalyticsEvent = {
192
192
  eventAction: EVENT_ACTION.SEND_STEPS_RETRY;
193
193
  attributes: {
194
194
  documentAri: string;
195
- eventStatus: EVENT_STATUS.SUCCESS;
195
+ eventStatus: EVENT_STATUS.INFO;
196
196
  count: number;
197
197
  };
198
198
  };
@@ -200,7 +200,7 @@ type CatchupAfterMaxSendStepsRetryAnalyticsEvent = {
200
200
  eventAction: EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY;
201
201
  attributes: {
202
202
  documentAri: string;
203
- eventStatus: EVENT_STATUS.SUCCESS;
203
+ eventStatus: EVENT_STATUS.INFO;
204
204
  };
205
205
  };
206
206
  export type ActionAnalyticsEvent = AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ReInitDocFailAnalyticsEvent | ReInitDocSuccessAnalyticsEvent | ConnectionSuccessAnalyticsEvent | ConnectionFailureAnalyticsEvent | CatchUpSuccessAnalyticsEvent | CatchUpFailureAnalyticsEvent | DocumentInitSuccessAnalyticsEvent | UpdateParticipantsSuccessAnalyticsEvent | CommitUnconfirmedStepsSuccessAnalyticsEvent | CommitUnconfirmedStepsFailureAnalyticsEvent | PublishPageSuccessAnalyticsEvent | PublishPageFailureAnalyticsEvent | GetCurrentStateSuccessAnalyticsEvent | GetCurrentStateFailureAnalyticsEvent | InvalidateTokenAnalyticsEvent | SendStepsRetryAnalyticsEvent | CatchupAfterMaxSendStepsRetryAnalyticsEvent | CatchUpDroppedStepsEvent;
@@ -1,5 +1,12 @@
1
1
  import type { ProductInformation } from '../types';
2
+ import type { Step as ProseMirrorStep } from 'prosemirror-transform';
2
3
  export declare const createLogger: (prefix: string, color?: string) => (msg: string, data?: any) => void;
3
4
  export declare function sleep(ms: number): Promise<unknown>;
4
5
  export declare const getProduct: (productInfo?: ProductInformation) => string;
5
6
  export declare const getSubProduct: (productInfo?: ProductInformation) => string;
7
+ export type UGCFreeStepDetails = {
8
+ type: string;
9
+ contentTypes: string;
10
+ stepSizeInBytes?: number;
11
+ };
12
+ export declare const getStepUGCFreeDetails: (step: ProseMirrorStep) => UGCFreeStepDetails;
@@ -59,6 +59,12 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
59
59
  onSyncUpError?: SyncUpErrorFunction;
60
60
  }): this;
61
61
  private checkForCookies;
62
+ /**
63
+ * Checks the provider's initial draft timestamp to determine if it is stale.
64
+ * Returns true only if the time elapsed since the draft timestamp is greater than or
65
+ * equal to a predetermined timeout. Returns false in all other cases.
66
+ */
67
+ private isDraftTimestampStale;
62
68
  /**
63
69
  * Send steps from transaction to NCS (and as a consequence to other participants), called from the collab-edit plugin in the editor
64
70
  * @param {Transaction} _tr Deprecated, included to keep API consistent with Synchrony provider
@@ -61,6 +61,7 @@ export interface InitialDraft {
61
61
  document: JSONDocNode;
62
62
  version: number;
63
63
  metadata?: Metadata;
64
+ timestamp?: number;
64
65
  }
65
66
  export interface Config {
66
67
  url: string;
@@ -192,7 +192,7 @@ type SendStepsRetryAnalyticsEvent = {
192
192
  eventAction: EVENT_ACTION.SEND_STEPS_RETRY;
193
193
  attributes: {
194
194
  documentAri: string;
195
- eventStatus: EVENT_STATUS.SUCCESS;
195
+ eventStatus: EVENT_STATUS.INFO;
196
196
  count: number;
197
197
  };
198
198
  };
@@ -200,7 +200,7 @@ type CatchupAfterMaxSendStepsRetryAnalyticsEvent = {
200
200
  eventAction: EVENT_ACTION.CATCHUP_AFTER_MAX_SEND_STEPS_RETRY;
201
201
  attributes: {
202
202
  documentAri: string;
203
- eventStatus: EVENT_STATUS.SUCCESS;
203
+ eventStatus: EVENT_STATUS.INFO;
204
204
  };
205
205
  };
206
206
  export type ActionAnalyticsEvent = AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ReInitDocFailAnalyticsEvent | ReInitDocSuccessAnalyticsEvent | ConnectionSuccessAnalyticsEvent | ConnectionFailureAnalyticsEvent | CatchUpSuccessAnalyticsEvent | CatchUpFailureAnalyticsEvent | DocumentInitSuccessAnalyticsEvent | UpdateParticipantsSuccessAnalyticsEvent | CommitUnconfirmedStepsSuccessAnalyticsEvent | CommitUnconfirmedStepsFailureAnalyticsEvent | PublishPageSuccessAnalyticsEvent | PublishPageFailureAnalyticsEvent | GetCurrentStateSuccessAnalyticsEvent | GetCurrentStateFailureAnalyticsEvent | InvalidateTokenAnalyticsEvent | SendStepsRetryAnalyticsEvent | CatchupAfterMaxSendStepsRetryAnalyticsEvent | CatchUpDroppedStepsEvent;
@@ -1,5 +1,12 @@
1
1
  import type { ProductInformation } from '../types';
2
+ import type { Step as ProseMirrorStep } from 'prosemirror-transform';
2
3
  export declare const createLogger: (prefix: string, color?: string) => (msg: string, data?: any) => void;
3
4
  export declare function sleep(ms: number): Promise<unknown>;
4
5
  export declare const getProduct: (productInfo?: ProductInformation) => string;
5
6
  export declare const getSubProduct: (productInfo?: ProductInformation) => string;
7
+ export type UGCFreeStepDetails = {
8
+ type: string;
9
+ contentTypes: string;
10
+ stepSizeInBytes?: number;
11
+ };
12
+ export declare const getStepUGCFreeDetails: (step: ProseMirrorStep) => UGCFreeStepDetails;
@@ -59,6 +59,12 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
59
59
  onSyncUpError?: SyncUpErrorFunction;
60
60
  }): this;
61
61
  private checkForCookies;
62
+ /**
63
+ * Checks the provider's initial draft timestamp to determine if it is stale.
64
+ * Returns true only if the time elapsed since the draft timestamp is greater than or
65
+ * equal to a predetermined timeout. Returns false in all other cases.
66
+ */
67
+ private isDraftTimestampStale;
62
68
  /**
63
69
  * Send steps from transaction to NCS (and as a consequence to other participants), called from the collab-edit plugin in the editor
64
70
  * @param {Transaction} _tr Deprecated, included to keep API consistent with Synchrony provider
@@ -61,6 +61,7 @@ export interface InitialDraft {
61
61
  document: JSONDocNode;
62
62
  version: number;
63
63
  metadata?: Metadata;
64
+ timestamp?: number;
64
65
  }
65
66
  export interface Config {
66
67
  url: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "9.1.0",
3
+ "version": "9.2.1",
4
4
  "description": "A provider for collaborative editing.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,7 +25,7 @@
25
25
  "atlassian": {
26
26
  "team": "Editor Services",
27
27
  "inPublicMirror": true,
28
- "releaseModel": "scheduled"
28
+ "releaseModel": "continuous"
29
29
  },
30
30
  "af:exports": {
31
31
  ".": "./src/index.ts",
@@ -63,7 +63,7 @@
63
63
  "devDependencies": {
64
64
  "@atlaskit/adf-schema": "^25.8.0",
65
65
  "@atlaskit/analytics-listeners": "^8.7.0",
66
- "@atlaskit/editor-test-helpers": "^18.5.0",
66
+ "@atlaskit/editor-test-helpers": "^18.6.0",
67
67
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
68
68
  "@types/prosemirror-model": "^1.11.0",
69
69
  "@types/prosemirror-state": "^1.2.0",
package/report.api.md CHANGED
@@ -354,6 +354,8 @@ interface InitialDraft {
354
354
  // (undocumented)
355
355
  metadata?: Metadata_2;
356
356
  // (undocumented)
357
+ timestamp?: number;
358
+ // (undocumented)
357
359
  version: number;
358
360
  }
359
361