@dpgradio/creative 5.1.1 → 5.3.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/README.md +7 -2
- package/examples/useConfig.js +9 -5
- package/package-lock.json +3891 -0
- package/package.json +1 -1
- package/src/api/api.js +2 -0
- package/src/api/endpoints/ForbiddenWord.js +7 -0
- package/src/api/endpoints/Members.js +4 -0
- package/src/config/config.js +32 -11
package/package.json
CHANGED
package/src/api/api.js
CHANGED
|
@@ -5,6 +5,7 @@ import Channels from './endpoints/Channels.js'
|
|
|
5
5
|
import Config from './endpoints/Config.js'
|
|
6
6
|
import Members from './endpoints/Members.js'
|
|
7
7
|
import Ratings from './endpoints/Ratings.js'
|
|
8
|
+
import ForbiddenWord from './endpoints/ForbiddenWord.js'
|
|
8
9
|
|
|
9
10
|
const GLOBAL_API_URL = 'https://api.radio.dpgmedia.cloud'
|
|
10
11
|
|
|
@@ -27,6 +28,7 @@ export class Api {
|
|
|
27
28
|
this.config = new Config(this)
|
|
28
29
|
this.members = new Members(this)
|
|
29
30
|
this.ratings = new Ratings(this)
|
|
31
|
+
this.forbiddenWord = new ForbiddenWord(this)
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
get baseUrl() {
|
package/src/config/config.js
CHANGED
|
@@ -15,7 +15,10 @@ class Configuration {
|
|
|
15
15
|
return this
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Retrieve the configuration for the current hostname or present query parameter and the given app (optional).
|
|
20
|
+
*/
|
|
21
|
+
async retrieveConfigForDetectedStation(appId = null) {
|
|
19
22
|
const parameters = new URLSearchParams(window.location.search)
|
|
20
23
|
if (parameters.has('stationId')) {
|
|
21
24
|
return this.retrieveConfigForStation(appId, parameters.get('stationId'))
|
|
@@ -24,15 +27,20 @@ class Configuration {
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
|
-
* Retrieve the configuration for the
|
|
30
|
+
* Retrieve the configuration for the current hostname and the given app (optional).
|
|
28
31
|
*/
|
|
29
|
-
async retrieveConfigByHostname(appId) {
|
|
32
|
+
async retrieveConfigByHostname(appId = null) {
|
|
30
33
|
this.appId = appId
|
|
31
34
|
|
|
32
35
|
// This is not the most robust way to get the hostname without subdomains, e.g. .co.uk domains will break.
|
|
33
36
|
// However, for the TLDs we use, this should be fine.
|
|
34
37
|
const hostname = window.location.hostname.split('.').splice(-2).join('.')
|
|
35
|
-
|
|
38
|
+
|
|
39
|
+
if (appId) {
|
|
40
|
+
this.rawConfig = await api.global().config.app(appId, { domains: [hostname] })
|
|
41
|
+
} else {
|
|
42
|
+
this.rawConfig = await api.global().config.global({ domains: [hostname] })
|
|
43
|
+
}
|
|
36
44
|
|
|
37
45
|
this.stationId = Object.keys(this.rawConfig)[0]
|
|
38
46
|
|
|
@@ -40,13 +48,24 @@ class Configuration {
|
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
/**
|
|
43
|
-
* Retrieve the configuration for the given
|
|
51
|
+
* Retrieve the configuration for the given station and the given app (optional).
|
|
44
52
|
*/
|
|
45
|
-
async retrieveConfigForStation(
|
|
53
|
+
async retrieveConfigForStation(stationId, appId = null) {
|
|
54
|
+
return await this.retrieveConfigForStations([stationId], appId)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve the configuration for the given stations and the given app (optional).
|
|
59
|
+
*/
|
|
60
|
+
async retrieveConfigForStations(stationIds, appId = null) {
|
|
46
61
|
this.appId = appId
|
|
47
62
|
this.stationId = stationIds[0]
|
|
48
63
|
|
|
49
|
-
|
|
64
|
+
if (appId) {
|
|
65
|
+
this.rawConfig = await api.global().config.app(appId, { stationIds })
|
|
66
|
+
} else {
|
|
67
|
+
this.rawConfig = await api.global().config.global({ stationIds })
|
|
68
|
+
}
|
|
50
69
|
|
|
51
70
|
return this
|
|
52
71
|
}
|
|
@@ -58,10 +77,12 @@ class Configuration {
|
|
|
58
77
|
if (!this.stationId) {
|
|
59
78
|
throw new Error('No station set. First use [config.setStation] to set the station.')
|
|
60
79
|
}
|
|
61
|
-
if (!this.
|
|
62
|
-
throw new Error(
|
|
80
|
+
if (!this.rawConfig[this.stationId]) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`No configuration found for station [${this.stationId}]. Make sure there is a global config for this station.`
|
|
83
|
+
)
|
|
63
84
|
}
|
|
64
|
-
if (!this.rawConfig[this.stationId]?.[this.appId]) {
|
|
85
|
+
if (this.appId && !this.rawConfig[this.stationId]?.[this.appId]) {
|
|
65
86
|
throw new Error(
|
|
66
87
|
`No configuration found for station [${this.stationId}] and app [${this.appId}]. Make sure the app is enabled for this station.`
|
|
67
88
|
)
|
|
@@ -69,7 +90,7 @@ class Configuration {
|
|
|
69
90
|
|
|
70
91
|
const stationConfig = {
|
|
71
92
|
...this.rawConfig[this.stationId],
|
|
72
|
-
app: this.rawConfig[this.stationId][this.appId],
|
|
93
|
+
...(this.appId ? { app: this.rawConfig[this.stationId][this.appId] } : {}),
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
return property ? dotSyntaxAccess(stationConfig, property) : stationConfig
|