Skip to content

Commit eecb61d

Browse files
committed
chore: Remove deprecated request library in favour of got
1 parent 10ef534 commit eecb61d

File tree

8 files changed

+191
-321
lines changed

8 files changed

+191
-321
lines changed

doc/architecture_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ This might be an option to explore further if other approaches are unsuccessful.
138138
A simple Node.js application has been written ([`cli_bund.js`](../scratch/cli_bund.js)) that allows interaction with the an MSE to change the text of a lower third overlay, _take-in_ the graphic, wait ten seconds and _take-out_ the graphic. This will be the basis of ongoing development, using the following modules:
139139

140140
- [`ws`](https://www.npmjs.com/package/ws) to connect to the MSE over webscockets with PepTalk. Used for reading and writing data and monitoring events.
141-
- [`request-promise-native`](https://www.npmjs.com/package/request-promise-native) to POST commands to the REST interface of the MSE.
141+
- [`got`](https://www.npmjs.com/package/got) to POST commands to the REST interface of the MSE.
142142

143143
So as to work with the XML structures in a Javascript-like format, the following library will be used:
144144

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@
114114
"/LICENSE"
115115
],
116116
"dependencies": {
117-
"request": "^2.88.2",
118-
"request-promise-native": "^1.0.9",
117+
"got": "11.8.6",
119118
"uuid": "^8.3.2",
120119
"ws": "^7.4.6",
121120
"xml2js": "^0.4.23"
@@ -126,8 +125,6 @@
126125
"@types/koa": "^2.11.6",
127126
"@types/koa-bodyparser": "^4.3.0",
128127
"@types/node": "^12.19.15",
129-
"@types/request": "^2.48.5",
130-
"@types/request-promise-native": "^1.0.17",
131128
"@types/uuid": "^8.3.0",
132129
"@types/ws": "^7.4.0",
133130
"@types/xml2js": "^0.4.8",

scratch/cli_bund.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const request = require('request-promise-native')
1+
const got = require('got')
22
const ws = require('ws')
33

44
let webby = new ws('ws://1d8dab0e.ngrok.io/')
@@ -19,18 +19,18 @@ webby.on('open', () => {
1919
)
2020

2121
setTimeout(() => {
22-
request.post({
22+
got({
2323
method: 'POST',
24-
uri: 'http://62918c05.ngrok.io/profiles/MOSART/take',
24+
url: 'http://62918c05.ngrok.io/profiles/MOSART/take',
2525
body: '/storage/shows/{239F365A-5671-43F3-AD44-D44EB7C4F206}/elements/100_NYHEDERNE-TEST.SOFIE.VIZ-ELEMENTER_271DB363_0',
2626
})
2727
console.log('>>> Take requested')
2828
}, 500)
2929

3030
setTimeout(() => {
31-
request.post({
31+
got({
3232
method: 'POST',
33-
uri: 'http://62918c05.ngrok.io/profiles/MOSART/out',
33+
url: 'http://62918c05.ngrok.io/profiles/MOSART/out',
3434
body: '/storage/shows/{239F365A-5671-43F3-AD44-D44EB7C4F206}/elements/100_NYHEDERNE-TEST.SOFIE.VIZ-ELEMENTER_271DB363_0',
3535
})
3636
console.log('>>> Out requested')

scratch/experiments/cli_other.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const request = require('request-promise-native')
1+
const got = require('got')
22
const ws = require('ws')
33

44
let webby = new ws('ws://1d8dab0e.ngrok.io/')
@@ -17,18 +17,18 @@ webby.on('open', () => {
1717
)
1818

1919
setTimeout(() => {
20-
request.post({
20+
got({
2121
method: 'POST',
22-
uri: 'http://62918c05.ngrok.io/profiles/MOSART/take',
22+
url: 'http://62918c05.ngrok.io/profiles/MOSART/take',
2323
body: '/storage/shows/{66E45216-9476-4BDC-9556-C3DB487ED9DF}/elements/SUPERFLY',
2424
})
2525
console.log('>>> Take requested')
2626
}, 500)
2727

2828
setTimeout(() => {
29-
request.post({
29+
got({
3030
method: 'POST',
31-
uri: 'http://62918c05.ngrok.io/profiles/MOSART/out',
31+
url: 'http://62918c05.ngrok.io/profiles/MOSART/out',
3232
body: '/storage/shows/{66E45216-9476-4BDC-9556-C3DB487ED9DF}/elements/SUPERFLY',
3333
})
3434
console.log('>>> Out requested')

scratch/experiments/cli_sm_gfx.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const request = require('request-promise-native')
1+
const got = require('got')
22
const ws = require('ws')
33

44
let webby = new ws('ws://1d8dab0e.ngrok.io/')
@@ -15,18 +15,18 @@ webby.on('open', () => {
1515
// webby.send(`3 replace {76}/storage/shows/{66E45216-9476-4BDC-9556-C3DB487ED9DF}/elements/SUPERFLY/data {${change.length}}${change}\n\n`);
1616

1717
setTimeout(() => {
18-
request.post({
18+
got({
1919
method: 'POST',
20-
uri: 'http://62918c05.ngrok.io/profiles/MOSART/take',
20+
url: 'http://62918c05.ngrok.io/profiles/MOSART/take',
2121
body: '/storage/shows/{66E45216-9476-4BDC-9556-C3DB487ED9DF}/elements/SUPERFLY2',
2222
})
2323
console.log('>>> Take requested')
2424
}, 500)
2525

2626
setTimeout(() => {
27-
request.post({
27+
got({
2828
method: 'POST',
29-
uri: 'http://62918c05.ngrok.io/profiles/MOSART/out',
29+
url: 'http://62918c05.ngrok.io/profiles/MOSART/out',
3030
body: '/storage/shows/{66E45216-9476-4BDC-9556-C3DB487ED9DF}/elements/SUPERFLY2',
3131
})
3232
console.log('>>> Out requested')

src/__tests__/msehttp.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Koa from 'koa'
22
import * as bodyParser from 'koa-bodyparser'
3-
import * as request from 'request-promise-native'
3+
import got from 'got'
44
import * as http from 'http'
55
import * as uuid from 'uuid'
66
import { createHTTPContext, HttpMSEClient } from '../msehttp'
@@ -99,8 +99,8 @@ describe('MSE HTTP library when happy', () => {
9999
})
100100

101101
test('Basic connection test', async () => {
102-
const fromMe = await request(`http://localhost:${testPort}`)
103-
expect(fromMe).toBe('Look at me')
102+
const fromMe = await got(`http://localhost:${testPort}`)
103+
expect(fromMe.body).toBe('Look at me')
104104
})
105105

106106
test('Ping test', async () => {
@@ -196,7 +196,9 @@ describe('MSE HTTP library when happy', () => {
196196
test('Trigger timeout', async () => {
197197
msehttp.setHTTPTimeout(300)
198198
expect(msehttp.timeout).toBe(300)
199-
await expect(msehttp.command('timeout', '/running/out/of/time')).rejects.toThrow('ESOCKETTIMEDOUT')
199+
await expect(msehttp.command('timeout', '/running/out/of/time')).rejects.toThrow(
200+
"Timeout awaiting 'request' for 300ms"
201+
)
200202
msehttp.setHTTPTimeout(3000)
201203
expect(msehttp.timeout).toBe(3000)
202204
})

src/msehttp.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { URL } from 'url'
7-
import * as request from 'request-promise-native'
7+
import got from 'got'
88
import { ServerResponse } from 'http'
99

1010
export const uuidRe = /[a-fA-f0-9]{8}-[a-fA-f0-9]{4}-[a-fA-f0-9]{4}-[a-fA-f0-9]{4}-[a-fA-f0-9]{12}/
@@ -233,18 +233,18 @@ class MSEHTTP implements HttpMSEClient {
233233
async command(path: string | URL, body: string): Promise<CommandResult> {
234234
try {
235235
if (typeof path === 'string') {
236-
const response = await request({
236+
const response = await got({
237237
method: 'POST',
238-
uri: `${this.baseURL}/${path}`,
238+
url: `${this.baseURL}/${path}`,
239239
body,
240240
timeout: this.timeout,
241241
headers: {
242242
'Content-Type': 'text/plain',
243243
},
244244
})
245-
return { status: 200, response: response.toString() } as CommandResult
245+
return { status: 200, response: response.body.toString() } as CommandResult
246246
} else {
247-
const response = await request({
247+
const response = await got({
248248
method: 'POST',
249249
url: path.toString(),
250250
body,
@@ -253,7 +253,7 @@ class MSEHTTP implements HttpMSEClient {
253253
'Content-Type': 'text/plain',
254254
},
255255
})
256-
return { status: 200, response: response.toString() } as CommandResult
256+
return { status: 200, response: response.body.toString() } as CommandResult
257257
}
258258
} catch (err) {
259259
throw this.processError(err, typeof path === 'string' ? `${this.baseURL}/${path}` : path.toString(), body)
@@ -303,9 +303,9 @@ class MSEHTTP implements HttpMSEClient {
303303

304304
async ping(): Promise<CommandResult> {
305305
try {
306-
await request.get({
306+
await got({
307307
method: 'GET',
308-
uri: this.baseURL,
308+
url: this.baseURL,
309309
timeout: this.timeout,
310310
})
311311
return { status: 200, response: 'PONG!' } as CommandResult

0 commit comments

Comments
 (0)