seatsio 65.0.0 → 66.0.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.
Files changed (33) hide show
  1. package/README.md +27 -6
  2. package/package.json +6 -6
  3. package/src/AsyncIterator.js +14 -0
  4. package/src/Events/EventObjectInfo.js +2 -1
  5. package/src/Events/Events.js +23 -4
  6. package/src/Events/StatusChange.js +2 -0
  7. package/src/Events/StatusChangeRequest.js +5 -1
  8. package/src/Reports/ChartReports.js +55 -5
  9. package/src/Reports/EventReports.js +31 -3
  10. package/src/Seasons/Season.js +16 -0
  11. package/src/Seasons/SeasonParams.js +28 -0
  12. package/src/Seasons/Seasons.js +194 -0
  13. package/src/SeatsioClient.js +2 -0
  14. package/tests/chartReports/chartReport.test.js +11 -0
  15. package/tests/chartReports/chartReportSummary.test.js +155 -0
  16. package/tests/charts/listAllCharts.test.js +4 -8
  17. package/tests/eventReports/eventReport.test.js +31 -1
  18. package/tests/eventReports/eventReportDeepSummary.test.js +14 -0
  19. package/tests/eventReports/eventReportSummary.test.js +99 -9
  20. package/tests/events/changeObjectStatus.test.js +32 -1
  21. package/tests/events/changeObjectStatusInBatch.test.js +34 -0
  22. package/tests/events/listAllStatusChanges.test.js +2 -0
  23. package/tests/exponentialBackoff.test.js +9 -9
  24. package/tests/seasons/addEventsToPartialSeason.test.js +13 -0
  25. package/tests/seasons/createEventsInSeason.test.js +21 -0
  26. package/tests/seasons/createPartialSeason.test.js +22 -0
  27. package/tests/seasons/createSeason.test.js +76 -0
  28. package/tests/seasons/deletePartialSeason.test.js +18 -0
  29. package/tests/seasons/deleteSeason.test.js +17 -0
  30. package/tests/seasons/listAllSeasons.test.js +16 -0
  31. package/tests/seasons/removeEventsFromPartialSeason.test.js +13 -0
  32. package/tests/seasons/retrievePartialSeason.test.js +25 -0
  33. package/tests/seasons/retrieveSeason.test.js +29 -0
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.0.0",
3
+ "version": "66.0.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",
@@ -14,15 +14,15 @@
14
14
  "url": "https://github.com/seatsio/seatsio-js"
15
15
  },
16
16
  "dependencies": {
17
- "axios": "0.24.0"
17
+ "axios": "0.25.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "browserify": "latest",
21
21
  "eslint": "7.32.0",
22
22
  "eslint-config-standard": "16.0.3",
23
- "eslint-plugin-import": "2.25.3",
23
+ "eslint-plugin-import": "2.25.4",
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.7",
34
+ "jest-cli": "27.4.7",
35
35
  "uuid": "8.3.2"
36
36
  }
37
37
  }
@@ -5,6 +5,7 @@ const Event = require('./Events/Event.js')
5
5
  const User = require('./Users/User.js')
6
6
  const Subaccount = require('./Subaccounts/Subaccount.js')
7
7
  const Workspace = require('./Workspaces/Workspace.js')
8
+ const Season = require('./Seasons/Season')
8
9
 
9
10
  class AsyncIterator {
10
11
  /**
@@ -45,6 +46,16 @@ class AsyncIterator {
45
46
  this.pages.push(new Page(events, data.next_page_starts_after, data.previous_page_ends_before))
46
47
  }
47
48
 
49
+ seasons (data) {
50
+ const seasons = []
51
+ data.items.forEach(seasonData => {
52
+ const season = new Season(seasonData)
53
+ this.items.push(season)
54
+ seasons.push(season)
55
+ })
56
+ this.pages.push(new Page(seasons, data.next_page_starts_after, data.previous_page_ends_before))
57
+ }
58
+
48
59
  statusChanges (data) {
49
60
  const statusChanges = []
50
61
  data.items.forEach((statusData) => {
@@ -102,6 +113,9 @@ class AsyncIterator {
102
113
  case 'events':
103
114
  this.events(res.data)
104
115
  break
116
+ case 'seasons':
117
+ this.seasons(res.data)
118
+ break
105
119
  case 'statusChanges':
106
120
  this.statusChanges(res.data)
107
121
  break
@@ -31,7 +31,8 @@ class EventObjectInfo {
31
31
  this.displayedObjectType = report.displayedObjectType
32
32
  this.leftNeighbour = report.leftNeighbour
33
33
  this.rightNeighbour = report.rightNeighbour
34
- this.isSelectable = report.isSelectable
34
+ this.isAvailable = report.isAvailable
35
+ this.availabilityReason = report.availabilityReason
35
36
  this.isDisabledBySocialDistancing = report.isDisabledBySocialDistancing
36
37
  this.channel = report.channel
37
38
  this.distanceToFocalPoint = report.distanceToFocalPoint
@@ -272,9 +272,11 @@ class Events {
272
272
  * @param {?string[]} channelKeys
273
273
  * @param {?boolean} ignoreSocialDistancing
274
274
  * @returns {Promise<ChangeObjectStatusResult>}
275
+ * @param {?string[]} allowedPreviousStatuses
276
+ * @param {?string[]} rejectedPreviousStatuses
275
277
  */
276
- changeObjectStatus (eventKeyOrKeys, objectOrObjects, status, holdToken = null, orderId = null, keepExtraData = null, ignoreChannels = null, channelKeys = null, ignoreSocialDistancing = null) {
277
- const request = this.changeObjectStatusRequest(objectOrObjects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, ignoreSocialDistancing)
278
+ changeObjectStatus (eventKeyOrKeys, objectOrObjects, status, holdToken = null, orderId = null, keepExtraData = null, ignoreChannels = null, channelKeys = null, ignoreSocialDistancing = null, allowedPreviousStatuses = null, rejectedPreviousStatuses = null) {
279
+ const request = this.changeObjectStatusRequest(objectOrObjects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, ignoreSocialDistancing, allowedPreviousStatuses, rejectedPreviousStatuses)
278
280
  request.events = Array.isArray(eventKeyOrKeys) ? eventKeyOrKeys : [eventKeyOrKeys]
279
281
 
280
282
  return this.client.post('/events/groups/actions/change-object-status?expand=objects', request)
@@ -287,7 +289,18 @@ class Events {
287
289
  */
288
290
  changeObjectStatusInBatch (statusChangeRequests) {
289
291
  const requests = statusChangeRequests.map(r => {
290
- const json = this.changeObjectStatusRequest(r.objectOrObjects, r.status, r.holdToken, r.orderId, r.keepExtraData, r.ignoreChannels, r.channelKeys)
292
+ const json = this.changeObjectStatusRequest(
293
+ r.objectOrObjects,
294
+ r.status,
295
+ r.holdToken,
296
+ r.orderId,
297
+ r.keepExtraData,
298
+ r.ignoreChannels,
299
+ r.channelKeys,
300
+ null,
301
+ r.allowedPreviousStatuses,
302
+ r.rejectedPreviousStatuses
303
+ )
291
304
  json.event = r.eventKey
292
305
  return json
293
306
  })
@@ -297,7 +310,7 @@ class Events {
297
310
  .then((res) => res.data.results.map(r => new ChangeObjectStatusResult(r.objects)))
298
311
  }
299
312
 
300
- changeObjectStatusRequest (objectOrObjects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, ignoreSocialDistancing) {
313
+ changeObjectStatusRequest (objectOrObjects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, ignoreSocialDistancing, allowedPreviousStatuses, rejectedPreviousStatuses) {
301
314
  const request = {}
302
315
  request.objects = this.normalizeObjects(objectOrObjects)
303
316
  request.status = status
@@ -319,6 +332,12 @@ class Events {
319
332
  if (ignoreSocialDistancing !== null) {
320
333
  request.ignoreSocialDistancing = ignoreSocialDistancing
321
334
  }
335
+ if (allowedPreviousStatuses !== null) {
336
+ request.allowedPreviousStatuses = allowedPreviousStatuses
337
+ }
338
+ if (rejectedPreviousStatuses !== null) {
339
+ request.rejectedPreviousStatuses = rejectedPreviousStatuses
340
+ }
322
341
  return request
323
342
  }
324
343
 
@@ -13,6 +13,8 @@ class StatusChange {
13
13
  this.extraData = statusChange.extraData ? statusChange.extraData : null
14
14
  this.holdToken = statusChange.holdToken ? statusChange.holdToken : null
15
15
  this.origin = statusChange.origin
16
+ this.isPresentOnChart = statusChange.isPresentOnChart
17
+ this.displayedLabel = statusChange.displayedLabel ? statusChange.displayedLabel : null
16
18
  }
17
19
  }
18
20
 
@@ -8,8 +8,10 @@ class StatusChangeRequest {
8
8
  * @param {?boolean} keepExtraData
9
9
  * @param {?boolean} ignoreChannels
10
10
  * @param {?string[]} channelKeys
11
+ * @param {?string[]} allowedPreviousStatuses
12
+ * @param {?string[]} rejectedPreviousStatuses
11
13
  */
12
- constructor (eventKey, objectOrObjects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys) {
14
+ constructor (eventKey, objectOrObjects, status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses) {
13
15
  this.eventKey = eventKey
14
16
  this.objectOrObjects = objectOrObjects
15
17
  this.status = status
@@ -18,6 +20,8 @@ class StatusChangeRequest {
18
20
  this.keepExtraData = keepExtraData
19
21
  this.ignoreChannels = ignoreChannels
20
22
  this.channelKeys = channelKeys
23
+ this.allowedPreviousStatuses = allowedPreviousStatuses
24
+ this.rejectedPreviousStatuses = rejectedPreviousStatuses
21
25
  }
22
26
  }
23
27
 
@@ -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
+ * @param {string} bookWholeTables
29
+ * @returns {Object} JSON response from the server
30
+ */
31
+ summaryByObjectType (chartKey, bookWholeTables = undefined) {
32
+ return this.fetchSummaryReport('byObjectType', chartKey, bookWholeTables)
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
+ * @param {string} bookWholeTables
47
+ * @returns {Object} JSON response from the server
48
+ */
49
+ summaryByCategoryLabel (chartKey, bookWholeTables = undefined) {
50
+ return this.fetchSummaryReport('byCategoryLabel', chartKey, bookWholeTables)
51
+ }
52
+
40
53
  /**
41
54
  * @param {string} chartKey
42
55
  * @param {string} bookWholeTables
@@ -45,6 +58,43 @@ 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
+ * @param {string} bookWholeTables
65
+ * @returns {Object} JSON response from the server
66
+ */
67
+ summaryByCategoryKey (chartKey, bookWholeTables = undefined) {
68
+ return this.fetchSummaryReport('byCategoryKey', chartKey, bookWholeTables)
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
+ * @param {string} bookWholeTables
83
+ * @returns {Object} JSON response from the server
84
+ */
85
+ summaryBySection (chartKey, bookWholeTables = undefined) {
86
+ return this.fetchSummaryReport('bySection', chartKey, bookWholeTables)
87
+ }
88
+
89
+ fetchReport (reportType, chartKey, bookWholeTables) {
90
+ return this.client.get(`/reports/charts/${encodeURIComponent(chartKey)}/${reportType}`, { params: { bookWholeTables } })
91
+ .then((res) => utilities.createChartReport(res.data))
92
+ }
93
+
94
+ fetchSummaryReport (reportType, chartKey, bookWholeTables) {
95
+ return this.client.get(`/reports/charts/${encodeURIComponent(chartKey)}/${reportType}/summary`, { params: { bookWholeTables } })
96
+ .then((res) => res.data)
97
+ }
48
98
  }
49
99
 
50
100
  module.exports = ChartReports
@@ -167,11 +167,21 @@ class EventReports {
167
167
 
168
168
  /**
169
169
  * @param {string} eventKey
170
- * @param {?string} selectability
170
+ * @param {?string} availability
171
171
  * @returns {Object.<string, ObjectInfo[]>}
172
172
  */
173
- byAvailability (eventKey, selectability = null) {
174
- return this.client.get(EventReports.reportUrl('byAvailability', eventKey, selectability))
173
+ byAvailability (eventKey, availability = null) {
174
+ return this.client.get(EventReports.reportUrl('byAvailability', eventKey, availability))
175
+ .then((res) => utilities.createEventReport(res.data))
176
+ }
177
+
178
+ /**
179
+ * @param {string} eventKey
180
+ * @param {?string} availabilityReason
181
+ * @returns {Object.<string, ObjectInfo[]>}
182
+ */
183
+ byAvailabilityReason (eventKey, availabilityReason = null) {
184
+ return this.client.get(EventReports.reportUrl('byAvailabilityReason', eventKey, availabilityReason))
175
185
  .then((res) => utilities.createEventReport(res.data))
176
186
  }
177
187
 
@@ -184,6 +194,15 @@ class EventReports {
184
194
  .then((res) => res.data)
185
195
  }
186
196
 
197
+ /**
198
+ * @param {string} eventKey
199
+ * @returns {Object} JSON response from the server
200
+ */
201
+ summaryByAvailabilityReason (eventKey) {
202
+ return this.client.get(EventReports.summaryReportUrl('byAvailabilityReason', eventKey))
203
+ .then((res) => res.data)
204
+ }
205
+
187
206
  /**
188
207
  * @param {string} eventKey
189
208
  * @returns {Object} JSON response from the server
@@ -193,6 +212,15 @@ class EventReports {
193
212
  .then((res) => res.data)
194
213
  }
195
214
 
215
+ /**
216
+ * @param {string} eventKey
217
+ * @returns {Object} JSON response from the server
218
+ */
219
+ deepSummaryByAvailabilityReason (eventKey) {
220
+ return this.client.get(EventReports.deepSummaryReportUrl('byAvailabilityReason', eventKey))
221
+ .then((res) => res.data)
222
+ }
223
+
196
224
  /**
197
225
  * @param {string} eventKey
198
226
  * @param {?string} channel
@@ -0,0 +1,16 @@
1
+ const Event = require('../Events/Event.js')
2
+
3
+ class Season {
4
+ /**
5
+ * @param {object} season
6
+ */
7
+ constructor (season) {
8
+ this.id = season.id
9
+ this.key = season.key
10
+ this.seasonEvent = new Event(season.seasonEvent)
11
+ this.partialSeasonKeys = season.partialSeasonKeys
12
+ this.events = season.events.map(e => new Event(e))
13
+ }
14
+ }
15
+
16
+ module.exports = Season
@@ -0,0 +1,28 @@
1
+ class SeasonParams {
2
+ key (key) {
3
+ this._key = key
4
+ return this
5
+ }
6
+
7
+ numberOfEvents (numberOfEvents) {
8
+ this._numberOfEvents = numberOfEvents
9
+ return this
10
+ }
11
+
12
+ eventKeys (eventKeys) {
13
+ this._eventKeys = eventKeys
14
+ return this
15
+ }
16
+
17
+ tableBookingConfig (tableBookingConfig) {
18
+ this._tableBookingConfig = tableBookingConfig
19
+ return this
20
+ }
21
+
22
+ socialDistancingRulesetKey (socialDistancingRulesetKey) {
23
+ this._socialDistancingRulesetKey = socialDistancingRulesetKey
24
+ return this
25
+ }
26
+ }
27
+
28
+ module.exports = SeasonParams
@@ -0,0 +1,194 @@
1
+ const Page = require('../Page.js')
2
+ const Lister = require('../Lister.js')
3
+ const Season = require('./Season')
4
+
5
+ class Seasons {
6
+ /**
7
+ * @param {SeatsioClient} client
8
+ */
9
+ constructor (client) {
10
+ this.client = client
11
+ }
12
+
13
+ /**
14
+ * @param {string} chartKey
15
+ * @param {?seasonParams} SeasonParams
16
+ * @returns {Promise<Season>}
17
+ */
18
+ create (chartKey, seasonParams = null) {
19
+ const requestParameters = {}
20
+
21
+ requestParameters.chartKey = chartKey
22
+
23
+ if (seasonParams !== null) {
24
+ if (seasonParams._key !== null) {
25
+ requestParameters.key = seasonParams._key
26
+ }
27
+
28
+ if (seasonParams._numberOfEvents !== null) {
29
+ requestParameters.numberOfEvents = seasonParams._numberOfEvents
30
+ }
31
+
32
+ if (seasonParams._eventKeys !== null) {
33
+ requestParameters.eventKeys = seasonParams._eventKeys
34
+ }
35
+
36
+ if (seasonParams._tableBookingConfig !== null) {
37
+ requestParameters.tableBookingConfig = seasonParams._tableBookingConfig
38
+ }
39
+
40
+ if (seasonParams._socialDistancingRulesetKey !== null) {
41
+ requestParameters.socialDistancingRulesetKey = seasonParams._socialDistancingRulesetKey
42
+ }
43
+ }
44
+
45
+ return this.client.post('/seasons', requestParameters)
46
+ .then((res) => new Season(res.data))
47
+ }
48
+
49
+ /**
50
+ * @param {string} topLevelSeasonKey
51
+ * @param {?string} partialSeasonKey
52
+ * @param {?string[]} eventKeys
53
+ * @returns {Promise<Season>}
54
+ */
55
+ createPartialSeason (topLevelSeasonKey, partialSeasonKey = null, eventKeys = null) {
56
+ const requestParameters = {}
57
+
58
+ if (partialSeasonKey !== null) {
59
+ requestParameters.key = partialSeasonKey
60
+ }
61
+
62
+ if (eventKeys !== null) {
63
+ requestParameters.eventKeys = eventKeys
64
+ }
65
+ return this.client.post(`/seasons/${encodeURIComponent(topLevelSeasonKey)}/partial-seasons`, requestParameters)
66
+ .then((res) => new Season(res.data))
67
+ }
68
+
69
+ /**
70
+ * @param {string} key
71
+ * @returns {Promise<Season>}
72
+ */
73
+ retrieve (key) {
74
+ return this.client.get(`/seasons/${encodeURIComponent(key)}`)
75
+ .then((res) => new Season(res.data))
76
+ }
77
+
78
+ /**
79
+ * @param {string} topLevelSeasonKey
80
+ * @param {?string} partialSeasonKey
81
+ * @returns {Promise<Season>}
82
+ */
83
+ retrievePartialSeason (topLevelSeasonKey, partialSeasonKey) {
84
+ return this.client.get(`/seasons/${encodeURIComponent(topLevelSeasonKey)}/partial-seasons/${encodeURIComponent(partialSeasonKey)}`)
85
+ .then((res) => new Season(res.data))
86
+ }
87
+
88
+ /**
89
+ * @param {string} key
90
+ * @param {?number} numberOfEvents
91
+ * @param {?string[]} eventKeys
92
+ * @returns {Promise<Season>}
93
+ */
94
+ createEvents (key, numberOfEvents = null, eventKeys = null) {
95
+ const requestParameters = { }
96
+
97
+ if (numberOfEvents !== null) {
98
+ requestParameters.numberOfEvents = numberOfEvents
99
+ }
100
+
101
+ if (eventKeys !== null) {
102
+ requestParameters.eventKeys = eventKeys
103
+ }
104
+
105
+ return this.client.post(`/seasons/${encodeURIComponent(key)}/actions/create-events`, requestParameters)
106
+ .then((res) => new Season(res.data))
107
+ }
108
+
109
+ /**
110
+ * @param {string} topLevelSeasonKey
111
+ * @param {string} partialSeasonKey
112
+ * @param {string[]} eventKeys
113
+ * @returns {Promise<Season>}
114
+ */
115
+ addEventsToPartialSeason (topLevelSeasonKey, partialSeasonKey, eventKeys) {
116
+ const requestParameters = { eventKeys }
117
+ return this.client.post(`/seasons/${encodeURIComponent(topLevelSeasonKey)}/partial-seasons/${encodeURIComponent(partialSeasonKey)}/actions/add-events`, requestParameters)
118
+ .then((res) => new Season(res.data))
119
+ }
120
+
121
+ /**
122
+ * @param {string} key
123
+ * @returns {Promise}
124
+ */
125
+ delete (key) {
126
+ return this.client.delete(`/seasons/${encodeURIComponent(key)}`)
127
+ }
128
+
129
+ /**
130
+ * @param {string} topLevelSeasonKey
131
+ * @param {string} partialSeasonKey
132
+ * @returns {Promise<void>}
133
+ */
134
+ deletePartialSeason (topLevelSeasonKey, partialSeasonKey) {
135
+ return this.client.delete(`/seasons/${encodeURIComponent(topLevelSeasonKey)}/partial-seasons/${encodeURIComponent(partialSeasonKey)}`)
136
+ }
137
+
138
+ /**
139
+ * @param {string} topLevelSeasonKey
140
+ * @param {string} partialSeasonKey
141
+ * @param {string} eventKey
142
+ * @returns {Promise<Season>}
143
+ */
144
+ async removeEventFromPartialSeason (topLevelSeasonKey, partialSeasonKey, eventKey) {
145
+ return this.client.delete(`/seasons/${encodeURIComponent(topLevelSeasonKey)}/partial-seasons/${encodeURIComponent(partialSeasonKey)}/events/${encodeURIComponent(eventKey)}`)
146
+ .then((res) => new Season(res.data))
147
+ }
148
+
149
+ /**
150
+ * @param {?object} requestParameters
151
+ * @returns {AsyncIterator<Season>}
152
+ */
153
+ listAll (requestParameters = {}) {
154
+ return this.iterator().all(requestParameters)
155
+ }
156
+
157
+ /**
158
+ * @param {?number} pageSize
159
+ * @returns {Page<Season>}
160
+ */
161
+ listFirstPage (pageSize = null) {
162
+ return this.iterator().firstPage(null, pageSize)
163
+ }
164
+
165
+ /**
166
+ * @param {?string} afterId
167
+ * @param {?number} pageSize
168
+ * @returns {Page<Season>}
169
+ */
170
+ listPageAfter (afterId, pageSize = null) {
171
+ return this.iterator().pageAfter(afterId, null, pageSize)
172
+ }
173
+
174
+ /**
175
+ * @param {?string} beforeId
176
+ * @param {?number} pageSize
177
+ * @returns {Page<Season>}
178
+ */
179
+ listPageBefore (beforeId, pageSize = null) {
180
+ return this.iterator().pageBefore(beforeId, null, pageSize)
181
+ }
182
+
183
+ /**
184
+ * @returns {Lister}
185
+ */
186
+ iterator () {
187
+ return new Lister('/seasons', this.client, 'seasons', (data) => {
188
+ const seasons = data.items.map(seasonData => new Season(seasonData))
189
+ return new Page(seasons, data.next_page_starts_after, data.previous_page_ends_before)
190
+ })
191
+ }
192
+ }
193
+
194
+ module.exports = Seasons
@@ -11,6 +11,7 @@ const EventReports = require('./Reports/EventReports.js')
11
11
  const UsageReports = require('./Reports/UsageReports.js')
12
12
  const errorResponseHandler = require('./errorInterceptor.js')
13
13
  const Axios = require('axios')
14
+ const Seasons = require('./Seasons/Seasons')
14
15
 
15
16
  class SeatsioClient {
16
17
  constructor (region, secretKey, workspaceKey = null, extraHeaders = {}) {
@@ -32,6 +33,7 @@ class SeatsioClient {
32
33
  this.chartReports = new ChartReports(this.client)
33
34
  this.eventReports = new EventReports(this.client)
34
35
  this.usageReports = new UsageReports(this.client)
36
+ this.seasons = new Seasons(this.client)
35
37
  }
36
38
 
37
39
  _axiosConfig (baseUrl, secretKey, workspaceKey, extraHeaders) {
@@ -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
+ })