@dpgradio/creative 9.0.0 → 9.0.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.
@@ -13,7 +13,7 @@ jobs:
13
13
  cache: npm
14
14
  registry-url: "https://registry.npmjs.org" # This is needed to make npm publish work...
15
15
  - run: npm ci
16
- - run: npm version ${{ github.event.release.tag_name }} --no-git-tag-version
16
+ - run: npm version ${{ github.event.release.tag_name }} --no-git-tag-version --allow-same-version
17
17
  - run: npm publish
18
18
  env:
19
19
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpgradio/creative",
3
- "version": "9.0.0",
3
+ "version": "9.0.1",
4
4
  "description": "Support package for standalone Javascript applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -19,6 +19,8 @@ class Authentication {
19
19
 
20
20
  this.radioTokenListeners = []
21
21
  this.askingForLoginListeners = []
22
+
23
+ this._refreshTokenPromise = null
22
24
  }
23
25
 
24
26
  initialize() {
@@ -114,7 +116,7 @@ class Authentication {
114
116
  })
115
117
  }
116
118
 
117
- async refreshToken() {
119
+ async _doRefreshToken() {
118
120
  if (hybrid.isNativeApp()) {
119
121
  const updatedToken = Promise.race([
120
122
  new Promise((resolve) => {
@@ -136,6 +138,9 @@ class Authentication {
136
138
  'Content-Type': 'application/json',
137
139
  },
138
140
  })
141
+ if (!response.ok) {
142
+ throw new Error(`Failed to refresh token: ${response.status} ${response.statusText}`)
143
+ }
139
144
  const token = (await response.json()).radioToken
140
145
  localStorage.setItem(RADIO_TOKEN_LOCAL_STORAGE_KEY, token)
141
146
  return token
@@ -145,6 +150,18 @@ class Authentication {
145
150
  }
146
151
  }
147
152
  }
153
+
154
+ async refreshToken() {
155
+ if (this._refreshTokenPromise) {
156
+ return this._refreshTokenPromise
157
+ }
158
+ this._refreshTokenPromise = this._doRefreshToken()
159
+ try {
160
+ return await this._refreshTokenPromise
161
+ } finally {
162
+ this._refreshTokenPromise = null
163
+ }
164
+ }
148
165
  }
149
166
 
150
167
  export default new Authentication()