seatsio 72.2.0 → 72.4.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 CHANGED
@@ -256,6 +256,18 @@ let event = await client.events.create(chart.key)
256
256
  console.log(`Created a chart with key ${chart.key} and an event with key: ${event.key}`)
257
257
  ```
258
258
 
259
+ ### Listing categories
260
+
261
+ ```js
262
+ import { SeatsioClient, Region } from 'seatsio'
263
+
264
+ let client = new SeatsioClient(Region.EU(), <COMPANY ADMIN KEY>, <WORKSPACE PUBLIC KEY>)
265
+ let categories = await client.charts.listCategories("the chart key")
266
+ for (const category of categoryList) {
267
+ console.log(category.label)
268
+ }
269
+ ```
270
+
259
271
  ## Error Handling
260
272
  When an API call results in an error, a rejected promise is returned with a value that looks like
261
273
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seatsio",
3
- "version": "72.2.0",
3
+ "version": "72.4.0",
4
4
  "main": "index.js",
5
5
  "description": "Official JavaScript and Node.JS client library for the Seats.io REST API",
6
6
  "license": "MIT",
@@ -13,16 +13,16 @@
13
13
  "url": "https://github.com/seatsio/seatsio-js"
14
14
  },
15
15
  "dependencies": {
16
- "axios": "1.2.2"
16
+ "axios": "1.3.4"
17
17
  },
18
18
  "devDependencies": {
19
- "eslint": "8.31.0",
19
+ "eslint": "8.35.0",
20
20
  "eslint-config-standard": "17.0.0",
21
- "eslint-plugin-import": "2.26.0",
22
- "eslint-plugin-n": "15.6.0",
21
+ "eslint-plugin-import": "2.27.5",
22
+ "eslint-plugin-n": "15.6.1",
23
23
  "eslint-plugin-promise": "6.1.1",
24
- "jest": "29.3.1",
25
- "jest-cli": "29.3.1",
24
+ "jest": "29.4.3",
25
+ "jest-cli": "29.4.3",
26
26
  "uuid": "9.0.0"
27
27
  }
28
28
  }
@@ -68,6 +68,11 @@ class Charts {
68
68
  return this.client.delete(`/charts/${chartKey}/categories/${categoryKey}`)
69
69
  }
70
70
 
71
+ listCategories (key) {
72
+ return this.client.get(`/charts/${key}/categories`)
73
+ .then((res) => res.data.categories)
74
+ }
75
+
71
76
  /**
72
77
  * @param {string} key
73
78
  * @returns {object}
@@ -16,6 +16,10 @@ class Channels {
16
16
  })
17
17
  }
18
18
 
19
+ addMultiple (eventKey, channelCreationParams) {
20
+ return this.client.post(`/events/${encodeURIComponent(eventKey)}/channels`, channelCreationParams)
21
+ }
22
+
19
23
  remove (eventKey, channelKey) {
20
24
  return this.client.delete(`/events/${encodeURIComponent(eventKey)}/channels/${encodeURIComponent(channelKey)}`)
21
25
  }
@@ -30,3 +30,15 @@ test('should remove a category', async () => {
30
30
  const retrievedChart = await client.charts.retrievePublishedVersion(chart.key)
31
31
  expect(retrievedChart.categories.list).toEqual([{ key: 1, label: 'Category 1', color: '#aaaaaa', accessible: false }])
32
32
  })
33
+
34
+ test('should retrieve the categories of a chart', async () => {
35
+ const { client } = await testUtils.createTestUserAndClient()
36
+ const categories = [
37
+ { key: 1, label: 'Category 1', color: '#aaaaaa', accessible: false },
38
+ { key: 'cat2', label: 'Category 2', color: '#bbbbbb', accessible: true }
39
+ ]
40
+ const chart = await client.charts.create('aChart', null, categories)
41
+
42
+ const categoryList = await client.charts.listCategories(chart.key)
43
+ expect(categoryList).toEqual(categories)
44
+ })
@@ -31,6 +31,42 @@ test('can add a channel', async () => {
31
31
  ])
32
32
  })
33
33
 
34
+ test('can add multiple channels', async () => {
35
+ const {
36
+ client,
37
+ user
38
+ } = await testUtils.createTestUserAndClient()
39
+ const chartKey = testUtils.getChartKey()
40
+ await testUtils.createTestChart(chartKey, user.secretKey)
41
+ const event = await client.events.create(chartKey)
42
+
43
+ await client.events.channels.addMultiple(
44
+ event.key,
45
+ [
46
+ { key: 'channelKey1', name: 'channel 1', color: '#FFFF98', index: 1, objects: ['A-1', 'A-2'] },
47
+ { key: 'channelKey2', name: 'channel 2', color: '#FFFF99', index: 2, objects: ['A-3'] }
48
+ ]
49
+ )
50
+
51
+ const retrievedEvent = await client.events.retrieve(event.key)
52
+ expect(retrievedEvent.channels).toEqual([
53
+ new Channel({
54
+ key: 'channelKey1',
55
+ name: 'channel 1',
56
+ color: '#FFFF98',
57
+ index: 1,
58
+ objects: ['A-1', 'A-2']
59
+ }),
60
+ new Channel({
61
+ key: 'channelKey2',
62
+ name: 'channel 2',
63
+ color: '#FFFF99',
64
+ index: 2,
65
+ objects: ['A-3']
66
+ })
67
+ ])
68
+ })
69
+
34
70
  test('index is optional', async () => {
35
71
  const {
36
72
  client,
@@ -2,13 +2,13 @@ const Region = require('../src/Region')
2
2
  const { SeatsioClient } = require('../index.js')
3
3
 
4
4
  test('aborts eventually if server keeps returning 429', async () => {
5
- const client = new SeatsioClient(new Region('https://httpbin.org'))
5
+ const client = new SeatsioClient(new Region('https://httpbin.seatsio.net'))
6
6
  const start = new Date()
7
7
  try {
8
8
  await client.client.get('/status/429')
9
9
  throw new Error('Should have failed')
10
10
  } catch (e) {
11
- expect(e).toBe('get /status/429 resulted in 429 TOO MANY REQUESTS error')
11
+ expect(e).toBe('get /status/429 resulted in 429 Too Many Requests error')
12
12
  const waitTime = new Date().getTime() - start.getTime()
13
13
  expect(waitTime).toBeGreaterThan(10000)
14
14
  expect(waitTime).toBeLessThan(20000)
@@ -16,33 +16,33 @@ test('aborts eventually if server keeps returning 429', async () => {
16
16
  })
17
17
 
18
18
  test('aborts directly if server returns error other than 429', async () => {
19
- const client = new SeatsioClient(new Region('https://httpbin.org'))
19
+ const client = new SeatsioClient(new Region('https://httpbin.seatsio.net'))
20
20
  const start = new Date()
21
21
  try {
22
22
  await client.client.get('/status/400')
23
23
  throw new Error('Should have failed')
24
24
  } catch (e) {
25
- expect(e).toBe('get /status/400 resulted in 400 BAD REQUEST error')
25
+ expect(e).toBe('get /status/400 resulted in 400 Bad Request error')
26
26
  const waitTime = new Date().getTime() - start.getTime()
27
27
  expect(waitTime).toBeLessThan(2000)
28
28
  }
29
29
  })
30
30
 
31
31
  test('aborts directly if server returns 429 but max retries 0', async () => {
32
- const client = new SeatsioClient(new Region('https://httpbin.org')).setMaxRetries(0)
32
+ const client = new SeatsioClient(new Region('https://httpbin.seatsio.net')).setMaxRetries(0)
33
33
  const start = new Date()
34
34
  try {
35
35
  await client.client.get('/status/429')
36
36
  throw new Error('Should have failed')
37
37
  } catch (e) {
38
- expect(e).toBe('get /status/429 resulted in 429 TOO MANY REQUESTS error')
38
+ expect(e).toBe('get /status/429 resulted in 429 Too Many Requests error')
39
39
  const waitTime = new Date().getTime() - start.getTime()
40
40
  expect(waitTime).toBeLessThan(2000)
41
41
  }
42
42
  })
43
43
 
44
44
  test('returns successfully when the server sends a 429 first, but then a successful response', async () => {
45
- const client = new SeatsioClient(new Region('https://httpbin.org'))
45
+ const client = new SeatsioClient(new Region('https://httpbin.seatsio.net'))
46
46
  for (let i = 0; i < 20; ++i) {
47
47
  const response = await client.client.get('/status/429:0.25,204:0.75')
48
48
  expect(response.status).toBe(204)
@@ -21,13 +21,13 @@ test('should filter subaccounts ', async () => {
21
21
  test('should filter subaccounts with special characters', async () => {
22
22
  const { client } = await testUtils.createTestUserAndClient()
23
23
  let i = 0
24
- await testUtils.createArray(20, () => client.subaccounts.create('test-/@/' + i++))
24
+ await testUtils.createArray(10, () => client.subaccounts.create('test-/@/' + i++))
25
25
  const retrievedSubaccountKeys = []
26
26
  for await (const subaccount of client.subaccounts.listAll('test-/@/1')) {
27
27
  retrievedSubaccountKeys.push(subaccount.secretKey)
28
28
  }
29
29
 
30
- expect(retrievedSubaccountKeys.length).toEqual(11)
30
+ expect(retrievedSubaccountKeys.length).toEqual(1)
31
31
  })
32
32
 
33
33
  test('should filter with no results ', async () => {
@@ -81,14 +81,14 @@ module.exports = {
81
81
  return uuidv4() + '@mailinator.com'
82
82
  },
83
83
 
84
- createArray (length, fn) {
84
+ async createArray (length, fn) {
85
85
  const array = []
86
86
 
87
87
  for (let i = 0; i < length; ++i) {
88
- array.push(fn())
88
+ array.push(await fn())
89
89
  }
90
90
 
91
- return Promise.all(array)
91
+ return array
92
92
  },
93
93
 
94
94
  deferred () {