seatsio 65.1.0 → 65.2.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
@@ -38,10 +38,31 @@ seatsio-js follows semver since v54.4.0.
38
38
 
39
39
  Please note that any version below v2 is not production ready.
40
40
 
41
- ## Examples
41
+ ## Usage
42
+
43
+ ### General instructions
44
+
45
+ To use this library, you'll need to create a `SeatsioClient`:
46
+
47
+ ```js
48
+ import { SeatsioClient, Region } from 'seatsio'
49
+
50
+ let client = new SeatsioClient(Region.EU(), <WORKSPACE SECRET KEY>)
51
+ ...
52
+ ```
53
+
54
+ You can find your _workspace secret key_ in the [settings section of the workspace](https://app.seats.io/workspace-settings). It is important that you keep your _secret key_ private and not expose it in-browser calls unless it is password protected.
55
+
56
+ The region should correspond to the region of your account:
57
+
58
+ - `Region.EU()`: Europe
59
+ - `Region.NA()`: North-America
60
+ - `Region.SA()`: South-America
61
+ - `Region.OC()`: Oceania
62
+
63
+ If you're unsure about your region, have a look at your [company settings page](https://app.seats.io/company-settings).
42
64
 
43
65
  ### Creating a chart and an event
44
- Once you create a new `SeatsioClient` using your _secret key_, you can create _charts_ and then _events_. You can find your _secret key_ in the Settings section of your workspace: https://app.seats.io/workspace-settings. It is important that you keep your _secret key_ private and not expose it in-browser calls unless it is password protected.
45
66
 
46
67
  ```js
47
68
  import { SeatsioClient, Region } from 'seatsio'
@@ -257,10 +278,10 @@ When an API call results in an error, a rejected promise is returned with a valu
257
278
 
258
279
  ```json
259
280
  {
260
- errors: [{ code: 'RATE_LIMIT_EXCEEDED', message: 'Rate limit exceeded' }],
261
- messages: ['Rate limit exceeded'],
262
- requestId: '123456',
263
- status: 429
281
+ "errors": [{ "code": "RATE_LIMIT_EXCEEDED", "message": "Rate limit exceeded" }],
282
+ "messages": ["Rate limit exceeded"],
283
+ "requestId": "123456",
284
+ "status": 429
264
285
  }
265
286
  ```
266
287
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seatsio",
3
- "version": "65.1.0",
3
+ "version": "65.2.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",
@@ -22,7 +22,7 @@
22
22
  "eslint-config-standard": "16.0.3",
23
23
  "eslint-plugin-import": "2.25.3",
24
24
  "eslint-plugin-node": "11.1.0",
25
- "eslint-plugin-promise": "5.2.0",
25
+ "eslint-plugin-promise": "6.0.0",
26
26
  "eslint-plugin-standard": "5.0.0",
27
27
  "gulp": "latest",
28
28
  "gulp-buffer": "latest",
@@ -30,8 +30,8 @@
30
30
  "gulp-tap": "latest",
31
31
  "gulp-uglify": "latest",
32
32
  "gulp-uglify-es": "latest",
33
- "jest": "27.4.3",
34
- "jest-cli": "27.4.3",
33
+ "jest": "27.4.5",
34
+ "jest-cli": "27.4.5",
35
35
  "uuid": "8.3.2"
36
36
  }
37
37
  }
@@ -5,11 +5,6 @@ class ChartReports {
5
5
  this.client = client
6
6
  }
7
7
 
8
- fetchReport (reportType, eventKey, bookWholeTables) {
9
- return this.client.get(`/reports/charts/${encodeURIComponent(eventKey)}/${reportType}`, { params: { bookWholeTables } })
10
- .then((res) => utilities.createChartReport(res.data))
11
- }
12
-
13
8
  /**
14
9
  * @param {string} chartKey
15
10
  * @param {string} bookWholeTables
@@ -28,6 +23,15 @@ class ChartReports {
28
23
  return this.fetchReport('byObjectType', chartKey, bookWholeTables)
29
24
  }
30
25
 
26
+ /**
27
+ * @param {string} chartKey
28
+ * @returns {Object} JSON response from the server
29
+ */
30
+ summaryByObjectType (chartKey) {
31
+ return this.client.get(ChartReports.summaryReportUrl('byObjectType', chartKey))
32
+ .then((res) => res.data)
33
+ }
34
+
31
35
  /**
32
36
  * @param {string} chartKey
33
37
  * @param {string} bookWholeTables
@@ -37,6 +41,15 @@ class ChartReports {
37
41
  return this.fetchReport('byCategoryLabel', chartKey, bookWholeTables)
38
42
  }
39
43
 
44
+ /**
45
+ * @param {string} chartKey
46
+ * @returns {Object} JSON response from the server
47
+ */
48
+ summaryByCategoryLabel (chartKey) {
49
+ return this.client.get(ChartReports.summaryReportUrl('byCategoryLabel', chartKey))
50
+ .then((res) => res.data)
51
+ }
52
+
40
53
  /**
41
54
  * @param {string} chartKey
42
55
  * @param {string} bookWholeTables
@@ -45,6 +58,42 @@ class ChartReports {
45
58
  byCategoryKey (chartKey, bookWholeTables = undefined) {
46
59
  return this.fetchReport('byCategoryKey', chartKey, bookWholeTables)
47
60
  }
61
+
62
+ /**
63
+ * @param {string} chartKey
64
+ * @returns {Object} JSON response from the server
65
+ */
66
+ summaryByCategoryKey (chartKey) {
67
+ return this.client.get(ChartReports.summaryReportUrl('byCategoryKey', chartKey))
68
+ .then((res) => res.data)
69
+ }
70
+
71
+ /**
72
+ * @param {string} chartKey
73
+ * @param {string} bookWholeTables
74
+ * @returns {Object.<string, ChartObjectInfo[]>}
75
+ */
76
+ bySection (chartKey, bookWholeTables = undefined) {
77
+ return this.fetchReport('bySection', chartKey, bookWholeTables)
78
+ }
79
+
80
+ /**
81
+ * @param {string} chartKey
82
+ * @returns {Object} JSON response from the server
83
+ */
84
+ summaryBySection (chartKey) {
85
+ return this.client.get(ChartReports.summaryReportUrl('bySection', chartKey))
86
+ .then((res) => res.data)
87
+ }
88
+
89
+ fetchReport (reportType, eventKey, bookWholeTables) {
90
+ return this.client.get(`/reports/charts/${encodeURIComponent(eventKey)}/${reportType}`, { params: { bookWholeTables } })
91
+ .then((res) => utilities.createChartReport(res.data))
92
+ }
93
+
94
+ static summaryReportUrl (reportType, eventKey) {
95
+ return `/reports/charts/${encodeURIComponent(eventKey)}/${reportType}/summary`
96
+ }
48
97
  }
49
98
 
50
99
  module.exports = ChartReports
@@ -119,3 +119,14 @@ test('get report byCategoryLabel', async () => {
119
119
  expect(report.Cat1.length).toBe(17)
120
120
  expect(report.Cat2.length).toBe(17)
121
121
  })
122
+
123
+ test('get report bySection', async () => {
124
+ const { client, user } = await testUtils.createTestUserAndClient()
125
+ const chartKey = testUtils.getChartKey()
126
+ await testUtils.createTestChartWithSections(chartKey, user.secretKey)
127
+
128
+ const report = await client.chartReports.bySection(chartKey)
129
+
130
+ expect(report['Section A'].length).toBe(36)
131
+ expect(report['Section B'].length).toBe(35)
132
+ })
@@ -0,0 +1,120 @@
1
+ const testUtils = require('../testUtils.js')
2
+
3
+ test('summaryByObjectType', async () => {
4
+ const { client, user } = await testUtils.createTestUserAndClient()
5
+ const chartKey = testUtils.getChartKey()
6
+ await testUtils.createTestChart(chartKey, user.secretKey)
7
+
8
+ const report = await client.chartReports.summaryByObjectType(chartKey)
9
+
10
+ expect(report).toEqual({
11
+ seat: {
12
+ count: 32,
13
+ bySection: { NO_SECTION: 32 },
14
+ byCategoryKey: { 9: 16, 10: 16 },
15
+ byCategoryLabel: { Cat1: 16, Cat2: 16 }
16
+ },
17
+ generalAdmission: {
18
+ count: 200,
19
+ bySection: { NO_SECTION: 200 },
20
+ byCategoryKey: { 9: 100, 10: 100 },
21
+ byCategoryLabel: { Cat2: 100, Cat1: 100 }
22
+ },
23
+ table: {
24
+ count: 0,
25
+ bySection: {},
26
+ byCategoryKey: {},
27
+ byCategoryLabel: {}
28
+ },
29
+ booth: {
30
+ count: 0,
31
+ bySection: {},
32
+ byCategoryKey: {},
33
+ byCategoryLabel: {}
34
+ }
35
+ })
36
+ })
37
+
38
+ test('summaryByCategoryKey', async () => {
39
+ const { client, user } = await testUtils.createTestUserAndClient()
40
+ const chartKey = testUtils.getChartKey()
41
+ await testUtils.createTestChart(chartKey, user.secretKey)
42
+
43
+ const report = await client.chartReports.summaryByCategoryKey(chartKey)
44
+
45
+ expect(report).toEqual({
46
+ 9: {
47
+ count: 116,
48
+ bySection: { NO_SECTION: 116 },
49
+ byObjectType: {
50
+ generalAdmission: 100,
51
+ seat: 16
52
+ }
53
+ },
54
+ 10: {
55
+ count: 116,
56
+ bySection: { NO_SECTION: 116 },
57
+ byObjectType: {
58
+ generalAdmission: 100,
59
+ seat: 16
60
+ }
61
+ },
62
+ NO_CATEGORY: {
63
+ count: 0,
64
+ bySection: {},
65
+ byObjectType: {}
66
+ }
67
+ })
68
+ })
69
+
70
+ test('summaryByCategoryLabel', async () => {
71
+ const { client, user } = await testUtils.createTestUserAndClient()
72
+ const chartKey = testUtils.getChartKey()
73
+ await testUtils.createTestChart(chartKey, user.secretKey)
74
+
75
+ const report = await client.chartReports.summaryByCategoryLabel(chartKey)
76
+
77
+ expect(report).toEqual({
78
+ Cat2: {
79
+ count: 116,
80
+ bySection: { NO_SECTION: 116 },
81
+ byObjectType: {
82
+ generalAdmission: 100,
83
+ seat: 16
84
+ }
85
+ },
86
+ Cat1: {
87
+ count: 116,
88
+ bySection: { NO_SECTION: 116 },
89
+ byObjectType: {
90
+ generalAdmission: 100,
91
+ seat: 16
92
+ }
93
+ },
94
+ NO_CATEGORY: {
95
+ count: 0,
96
+ bySection: {},
97
+ byObjectType: {}
98
+ }
99
+ })
100
+ })
101
+
102
+ test('summaryBySection', async () => {
103
+ const { client, user } = await testUtils.createTestUserAndClient()
104
+ const chartKey = testUtils.getChartKey()
105
+ await testUtils.createTestChart(chartKey, user.secretKey)
106
+
107
+ const report = await client.chartReports.summaryBySection(chartKey)
108
+
109
+ expect(report).toEqual({
110
+ NO_SECTION: {
111
+ count: 232,
112
+ byCategoryKey: { 9: 116, 10: 116 },
113
+ byCategoryLabel: { Cat2: 116, Cat1: 116 },
114
+ byObjectType: {
115
+ generalAdmission: 200,
116
+ seat: 32
117
+ }
118
+ }
119
+ })
120
+ })
@@ -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://mockbin.org'))
5
+ const client = new SeatsioClient(new Region('https://httpbin.org'))
6
6
  const start = new Date()
7
7
  try {
8
- await client.client.get('/bin/0381d6f4-0155-4b8c-937b-73d3d88b2a3f')
8
+ await client.client.get('/status/429')
9
9
  throw new Error('Should have failed')
10
10
  } catch (e) {
11
- expect(e).toEqual({ errors: [{ code: 'RATE_LIMIT_EXCEEDED', message: 'Rate limit exceeded' }], messages: [], requestId: '123456', status: 429 })
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,26 +16,26 @@ 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://mockbin.org'))
19
+ const client = new SeatsioClient(new Region('https://httpbin.org'))
20
20
  const start = new Date()
21
21
  try {
22
- await client.client.get('/bin/1eea3aab-2bb2-4f92-99c2-50d942fb6294')
22
+ await client.client.get('/status/400')
23
23
  throw new Error('Should have failed')
24
24
  } catch (e) {
25
- expect(e).toBe('get /bin/1eea3aab-2bb2-4f92-99c2-50d942fb6294 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://mockbin.org')).setMaxRetries(0)
32
+ const client = new SeatsioClient(new Region('https://httpbin.org')).setMaxRetries(0)
33
33
  const start = new Date()
34
34
  try {
35
- await client.client.get('/bin/0381d6f4-0155-4b8c-937b-73d3d88b2a3f')
35
+ await client.client.get('/status/429')
36
36
  throw new Error('Should have failed')
37
37
  } catch (e) {
38
- expect(e).toEqual({ errors: [{ code: 'RATE_LIMIT_EXCEEDED', message: 'Rate limit exceeded' }], messages: [], requestId: '123456', status: 429 })
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
  }