@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpgradio/creative",
3
- "version": "5.1.1",
3
+ "version": "5.3.0",
4
4
  "description": "Support package for standalone Javascript applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
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() {
@@ -0,0 +1,7 @@
1
+ import Endpoint from './Endpoint.js'
2
+
3
+ export default class ForbiddenWord extends Endpoint {
4
+ async detection(id) {
5
+ await this.api.request().post(`/forbidden_word/${id}/detection`)
6
+ }
7
+ }
@@ -4,4 +4,8 @@ export default class Members extends Endpoint {
4
4
  async me() {
5
5
  return await this.api.request().get('/members/me')
6
6
  }
7
+
8
+ async updateProfile(profile) {
9
+ return await this.api.request().put('/members/me', { profile })
10
+ }
7
11
  }
@@ -15,7 +15,10 @@ class Configuration {
15
15
  return this
16
16
  }
17
17
 
18
- async retrieveConfigForDetectedStation(appId) {
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 given app and the current hostname.
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
- this.rawConfig = await api.global().config.app(appId, { domains: [hostname] })
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 app and the given station(s).
51
+ * Retrieve the configuration for the given station and the given app (optional).
44
52
  */
45
- async retrieveConfigForStation(appId, ...stationIds) {
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
- this.rawConfig = await api.global().config.app(appId, { stationIds })
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.appId) {
62
- throw new Error('No app identifier set. First use [config.retrieveConfig] to retrieve the configuration.')
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