musora-content-services 1.3.7 → 1.3.9
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/.github/workflows/node.js.yml +0 -0
- package/CHANGELOG.md +4 -0
- package/README.md +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/scripts/collapse.js +0 -0
- package/docs/scripts/commonNav.js +0 -0
- package/docs/scripts/linenumber.js +0 -0
- package/docs/scripts/nav.js +0 -0
- package/docs/scripts/polyfill.js +0 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
- package/docs/scripts/prettify/lang-css.js +0 -0
- package/docs/scripts/prettify/prettify.js +0 -0
- package/docs/scripts/search.js +0 -0
- package/docs/styles/jsdoc.css +0 -0
- package/docs/styles/prettify.css +0 -0
- package/package.json +1 -1
- package/src/filterBuilder.js +11 -11
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/services/dataContext.js +26 -5
- package/test/dataContext.test.js +38 -0
|
File without changes
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.3.9](https://github.com/railroadmedia/musora-content-services/compare/v1.3.8...v1.3.9) (2025-02-22)
|
|
6
|
+
|
|
7
|
+
### [1.3.8](https://github.com/railroadmedia/musora-content-services/compare/v1.3.7...v1.3.8) (2025-02-21)
|
|
8
|
+
|
|
5
9
|
### [1.3.7](https://github.com/railroadmedia/musora-content-services/compare/v1.3.6...v1.3.7) (2025-02-20)
|
|
6
10
|
|
|
7
11
|
### [1.3.6](https://github.com/railroadmedia/musora-content-services/compare/v1.3.5...v1.3.6) (2025-02-18)
|
package/README.md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/scripts/collapse.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/scripts/nav.js
CHANGED
|
File without changes
|
package/docs/scripts/polyfill.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/scripts/search.js
CHANGED
|
File without changes
|
package/docs/styles/jsdoc.css
CHANGED
|
File without changes
|
package/docs/styles/prettify.css
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/filterBuilder.js
CHANGED
|
@@ -56,6 +56,15 @@ export class FilterBuilder {
|
|
|
56
56
|
return filter
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
_getRoundedTime(){
|
|
60
|
+
// We need to set the published on filter date to be a round time so that it doesn't bypass the query cache
|
|
61
|
+
// with every request by changing the filter date every second. I've set it to one minute past the current hour
|
|
62
|
+
// because publishing usually publishes content on the hour exactly which means it should still skip the cache
|
|
63
|
+
// when the new content is available.
|
|
64
|
+
const now = new Date();
|
|
65
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), 1);
|
|
66
|
+
}
|
|
67
|
+
|
|
59
68
|
_applyContentStatuses() {
|
|
60
69
|
// This must be run before _applyPublishDateRestrictions()
|
|
61
70
|
if (this.bypassStatuses) return this
|
|
@@ -89,7 +98,7 @@ export class FilterBuilder {
|
|
|
89
98
|
) {
|
|
90
99
|
// we must pull in future content here, otherwise we'll restrict on content this is published in the past and remove any scheduled content
|
|
91
100
|
this.pullFutureContent = true
|
|
92
|
-
const now =
|
|
101
|
+
const now = this._getRoundedTime().toISOString();
|
|
93
102
|
let statuses = [...this.availableContentStatuses]
|
|
94
103
|
statuses.splice(statuses.indexOf(this.STATUS_SCHEDULED), 1)
|
|
95
104
|
this._andWhere(
|
|
@@ -121,16 +130,7 @@ export class FilterBuilder {
|
|
|
121
130
|
|
|
122
131
|
_applyPublishingDateRestrictions() {
|
|
123
132
|
if (this.bypassPublishedDateRestriction) return this
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// We need to set the published on filter date to be a round time so that it doesn't bypass the query cache
|
|
127
|
-
// with every request by changing the filter date every second. I've set it to one minute past the current hour
|
|
128
|
-
// because publishing usually publishes content on the hour exactly which means it should still skip the cache
|
|
129
|
-
// when the new content is available.
|
|
130
|
-
// Round to the start of the current hour
|
|
131
|
-
const roundedDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours())
|
|
132
|
-
|
|
133
|
-
now = roundedDate.toISOString()
|
|
133
|
+
const now = this._getRoundedTime().toISOString();
|
|
134
134
|
|
|
135
135
|
if (this.getFutureContentOnly) {
|
|
136
136
|
this._andWhere(`${this.prefix}published_on >= '${now}'`)
|
package/src/index.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
recordWatchSession
|
|
28
28
|
} from './services/contentProgress.js';
|
|
29
29
|
|
|
30
|
+
import {
|
|
31
|
+
verifyLocalDataContext
|
|
32
|
+
} from './services/dataContext.js';
|
|
33
|
+
|
|
30
34
|
import {
|
|
31
35
|
setLastUpdatedTime,
|
|
32
36
|
wasLastUpdateOlderThanXSeconds
|
|
@@ -258,6 +262,7 @@ declare module 'musora-content-services' {
|
|
|
258
262
|
unpinPlaylist,
|
|
259
263
|
updatePlaylist,
|
|
260
264
|
updatePlaylistItem,
|
|
265
|
+
verifyLocalDataContext,
|
|
261
266
|
wasLastUpdateOlderThanXSeconds,
|
|
262
267
|
}
|
|
263
268
|
}
|
package/src/index.js
CHANGED
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
recordWatchSession
|
|
28
28
|
} from './services/contentProgress.js';
|
|
29
29
|
|
|
30
|
+
import {
|
|
31
|
+
verifyLocalDataContext
|
|
32
|
+
} from './services/dataContext.js';
|
|
33
|
+
|
|
30
34
|
import {
|
|
31
35
|
setLastUpdatedTime,
|
|
32
36
|
wasLastUpdateOlderThanXSeconds
|
|
@@ -257,5 +261,6 @@ export {
|
|
|
257
261
|
unpinPlaylist,
|
|
258
262
|
updatePlaylist,
|
|
259
263
|
updatePlaylistItem,
|
|
264
|
+
verifyLocalDataContext,
|
|
260
265
|
wasLastUpdateOlderThanXSeconds,
|
|
261
266
|
};
|
|
@@ -13,6 +13,23 @@ export const ContentProgressVersionKey = 1
|
|
|
13
13
|
|
|
14
14
|
let cache = null
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Verify current cached data is on the correct version
|
|
18
|
+
*
|
|
19
|
+
* @param {int} dataVersionKey - Data version key from the back end
|
|
20
|
+
* @param {int} currentVersion - Current version of the data on the back end
|
|
21
|
+
* */
|
|
22
|
+
export async function verifyLocalDataContext(dataVersionKey, currentVersion) {
|
|
23
|
+
const tempContext = new DataContext(dataVersionKey, null)
|
|
24
|
+
await tempContext.ensureLocalContextLoaded()
|
|
25
|
+
|
|
26
|
+
if (currentVersion !== tempContext.version()) {
|
|
27
|
+
tempContext.clearCache()
|
|
28
|
+
} else {
|
|
29
|
+
tempContext.setLastUpdatedTime()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
16
33
|
export class DataContext {
|
|
17
34
|
context = null
|
|
18
35
|
dataPromise = null
|
|
@@ -33,7 +50,7 @@ export class DataContext {
|
|
|
33
50
|
|
|
34
51
|
async getDataPromise() {
|
|
35
52
|
await this.ensureLocalContextLoaded()
|
|
36
|
-
const shouldVerify = await this.
|
|
53
|
+
const shouldVerify = await this.shouldVerifyServerVersions()
|
|
37
54
|
|
|
38
55
|
if (!this.context || shouldVerify) {
|
|
39
56
|
let version = this.version()
|
|
@@ -42,7 +59,7 @@ export class DataContext {
|
|
|
42
59
|
this.context = data
|
|
43
60
|
cache.setItem(this.localStorageKey, JSON.stringify(data))
|
|
44
61
|
}
|
|
45
|
-
|
|
62
|
+
this.setLastUpdatedTime()
|
|
46
63
|
}
|
|
47
64
|
this.dataPromise = null
|
|
48
65
|
return this.context.data
|
|
@@ -73,11 +90,11 @@ export class DataContext {
|
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
92
|
|
|
76
|
-
async
|
|
93
|
+
async shouldVerifyServerVersions() {
|
|
77
94
|
let lastUpdated = globalConfig.isMA
|
|
78
95
|
? await cache.getItem(this.localStorageLastUpdatedKey)
|
|
79
96
|
: cache.getItem(this.localStorageLastUpdatedKey)
|
|
80
|
-
if (!lastUpdated) return
|
|
97
|
+
if (!lastUpdated) return true
|
|
81
98
|
const verifyServerTime = 10000 //10 s
|
|
82
99
|
return new Date().getTime() - lastUpdated > verifyServerTime
|
|
83
100
|
}
|
|
@@ -92,6 +109,10 @@ export class DataContext {
|
|
|
92
109
|
this.context = null
|
|
93
110
|
}
|
|
94
111
|
|
|
112
|
+
setLastUpdatedTime() {
|
|
113
|
+
cache.setItem(this.localStorageLastUpdatedKey, new Date().getTime().toString())
|
|
114
|
+
}
|
|
115
|
+
|
|
95
116
|
async update(localUpdateFunction, serverUpdateFunction) {
|
|
96
117
|
await this.ensureLocalContextLoaded()
|
|
97
118
|
if (this.context) {
|
|
@@ -99,7 +120,7 @@ export class DataContext {
|
|
|
99
120
|
if (this.context) this.context.version++
|
|
100
121
|
let data = JSON.stringify(this.context)
|
|
101
122
|
cache.setItem(this.localStorageKey, data)
|
|
102
|
-
|
|
123
|
+
this.setLastUpdatedTime()
|
|
103
124
|
}
|
|
104
125
|
const updatePromise = serverUpdateFunction()
|
|
105
126
|
updatePromise.then((response) => {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { initializeTestService } from './initializeTests'
|
|
2
|
+
import { DataContext, verifyLocalDataContext } from '../src/services/dataContext.js'
|
|
3
|
+
|
|
4
|
+
describe('dataContext', function () {
|
|
5
|
+
let mock = null
|
|
6
|
+
let testVersion = 1
|
|
7
|
+
const dataVersionKey = 1
|
|
8
|
+
const dataContext = new DataContext(dataVersionKey, null)
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
initializeTestService()
|
|
12
|
+
mock = jest.spyOn(dataContext, 'fetchData')
|
|
13
|
+
mock.mockImplementation(() =>
|
|
14
|
+
JSON.parse(`{"version":${testVersion},"data":[308516,308515,308514,308518]}`)
|
|
15
|
+
)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('verifyLocalData', async () => {
|
|
19
|
+
//force load data into context and verify version 1 loaded
|
|
20
|
+
await dataContext.getData()
|
|
21
|
+
expect(dataContext.version()).toBe(1)
|
|
22
|
+
|
|
23
|
+
//increment source version and verify data context still uses old version
|
|
24
|
+
testVersion++
|
|
25
|
+
await dataContext.getData()
|
|
26
|
+
expect(dataContext.version()).toBe(1)
|
|
27
|
+
|
|
28
|
+
//verifyLocalData with old source version and verify context still uses old version
|
|
29
|
+
await verifyLocalDataContext(1, 1)
|
|
30
|
+
await dataContext.getData()
|
|
31
|
+
expect(dataContext.version()).toBe(1)
|
|
32
|
+
|
|
33
|
+
//verifyLocalData with new source version and verify context loads new version
|
|
34
|
+
await verifyLocalDataContext(1, 2)
|
|
35
|
+
await dataContext.getData()
|
|
36
|
+
expect(dataContext.version()).toBe(2)
|
|
37
|
+
})
|
|
38
|
+
})
|