@dpgradio/creative 5.0.4 → 5.1.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 +15 -4
- package/package.json +1 -1
- package/src/api/PaginatedResponse.js +41 -0
- package/src/api/api.js +2 -0
- package/src/api/endpoints/Config.js +4 -4
- package/src/api/endpoints/Endpoint.js +21 -0
- package/src/api/endpoints/Ratings.js +1 -1
- package/src/api/request.js +7 -2
- package/src/config/config.js +29 -2
- package/styles/all.css +9 -0
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 "
|
|
18
|
-
@import "
|
|
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.
|
|
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 '
|
|
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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import api from './api'
|
|
2
|
+
|
|
3
|
+
export default class PaginatedResponse {
|
|
4
|
+
constructor(response, dataKey = 'data') {
|
|
5
|
+
this.pagination = response.pagination
|
|
6
|
+
this.data = response[dataKey]
|
|
7
|
+
this.dataKey = dataKey
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async fetchNext() {
|
|
11
|
+
const response = await api.onVersion(null).request().get(this.pagination.next)
|
|
12
|
+
this.pagination.next = response.pagination.next
|
|
13
|
+
this.data = [...this.data, ...response[this.dataKey]]
|
|
14
|
+
|
|
15
|
+
return response[this.dataKey]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async fetchPrevious() {
|
|
19
|
+
const response = await api.onVersion(null).request().get(this.pagination.previous)
|
|
20
|
+
this.pagination.previous = response.pagination.previous
|
|
21
|
+
this.data = [...response[this.dataKey], ...this.data]
|
|
22
|
+
|
|
23
|
+
return response[this.dataKey]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async fetchAllNext() {
|
|
27
|
+
while ((await this.fetchNext()).length > 0) {
|
|
28
|
+
continue
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return this.data
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async fetchAllPrevious() {
|
|
35
|
+
while ((await this.fetchPrevious()).length > 0) {
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return this.data
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/api/api.js
CHANGED
|
@@ -69,6 +69,8 @@ export class Api {
|
|
|
69
69
|
|
|
70
70
|
clone() {
|
|
71
71
|
return tap(new Api(this.baseUrlOverride, this.version), (api) => {
|
|
72
|
+
api.apiKey = this.apiKey
|
|
73
|
+
api.radioToken = this.radioToken
|
|
72
74
|
api.requestModifiers = this.requestModifiers
|
|
73
75
|
api.errorHandlers = this.errorHandlers
|
|
74
76
|
})
|
|
@@ -1,12 +1,12 @@
|
|
|
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', { 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) => r.get(`/config/${appId}`, { station_ids: stationIds, domains }))
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async updateSchema(appId, schema) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Api } from '../api.js'
|
|
3
3
|
// eslint-disable-next-line no-unused-vars -- used in JSDoc
|
|
4
4
|
import Request from '../request.js'
|
|
5
|
+
import PaginatedResponse from '../PaginatedResponse.js'
|
|
5
6
|
|
|
6
7
|
export default class Endpoint {
|
|
7
8
|
/**
|
|
@@ -34,4 +35,24 @@ export default class Endpoint {
|
|
|
34
35
|
}
|
|
35
36
|
return response[key]
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {requestCallback} callback
|
|
41
|
+
* @returns {PaginatedResponse}
|
|
42
|
+
*/
|
|
43
|
+
async requestPaginatedData(callback, key = 'data') {
|
|
44
|
+
const response = await callback(this.api.request())
|
|
45
|
+
|
|
46
|
+
if (response === null) {
|
|
47
|
+
throw new Error(`Endpoint returned invalid JSON.`)
|
|
48
|
+
}
|
|
49
|
+
if (response[key] === undefined) {
|
|
50
|
+
throw new Error(`Key '${key}' not found in response: ${JSON.stringify(response)}`)
|
|
51
|
+
}
|
|
52
|
+
if (response.pagination === undefined) {
|
|
53
|
+
throw new Error(`Key 'pagination' not found in response: ${JSON.stringify(response)}`)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return new PaginatedResponse(response, key)
|
|
57
|
+
}
|
|
37
58
|
}
|
|
@@ -2,7 +2,7 @@ import Endpoint from './Endpoint.js'
|
|
|
2
2
|
|
|
3
3
|
export default class Ratings extends Endpoint {
|
|
4
4
|
async allForMember() {
|
|
5
|
-
return await this.
|
|
5
|
+
return await this.requestPaginatedData((r) => r.get('/members/me/ratings'), 'ratings')
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
async like(selectorCode) {
|
package/src/api/request.js
CHANGED
|
@@ -96,8 +96,13 @@ export default class Request {
|
|
|
96
96
|
|
|
97
97
|
const endpointWithoutSlash = endpoint.replace(/^\/+/, '')
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const urlParts = [baseUrlWithProtocol, this.version, endpointWithoutSlash].filter(Boolean)
|
|
100
|
+
|
|
101
|
+
return tap(new URL(urlParts.join('/')), (url) => {
|
|
102
|
+
url.search = new URLSearchParams({
|
|
103
|
+
...Object.fromEntries(new URLSearchParams(url.search)),
|
|
104
|
+
...this.queryParameters,
|
|
105
|
+
}).toString()
|
|
101
106
|
})
|
|
102
107
|
}
|
|
103
108
|
}
|
package/src/config/config.js
CHANGED
|
@@ -15,11 +15,38 @@ class Configuration {
|
|
|
15
15
|
return this
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async
|
|
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
|
}
|