@dpgradio/creative 5.0.5 → 5.1.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.
package/README.md CHANGED
@@ -14,8 +14,8 @@ The variables and fonts are no longer available as scss variables/imports.
14
14
  Example:
15
15
 
16
16
  ```css
17
- @import "q-creative/styles/colors/qmusic";
18
- @import "q-creative/styles/fonts/qmusic";
17
+ @import "@dpgradio/creative/styles/colors/qmusic";
18
+ @import "@dpgradio/creative/styles/fonts/qmusic";
19
19
 
20
20
  body, html {
21
21
  background-color: rgb(var(--q-teal));
@@ -24,6 +24,12 @@ body, html {
24
24
  }
25
25
  ```
26
26
 
27
+ Use the following to import the colors and fonts of all brands:
28
+
29
+ ```css
30
+ @import "@dpgradio/creative/styles/all";
31
+ ```
32
+
27
33
  ## Config
28
34
 
29
35
  ### Usage
@@ -34,7 +40,12 @@ The configuration will also be used by other components of this package (e.g. pr
34
40
  ```js
35
41
  import { configuration } from '@dpgradio/creative'
36
42
 
37
- await configuration.retrieveConfig(appId, stationIdA, stationIdB, stationIdC)
43
+ await configuration.retrieveConfigForDetectedStation(appId) // Default, by hostname or query parameter
44
+
45
+ // Or, if you want to retrieve the config by hostnames only.
46
+ await configuration.retrieveConfigByHostname(appId)
47
+ // Or, if you want to retrieve the config for a specific station:
48
+ await configuration.retrieveConfigByStation(appId, stationIdA, stationIdB, stationIdC)
38
49
 
39
50
  // By default the first station ID (stationIdA) is used as the current station of the configuration.
40
51
  // If you want to use a different station, you can do so by calling:
@@ -190,7 +201,7 @@ hybrid.decodeRadioToken(radioToken)
190
201
  Example:
191
202
 
192
203
  ```js
193
- import { Shareable, ImageGeneratorProperties } from 'q-creative/share'
204
+ import { Shareable, ImageGeneratorProperties } from '@dpgradio/creative/share'
194
205
 
195
206
  const shareable = new Shareable()
196
207
  .withTitle(`${this.name} is mijn seventies match!`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpgradio/creative",
3
- "version": "5.0.5",
3
+ "version": "5.1.1",
4
4
  "description": "Support package for standalone Javascript applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,12 +1,14 @@
1
1
  import Endpoint from './Endpoint.js'
2
2
 
3
3
  export default class Config extends Endpoint {
4
- async global() {
5
- return await this.requestData((r) => r.get('/config'))
4
+ async global({ stationIds = null, domains = null }) {
5
+ return await this.requestData((r) => r.get('/config', this.withoutNullValues({ station_ids: stationIds, domains })))
6
6
  }
7
7
 
8
- async app(appId, stationIds) {
9
- return await this.requestData((r) => r.get(`/config/${appId}`, { station_ids: stationIds }))
8
+ async app(appId, { stationIds = null, domains = null }) {
9
+ return await this.requestData((r) =>
10
+ r.get(`/config/${appId}`, this.withoutNullValues({ station_ids: stationIds, domains }))
11
+ )
10
12
  }
11
13
 
12
14
  async updateSchema(appId, schema) {
@@ -55,4 +55,8 @@ export default class Endpoint {
55
55
 
56
56
  return new PaginatedResponse(response, key)
57
57
  }
58
+
59
+ withoutNullValues(object) {
60
+ return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== null))
61
+ }
58
62
  }
@@ -15,11 +15,38 @@ class Configuration {
15
15
  return this
16
16
  }
17
17
 
18
- async retrieveConfig(appId, ...stationIds) {
18
+ async retrieveConfigForDetectedStation(appId) {
19
+ const parameters = new URLSearchParams(window.location.search)
20
+ if (parameters.has('stationId')) {
21
+ return this.retrieveConfigForStation(appId, parameters.get('stationId'))
22
+ }
23
+ return this.retrieveConfigByHostname(appId)
24
+ }
25
+
26
+ /**
27
+ * Retrieve the configuration for the given app and the current hostname.
28
+ */
29
+ async retrieveConfigByHostname(appId) {
30
+ this.appId = appId
31
+
32
+ // This is not the most robust way to get the hostname without subdomains, e.g. .co.uk domains will break.
33
+ // However, for the TLDs we use, this should be fine.
34
+ const hostname = window.location.hostname.split('.').splice(-2).join('.')
35
+ this.rawConfig = await api.global().config.app(appId, { domains: [hostname] })
36
+
37
+ this.stationId = Object.keys(this.rawConfig)[0]
38
+
39
+ return this
40
+ }
41
+
42
+ /**
43
+ * Retrieve the configuration for the given app and the given station(s).
44
+ */
45
+ async retrieveConfigForStation(appId, ...stationIds) {
19
46
  this.appId = appId
20
47
  this.stationId = stationIds[0]
21
48
 
22
- this.rawConfig = await api.global().config.app(appId, stationIds)
49
+ this.rawConfig = await api.global().config.app(appId, { stationIds })
23
50
 
24
51
  return this
25
52
  }
package/styles/all.css ADDED
@@ -0,0 +1,9 @@
1
+ /* Colors */
2
+ @import url(./colors/joe.css);
3
+ @import url(./colors/qmusic.css);
4
+ @import url(./colors/willy.css);
5
+
6
+ /* Fonts */
7
+ @import url(./fonts/joe.css);
8
+ @import url(./fonts/qmusic.css);
9
+ @import url(./fonts/willy.css);