@atlaskit/editor-card-provider 8.1.36 → 8.2.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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/provider.js +2 -2
- package/dist/cjs/smart-card-local-cache-client.js +19 -91
- package/dist/es2019/provider.js +2 -2
- package/dist/es2019/smart-card-local-cache-client.js +17 -87
- package/dist/esm/provider.js +2 -2
- package/dist/esm/smart-card-local-cache-client.js +19 -91
- package/dist/types/smart-card-local-cache-client.d.ts +1 -6
- package/package.json +3 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-card-provider
|
|
2
2
|
|
|
3
|
+
## 8.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`771ebfec9f843`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/771ebfec9f843) -
|
|
8
|
+
Remove the platform_smartlink_document_cache gate and its session-storage fallback. Smart Link
|
|
9
|
+
responses remain cached within the current document.
|
|
10
|
+
|
|
11
|
+
## 8.1.37
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 8.1.36
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/cjs/provider.js
CHANGED
|
@@ -293,12 +293,12 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function (_No
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
// if parent class NodeDataProvider has cached the network request for the node
|
|
296
|
-
// we can skip fetching the data async and updating the
|
|
296
|
+
// we can skip fetching the data async and updating the document cache
|
|
297
297
|
if (isResolvedCachedResponse && this.getCacheStatusForNode(jsonNode) === 'network') {
|
|
298
298
|
return;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
// fetch the latest data async and update the
|
|
301
|
+
// fetch the latest data async and update the document cache
|
|
302
302
|
this.getDataAsync(node, function (payload) {
|
|
303
303
|
var response = payload.data;
|
|
304
304
|
if (!payload.error && response !== null && response !== void 0 && response.meta) {
|
|
@@ -8,36 +8,22 @@ exports.SmartCardLocalCacheClient = void 0;
|
|
|
8
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _StorageClient = require("@atlaskit/frontend-utilities/StorageClient");
|
|
12
|
-
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
13
|
-
var SMART_CARD_CACHE_CLIENT_KEY = 'smart-card-url-data';
|
|
14
|
-
var SMART_CARD_CACHE_KEY = 'response-cache';
|
|
15
11
|
var SMART_CARD_CACHE_DEFAULT_MAX_ITEMS = 100;
|
|
16
12
|
/**
|
|
17
13
|
* Singleton cache client for smart link responses shared within the current document.
|
|
18
|
-
* Session storage remains available only for the document-cache gate's control cohort.
|
|
19
14
|
*/
|
|
20
15
|
var SmartCardLocalCacheClient = exports.SmartCardLocalCacheClient = /*#__PURE__*/function () {
|
|
21
16
|
function SmartCardLocalCacheClient() {
|
|
22
17
|
var _this = this;
|
|
23
18
|
var maxItems = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SMART_CARD_CACHE_DEFAULT_MAX_ITEMS;
|
|
24
19
|
(0, _classCallCheck2.default)(this, SmartCardLocalCacheClient);
|
|
25
|
-
(0, _defineProperty2.default)(this, "storageClient", new _StorageClient.StorageClient(SMART_CARD_CACHE_CLIENT_KEY, {
|
|
26
|
-
storageEngine: 'sessionStorage'
|
|
27
|
-
}));
|
|
28
20
|
(0, _defineProperty2.default)(this, "documentCache", {});
|
|
29
|
-
(0, _defineProperty2.default)(this, "pendingWrite", false);
|
|
30
21
|
/**
|
|
31
22
|
* Retrieves the entire cache object from memory
|
|
32
23
|
* @returns The entire cache object
|
|
33
24
|
*/
|
|
34
25
|
(0, _defineProperty2.default)(this, "getCache", function () {
|
|
35
|
-
|
|
36
|
-
// Keep restored session data out of this cache if the gate changes after initialization.
|
|
37
|
-
return _this.documentCache;
|
|
38
|
-
} else {
|
|
39
|
-
return _this.memoryCache;
|
|
40
|
-
}
|
|
26
|
+
return _this.documentCache;
|
|
41
27
|
});
|
|
42
28
|
/**
|
|
43
29
|
* Caches the SmartLinkResponse against the provided url
|
|
@@ -45,58 +31,20 @@ var SmartCardLocalCacheClient = exports.SmartCardLocalCacheClient = /*#__PURE__*
|
|
|
45
31
|
* @param response The SmartLinkResponse to be cached
|
|
46
32
|
*/
|
|
47
33
|
(0, _defineProperty2.default)(this, "setItem", function (url, response) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
// Add or update the item in the cache with current timestamp
|
|
66
|
-
_this.memoryCache[url] = {
|
|
67
|
-
data: response,
|
|
68
|
-
timestamp: Date.now()
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// Apply FIFO behavior if cache exceeds maxItems
|
|
72
|
-
var _cacheKeys = Object.keys(_this.memoryCache);
|
|
73
|
-
if (_cacheKeys.length > _this.maxItems) {
|
|
74
|
-
// Sort keys by timestamp (oldest first) and remove the oldest items
|
|
75
|
-
var _sortedKeys = _cacheKeys.sort(function (a, b) {
|
|
76
|
-
return _this.memoryCache[a].timestamp - _this.memoryCache[b].timestamp;
|
|
77
|
-
});
|
|
78
|
-
var _itemsToRemove = _cacheKeys.length - _this.maxItems;
|
|
79
|
-
var _keysToRemove = _sortedKeys.slice(0, _itemsToRemove);
|
|
80
|
-
_keysToRemove.forEach(function (key) {
|
|
81
|
-
delete _this.memoryCache[key];
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Write through to storage asynchronously (non-blocking)
|
|
86
|
-
// Debounced to batch multiple rapid calls into a single write
|
|
87
|
-
if (!_this.pendingWrite) {
|
|
88
|
-
_this.pendingWrite = true;
|
|
89
|
-
queueMicrotask(function () {
|
|
90
|
-
try {
|
|
91
|
-
_this.storageClient.setItemWithExpiry(SMART_CARD_CACHE_KEY, JSON.stringify(_this.memoryCache));
|
|
92
|
-
} catch (_) {
|
|
93
|
-
// Ignore storage write errors (e.g. quota exceeded) to prevent blocking future writes
|
|
94
|
-
// Cache will still function in-memory for the session, but won't persist
|
|
95
|
-
} finally {
|
|
96
|
-
_this.pendingWrite = false;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
34
|
+
_this.documentCache[url] = {
|
|
35
|
+
data: response,
|
|
36
|
+
timestamp: Date.now()
|
|
37
|
+
};
|
|
38
|
+
var cacheKeys = Object.keys(_this.documentCache);
|
|
39
|
+
if (cacheKeys.length > _this.maxItems) {
|
|
40
|
+
var sortedKeys = cacheKeys.sort(function (a, b) {
|
|
41
|
+
return _this.documentCache[a].timestamp - _this.documentCache[b].timestamp;
|
|
42
|
+
});
|
|
43
|
+
var itemsToRemove = cacheKeys.length - _this.maxItems;
|
|
44
|
+
var keysToRemove = sortedKeys.slice(0, itemsToRemove);
|
|
45
|
+
keysToRemove.forEach(function (key) {
|
|
46
|
+
delete _this.documentCache[key];
|
|
47
|
+
});
|
|
100
48
|
}
|
|
101
49
|
});
|
|
102
50
|
/**
|
|
@@ -105,17 +53,11 @@ var SmartCardLocalCacheClient = exports.SmartCardLocalCacheClient = /*#__PURE__*
|
|
|
105
53
|
* @returns The cached SmartLinkResponse if it exists, else undefined
|
|
106
54
|
*/
|
|
107
55
|
(0, _defineProperty2.default)(this, "getItem", function (url) {
|
|
56
|
+
var _this$documentCache$u;
|
|
108
57
|
if (!url) {
|
|
109
58
|
return;
|
|
110
59
|
}
|
|
111
|
-
|
|
112
|
-
var _this$documentCache$u;
|
|
113
|
-
return (_this$documentCache$u = _this.documentCache[url]) === null || _this$documentCache$u === void 0 ? void 0 : _this$documentCache$u.data;
|
|
114
|
-
} else {
|
|
115
|
-
var _this$memoryCache;
|
|
116
|
-
var response = (_this$memoryCache = _this.memoryCache) === null || _this$memoryCache === void 0 || (_this$memoryCache = _this$memoryCache[url]) === null || _this$memoryCache === void 0 ? void 0 : _this$memoryCache.data;
|
|
117
|
-
return response;
|
|
118
|
-
}
|
|
60
|
+
return (_this$documentCache$u = _this.documentCache[url]) === null || _this$documentCache$u === void 0 ? void 0 : _this$documentCache$u.data;
|
|
119
61
|
});
|
|
120
62
|
/**
|
|
121
63
|
* Checks if a cached entry exists for the provided url
|
|
@@ -123,28 +65,14 @@ var SmartCardLocalCacheClient = exports.SmartCardLocalCacheClient = /*#__PURE__*
|
|
|
123
65
|
* @returns True if a cached entry exists, else false
|
|
124
66
|
*/
|
|
125
67
|
(0, _defineProperty2.default)(this, "isUrlInCache", function (url) {
|
|
126
|
-
|
|
127
|
-
return url in _this.documentCache;
|
|
128
|
-
} else {
|
|
129
|
-
return url in _this.memoryCache;
|
|
130
|
-
}
|
|
68
|
+
return url in _this.documentCache;
|
|
131
69
|
});
|
|
132
70
|
this.maxItems = maxItems;
|
|
133
|
-
if ((0, _fg.fg)('platform_smartlink_document_cache')) {
|
|
134
|
-
this.memoryCache = {};
|
|
135
|
-
} else {
|
|
136
|
-
// Load cache from storage into memory on instantiation
|
|
137
|
-
var stored = this.storageClient.getItem(SMART_CARD_CACHE_KEY, {
|
|
138
|
-
useExpiredItem: true
|
|
139
|
-
});
|
|
140
|
-
this.memoryCache = stored ? JSON.parse(stored) : {};
|
|
141
|
-
}
|
|
142
71
|
}
|
|
143
72
|
|
|
144
73
|
/**
|
|
145
74
|
* Gets the singleton instance of SmartCardLocalCacheClient.
|
|
146
|
-
* This ensures all callers share the same in-memory cache
|
|
147
|
-
* race conditions when multiple instances write to the same storage key.
|
|
75
|
+
* This ensures all callers share the same in-memory cache.
|
|
148
76
|
* @param maxItems Maximum number of items to store in the cache (only used on first instantiation)
|
|
149
77
|
* @returns The singleton instance
|
|
150
78
|
*/
|
package/dist/es2019/provider.js
CHANGED
|
@@ -208,12 +208,12 @@ export class EditorCardProvider extends NodeDataProvider {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
// if parent class NodeDataProvider has cached the network request for the node
|
|
211
|
-
// we can skip fetching the data async and updating the
|
|
211
|
+
// we can skip fetching the data async and updating the document cache
|
|
212
212
|
if (isResolvedCachedResponse && this.getCacheStatusForNode(jsonNode) === 'network') {
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
// fetch the latest data async and update the
|
|
216
|
+
// fetch the latest data async and update the document cache
|
|
217
217
|
this.getDataAsync(node, payload => {
|
|
218
218
|
const response = payload.data;
|
|
219
219
|
if (!payload.error && response !== null && response !== void 0 && response.meta) {
|
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { StorageClient } from '@atlaskit/frontend-utilities/StorageClient';
|
|
3
|
-
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
4
|
-
const SMART_CARD_CACHE_CLIENT_KEY = 'smart-card-url-data';
|
|
5
|
-
const SMART_CARD_CACHE_KEY = 'response-cache';
|
|
6
2
|
const SMART_CARD_CACHE_DEFAULT_MAX_ITEMS = 100;
|
|
7
3
|
/**
|
|
8
4
|
* Singleton cache client for smart link responses shared within the current document.
|
|
9
|
-
* Session storage remains available only for the document-cache gate's control cohort.
|
|
10
5
|
*/
|
|
11
6
|
export class SmartCardLocalCacheClient {
|
|
12
7
|
constructor(maxItems = SMART_CARD_CACHE_DEFAULT_MAX_ITEMS) {
|
|
13
|
-
_defineProperty(this, "storageClient", new StorageClient(SMART_CARD_CACHE_CLIENT_KEY, {
|
|
14
|
-
storageEngine: 'sessionStorage'
|
|
15
|
-
}));
|
|
16
8
|
_defineProperty(this, "documentCache", {});
|
|
17
|
-
_defineProperty(this, "pendingWrite", false);
|
|
18
9
|
/**
|
|
19
10
|
* Retrieves the entire cache object from memory
|
|
20
11
|
* @returns The entire cache object
|
|
21
12
|
*/
|
|
22
13
|
_defineProperty(this, "getCache", () => {
|
|
23
|
-
|
|
24
|
-
// Keep restored session data out of this cache if the gate changes after initialization.
|
|
25
|
-
return this.documentCache;
|
|
26
|
-
} else {
|
|
27
|
-
return this.memoryCache;
|
|
28
|
-
}
|
|
14
|
+
return this.documentCache;
|
|
29
15
|
});
|
|
30
16
|
/**
|
|
31
17
|
* Caches the SmartLinkResponse against the provided url
|
|
@@ -33,54 +19,18 @@ export class SmartCardLocalCacheClient {
|
|
|
33
19
|
* @param response The SmartLinkResponse to be cached
|
|
34
20
|
*/
|
|
35
21
|
_defineProperty(this, "setItem", (url, response) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
// Add or update the item in the cache with current timestamp
|
|
52
|
-
this.memoryCache[url] = {
|
|
53
|
-
data: response,
|
|
54
|
-
timestamp: Date.now()
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// Apply FIFO behavior if cache exceeds maxItems
|
|
58
|
-
const cacheKeys = Object.keys(this.memoryCache);
|
|
59
|
-
if (cacheKeys.length > this.maxItems) {
|
|
60
|
-
// Sort keys by timestamp (oldest first) and remove the oldest items
|
|
61
|
-
const sortedKeys = cacheKeys.sort((a, b) => this.memoryCache[a].timestamp - this.memoryCache[b].timestamp);
|
|
62
|
-
const itemsToRemove = cacheKeys.length - this.maxItems;
|
|
63
|
-
const keysToRemove = sortedKeys.slice(0, itemsToRemove);
|
|
64
|
-
keysToRemove.forEach(key => {
|
|
65
|
-
delete this.memoryCache[key];
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Write through to storage asynchronously (non-blocking)
|
|
70
|
-
// Debounced to batch multiple rapid calls into a single write
|
|
71
|
-
if (!this.pendingWrite) {
|
|
72
|
-
this.pendingWrite = true;
|
|
73
|
-
queueMicrotask(() => {
|
|
74
|
-
try {
|
|
75
|
-
this.storageClient.setItemWithExpiry(SMART_CARD_CACHE_KEY, JSON.stringify(this.memoryCache));
|
|
76
|
-
} catch (_) {
|
|
77
|
-
// Ignore storage write errors (e.g. quota exceeded) to prevent blocking future writes
|
|
78
|
-
// Cache will still function in-memory for the session, but won't persist
|
|
79
|
-
} finally {
|
|
80
|
-
this.pendingWrite = false;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
22
|
+
this.documentCache[url] = {
|
|
23
|
+
data: response,
|
|
24
|
+
timestamp: Date.now()
|
|
25
|
+
};
|
|
26
|
+
const cacheKeys = Object.keys(this.documentCache);
|
|
27
|
+
if (cacheKeys.length > this.maxItems) {
|
|
28
|
+
const sortedKeys = cacheKeys.sort((a, b) => this.documentCache[a].timestamp - this.documentCache[b].timestamp);
|
|
29
|
+
const itemsToRemove = cacheKeys.length - this.maxItems;
|
|
30
|
+
const keysToRemove = sortedKeys.slice(0, itemsToRemove);
|
|
31
|
+
keysToRemove.forEach(key => {
|
|
32
|
+
delete this.documentCache[key];
|
|
33
|
+
});
|
|
84
34
|
}
|
|
85
35
|
});
|
|
86
36
|
/**
|
|
@@ -89,17 +39,11 @@ export class SmartCardLocalCacheClient {
|
|
|
89
39
|
* @returns The cached SmartLinkResponse if it exists, else undefined
|
|
90
40
|
*/
|
|
91
41
|
_defineProperty(this, "getItem", url => {
|
|
42
|
+
var _this$documentCache$u;
|
|
92
43
|
if (!url) {
|
|
93
44
|
return;
|
|
94
45
|
}
|
|
95
|
-
|
|
96
|
-
var _this$documentCache$u;
|
|
97
|
-
return (_this$documentCache$u = this.documentCache[url]) === null || _this$documentCache$u === void 0 ? void 0 : _this$documentCache$u.data;
|
|
98
|
-
} else {
|
|
99
|
-
var _this$memoryCache, _this$memoryCache$url;
|
|
100
|
-
const response = (_this$memoryCache = this.memoryCache) === null || _this$memoryCache === void 0 ? void 0 : (_this$memoryCache$url = _this$memoryCache[url]) === null || _this$memoryCache$url === void 0 ? void 0 : _this$memoryCache$url.data;
|
|
101
|
-
return response;
|
|
102
|
-
}
|
|
46
|
+
return (_this$documentCache$u = this.documentCache[url]) === null || _this$documentCache$u === void 0 ? void 0 : _this$documentCache$u.data;
|
|
103
47
|
});
|
|
104
48
|
/**
|
|
105
49
|
* Checks if a cached entry exists for the provided url
|
|
@@ -107,28 +51,14 @@ export class SmartCardLocalCacheClient {
|
|
|
107
51
|
* @returns True if a cached entry exists, else false
|
|
108
52
|
*/
|
|
109
53
|
_defineProperty(this, "isUrlInCache", url => {
|
|
110
|
-
|
|
111
|
-
return url in this.documentCache;
|
|
112
|
-
} else {
|
|
113
|
-
return url in this.memoryCache;
|
|
114
|
-
}
|
|
54
|
+
return url in this.documentCache;
|
|
115
55
|
});
|
|
116
56
|
this.maxItems = maxItems;
|
|
117
|
-
if (fg('platform_smartlink_document_cache')) {
|
|
118
|
-
this.memoryCache = {};
|
|
119
|
-
} else {
|
|
120
|
-
// Load cache from storage into memory on instantiation
|
|
121
|
-
const stored = this.storageClient.getItem(SMART_CARD_CACHE_KEY, {
|
|
122
|
-
useExpiredItem: true
|
|
123
|
-
});
|
|
124
|
-
this.memoryCache = stored ? JSON.parse(stored) : {};
|
|
125
|
-
}
|
|
126
57
|
}
|
|
127
58
|
|
|
128
59
|
/**
|
|
129
60
|
* Gets the singleton instance of SmartCardLocalCacheClient.
|
|
130
|
-
* This ensures all callers share the same in-memory cache
|
|
131
|
-
* race conditions when multiple instances write to the same storage key.
|
|
61
|
+
* This ensures all callers share the same in-memory cache.
|
|
132
62
|
* @param maxItems Maximum number of items to store in the cache (only used on first instantiation)
|
|
133
63
|
* @returns The singleton instance
|
|
134
64
|
*/
|
package/dist/esm/provider.js
CHANGED
|
@@ -285,12 +285,12 @@ export var EditorCardProvider = /*#__PURE__*/function (_NodeDataProvider) {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
// if parent class NodeDataProvider has cached the network request for the node
|
|
288
|
-
// we can skip fetching the data async and updating the
|
|
288
|
+
// we can skip fetching the data async and updating the document cache
|
|
289
289
|
if (isResolvedCachedResponse && this.getCacheStatusForNode(jsonNode) === 'network') {
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
// fetch the latest data async and update the
|
|
293
|
+
// fetch the latest data async and update the document cache
|
|
294
294
|
this.getDataAsync(node, function (payload) {
|
|
295
295
|
var response = payload.data;
|
|
296
296
|
if (!payload.error && response !== null && response !== void 0 && response.meta) {
|
|
@@ -1,36 +1,22 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import { StorageClient } from '@atlaskit/frontend-utilities/StorageClient';
|
|
5
|
-
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
6
|
-
var SMART_CARD_CACHE_CLIENT_KEY = 'smart-card-url-data';
|
|
7
|
-
var SMART_CARD_CACHE_KEY = 'response-cache';
|
|
8
4
|
var SMART_CARD_CACHE_DEFAULT_MAX_ITEMS = 100;
|
|
9
5
|
/**
|
|
10
6
|
* Singleton cache client for smart link responses shared within the current document.
|
|
11
|
-
* Session storage remains available only for the document-cache gate's control cohort.
|
|
12
7
|
*/
|
|
13
8
|
export var SmartCardLocalCacheClient = /*#__PURE__*/function () {
|
|
14
9
|
function SmartCardLocalCacheClient() {
|
|
15
10
|
var _this = this;
|
|
16
11
|
var maxItems = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SMART_CARD_CACHE_DEFAULT_MAX_ITEMS;
|
|
17
12
|
_classCallCheck(this, SmartCardLocalCacheClient);
|
|
18
|
-
_defineProperty(this, "storageClient", new StorageClient(SMART_CARD_CACHE_CLIENT_KEY, {
|
|
19
|
-
storageEngine: 'sessionStorage'
|
|
20
|
-
}));
|
|
21
13
|
_defineProperty(this, "documentCache", {});
|
|
22
|
-
_defineProperty(this, "pendingWrite", false);
|
|
23
14
|
/**
|
|
24
15
|
* Retrieves the entire cache object from memory
|
|
25
16
|
* @returns The entire cache object
|
|
26
17
|
*/
|
|
27
18
|
_defineProperty(this, "getCache", function () {
|
|
28
|
-
|
|
29
|
-
// Keep restored session data out of this cache if the gate changes after initialization.
|
|
30
|
-
return _this.documentCache;
|
|
31
|
-
} else {
|
|
32
|
-
return _this.memoryCache;
|
|
33
|
-
}
|
|
19
|
+
return _this.documentCache;
|
|
34
20
|
});
|
|
35
21
|
/**
|
|
36
22
|
* Caches the SmartLinkResponse against the provided url
|
|
@@ -38,58 +24,20 @@ export var SmartCardLocalCacheClient = /*#__PURE__*/function () {
|
|
|
38
24
|
* @param response The SmartLinkResponse to be cached
|
|
39
25
|
*/
|
|
40
26
|
_defineProperty(this, "setItem", function (url, response) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
// Add or update the item in the cache with current timestamp
|
|
59
|
-
_this.memoryCache[url] = {
|
|
60
|
-
data: response,
|
|
61
|
-
timestamp: Date.now()
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Apply FIFO behavior if cache exceeds maxItems
|
|
65
|
-
var _cacheKeys = Object.keys(_this.memoryCache);
|
|
66
|
-
if (_cacheKeys.length > _this.maxItems) {
|
|
67
|
-
// Sort keys by timestamp (oldest first) and remove the oldest items
|
|
68
|
-
var _sortedKeys = _cacheKeys.sort(function (a, b) {
|
|
69
|
-
return _this.memoryCache[a].timestamp - _this.memoryCache[b].timestamp;
|
|
70
|
-
});
|
|
71
|
-
var _itemsToRemove = _cacheKeys.length - _this.maxItems;
|
|
72
|
-
var _keysToRemove = _sortedKeys.slice(0, _itemsToRemove);
|
|
73
|
-
_keysToRemove.forEach(function (key) {
|
|
74
|
-
delete _this.memoryCache[key];
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Write through to storage asynchronously (non-blocking)
|
|
79
|
-
// Debounced to batch multiple rapid calls into a single write
|
|
80
|
-
if (!_this.pendingWrite) {
|
|
81
|
-
_this.pendingWrite = true;
|
|
82
|
-
queueMicrotask(function () {
|
|
83
|
-
try {
|
|
84
|
-
_this.storageClient.setItemWithExpiry(SMART_CARD_CACHE_KEY, JSON.stringify(_this.memoryCache));
|
|
85
|
-
} catch (_) {
|
|
86
|
-
// Ignore storage write errors (e.g. quota exceeded) to prevent blocking future writes
|
|
87
|
-
// Cache will still function in-memory for the session, but won't persist
|
|
88
|
-
} finally {
|
|
89
|
-
_this.pendingWrite = false;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
27
|
+
_this.documentCache[url] = {
|
|
28
|
+
data: response,
|
|
29
|
+
timestamp: Date.now()
|
|
30
|
+
};
|
|
31
|
+
var cacheKeys = Object.keys(_this.documentCache);
|
|
32
|
+
if (cacheKeys.length > _this.maxItems) {
|
|
33
|
+
var sortedKeys = cacheKeys.sort(function (a, b) {
|
|
34
|
+
return _this.documentCache[a].timestamp - _this.documentCache[b].timestamp;
|
|
35
|
+
});
|
|
36
|
+
var itemsToRemove = cacheKeys.length - _this.maxItems;
|
|
37
|
+
var keysToRemove = sortedKeys.slice(0, itemsToRemove);
|
|
38
|
+
keysToRemove.forEach(function (key) {
|
|
39
|
+
delete _this.documentCache[key];
|
|
40
|
+
});
|
|
93
41
|
}
|
|
94
42
|
});
|
|
95
43
|
/**
|
|
@@ -98,17 +46,11 @@ export var SmartCardLocalCacheClient = /*#__PURE__*/function () {
|
|
|
98
46
|
* @returns The cached SmartLinkResponse if it exists, else undefined
|
|
99
47
|
*/
|
|
100
48
|
_defineProperty(this, "getItem", function (url) {
|
|
49
|
+
var _this$documentCache$u;
|
|
101
50
|
if (!url) {
|
|
102
51
|
return;
|
|
103
52
|
}
|
|
104
|
-
|
|
105
|
-
var _this$documentCache$u;
|
|
106
|
-
return (_this$documentCache$u = _this.documentCache[url]) === null || _this$documentCache$u === void 0 ? void 0 : _this$documentCache$u.data;
|
|
107
|
-
} else {
|
|
108
|
-
var _this$memoryCache;
|
|
109
|
-
var response = (_this$memoryCache = _this.memoryCache) === null || _this$memoryCache === void 0 || (_this$memoryCache = _this$memoryCache[url]) === null || _this$memoryCache === void 0 ? void 0 : _this$memoryCache.data;
|
|
110
|
-
return response;
|
|
111
|
-
}
|
|
53
|
+
return (_this$documentCache$u = _this.documentCache[url]) === null || _this$documentCache$u === void 0 ? void 0 : _this$documentCache$u.data;
|
|
112
54
|
});
|
|
113
55
|
/**
|
|
114
56
|
* Checks if a cached entry exists for the provided url
|
|
@@ -116,28 +58,14 @@ export var SmartCardLocalCacheClient = /*#__PURE__*/function () {
|
|
|
116
58
|
* @returns True if a cached entry exists, else false
|
|
117
59
|
*/
|
|
118
60
|
_defineProperty(this, "isUrlInCache", function (url) {
|
|
119
|
-
|
|
120
|
-
return url in _this.documentCache;
|
|
121
|
-
} else {
|
|
122
|
-
return url in _this.memoryCache;
|
|
123
|
-
}
|
|
61
|
+
return url in _this.documentCache;
|
|
124
62
|
});
|
|
125
63
|
this.maxItems = maxItems;
|
|
126
|
-
if (fg('platform_smartlink_document_cache')) {
|
|
127
|
-
this.memoryCache = {};
|
|
128
|
-
} else {
|
|
129
|
-
// Load cache from storage into memory on instantiation
|
|
130
|
-
var stored = this.storageClient.getItem(SMART_CARD_CACHE_KEY, {
|
|
131
|
-
useExpiredItem: true
|
|
132
|
-
});
|
|
133
|
-
this.memoryCache = stored ? JSON.parse(stored) : {};
|
|
134
|
-
}
|
|
135
64
|
}
|
|
136
65
|
|
|
137
66
|
/**
|
|
138
67
|
* Gets the singleton instance of SmartCardLocalCacheClient.
|
|
139
|
-
* This ensures all callers share the same in-memory cache
|
|
140
|
-
* race conditions when multiple instances write to the same storage key.
|
|
68
|
+
* This ensures all callers share the same in-memory cache.
|
|
141
69
|
* @param maxItems Maximum number of items to store in the cache (only used on first instantiation)
|
|
142
70
|
* @returns The singleton instance
|
|
143
71
|
*/
|
|
@@ -5,20 +5,15 @@ type CacheEntry = {
|
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Singleton cache client for smart link responses shared within the current document.
|
|
8
|
-
* Session storage remains available only for the document-cache gate's control cohort.
|
|
9
8
|
*/
|
|
10
9
|
export declare class SmartCardLocalCacheClient {
|
|
11
10
|
private static instance;
|
|
12
|
-
private readonly storageClient;
|
|
13
11
|
private maxItems;
|
|
14
|
-
private memoryCache;
|
|
15
12
|
private documentCache;
|
|
16
|
-
private pendingWrite;
|
|
17
13
|
private constructor();
|
|
18
14
|
/**
|
|
19
15
|
* Gets the singleton instance of SmartCardLocalCacheClient.
|
|
20
|
-
* This ensures all callers share the same in-memory cache
|
|
21
|
-
* race conditions when multiple instances write to the same storage key.
|
|
16
|
+
* This ensures all callers share the same in-memory cache.
|
|
22
17
|
* @param maxItems Maximum number of items to store in the cache (only used on first instantiation)
|
|
23
18
|
* @returns The singleton instance
|
|
24
19
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-card-provider",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "Contains the EditorCardProvider, for determining smart card behaviour in the editor.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"@atlaskit/editor-json-transformer": "^10.0.0",
|
|
25
25
|
"@atlaskit/editor-prosemirror": "^9.0.0",
|
|
26
26
|
"@atlaskit/feature-gate-js-client": "^7.0.0",
|
|
27
|
-
"@atlaskit/frontend-utilities": "^5.0.0",
|
|
28
27
|
"@atlaskit/json-ld-types": "^2.1.0",
|
|
29
28
|
"@atlaskit/link-client-extension": "^8.0.0",
|
|
30
29
|
"@atlaskit/link-extractors": "^5.0.0",
|
|
@@ -32,7 +31,7 @@
|
|
|
32
31
|
"@atlaskit/linking-types": "^16.0.0",
|
|
33
32
|
"@atlaskit/node-data-provider": "^30.0.0",
|
|
34
33
|
"@atlaskit/platform-feature-flags": "^2.2.0",
|
|
35
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
34
|
+
"@atlaskit/tmp-editor-statsig": "^245.0.0",
|
|
36
35
|
"@babel/runtime": "^7.0.0",
|
|
37
36
|
"dataloader": "^2.1.0"
|
|
38
37
|
},
|
|
@@ -41,13 +40,11 @@
|
|
|
41
40
|
"react": "^18.2.0 || ^19.2.0"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
43
|
+
"@atlaskit/frontend-utilities": "^5.0.0",
|
|
44
44
|
"@atlassian/feature-flags-test-utils": "^1.3.0",
|
|
45
45
|
"react": "^19.2.0"
|
|
46
46
|
},
|
|
47
47
|
"platform-feature-flags": {
|
|
48
|
-
"platform_smartlink_document_cache": {
|
|
49
|
-
"type": "boolean"
|
|
50
|
-
},
|
|
51
48
|
"tc_smart_link_embed_view": {
|
|
52
49
|
"type": "boolean"
|
|
53
50
|
},
|