rotacloud 1.0.39 → 1.0.41

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 (103) hide show
  1. package/dist/cjs/interfaces/query-params/leave-requests-query-params.interface.d.ts +1 -2
  2. package/dist/cjs/interfaces/shift.interface.d.ts +1 -1
  3. package/dist/cjs/models/SDKError.model.d.ts +11 -0
  4. package/dist/cjs/models/SDKError.model.js +15 -0
  5. package/dist/cjs/models/index.d.ts +29 -0
  6. package/dist/cjs/models/index.js +41 -0
  7. package/dist/cjs/models/location.model.d.ts +2 -7
  8. package/dist/cjs/models/location.model.js +1 -4
  9. package/dist/cjs/models/shift.model.d.ts +1 -1
  10. package/dist/cjs/models/terminal.model.d.ts +2 -6
  11. package/dist/cjs/models/terminal.model.js +1 -4
  12. package/dist/cjs/rotacloud.d.ts +1 -0
  13. package/dist/cjs/rotacloud.js +1 -0
  14. package/dist/cjs/services/accounts.service.js +3 -2
  15. package/dist/cjs/services/attendance.service.js +10 -5
  16. package/dist/cjs/services/auth.service.js +3 -2
  17. package/dist/cjs/services/availability.service.js +1 -2
  18. package/dist/cjs/services/daily-budgets.service.js +1 -2
  19. package/dist/cjs/services/daily-revenue.service.js +1 -2
  20. package/dist/cjs/services/day-notes.service.js +10 -5
  21. package/dist/cjs/services/days-off.service.js +2 -3
  22. package/dist/cjs/services/groups.service.js +10 -5
  23. package/dist/cjs/services/leave-embargoes.service.js +10 -5
  24. package/dist/cjs/services/leave-request.service.d.ts +4 -4
  25. package/dist/cjs/services/leave-request.service.js +10 -5
  26. package/dist/cjs/services/leave.service.js +10 -5
  27. package/dist/cjs/services/locations.service.js +10 -5
  28. package/dist/cjs/services/roles.service.js +10 -5
  29. package/dist/cjs/services/service.d.ts +2 -0
  30. package/dist/cjs/services/service.js +23 -1
  31. package/dist/cjs/services/settings.service.js +3 -2
  32. package/dist/cjs/services/shifts.service.d.ts +3 -3
  33. package/dist/cjs/services/shifts.service.js +21 -9
  34. package/dist/cjs/services/users.service.js +10 -5
  35. package/dist/cjs/version.js +1 -1
  36. package/dist/mjs/interfaces/query-params/leave-requests-query-params.interface.d.ts +1 -2
  37. package/dist/mjs/interfaces/shift.interface.d.ts +1 -1
  38. package/dist/mjs/models/SDKError.model.d.ts +11 -0
  39. package/dist/mjs/models/SDKError.model.js +10 -0
  40. package/dist/mjs/models/index.d.ts +29 -0
  41. package/dist/mjs/models/index.js +29 -0
  42. package/dist/mjs/models/location.model.d.ts +2 -7
  43. package/dist/mjs/models/location.model.js +0 -2
  44. package/dist/mjs/models/shift.model.d.ts +1 -1
  45. package/dist/mjs/models/terminal.model.d.ts +2 -6
  46. package/dist/mjs/models/terminal.model.js +0 -2
  47. package/dist/mjs/rotacloud.d.ts +1 -0
  48. package/dist/mjs/rotacloud.js +1 -0
  49. package/dist/mjs/services/accounts.service.js +3 -2
  50. package/dist/mjs/services/attendance.service.js +10 -5
  51. package/dist/mjs/services/auth.service.js +3 -2
  52. package/dist/mjs/services/availability.service.js +1 -2
  53. package/dist/mjs/services/daily-budgets.service.js +1 -2
  54. package/dist/mjs/services/daily-revenue.service.js +1 -2
  55. package/dist/mjs/services/day-notes.service.js +10 -5
  56. package/dist/mjs/services/days-off.service.js +2 -3
  57. package/dist/mjs/services/groups.service.js +10 -5
  58. package/dist/mjs/services/leave-embargoes.service.js +10 -5
  59. package/dist/mjs/services/leave-request.service.d.ts +4 -4
  60. package/dist/mjs/services/leave-request.service.js +10 -5
  61. package/dist/mjs/services/leave.service.js +10 -5
  62. package/dist/mjs/services/locations.service.js +10 -5
  63. package/dist/mjs/services/roles.service.js +10 -5
  64. package/dist/mjs/services/service.d.ts +2 -0
  65. package/dist/mjs/services/service.js +22 -1
  66. package/dist/mjs/services/settings.service.js +3 -2
  67. package/dist/mjs/services/shifts.service.d.ts +3 -3
  68. package/dist/mjs/services/shifts.service.js +21 -9
  69. package/dist/mjs/services/users.service.js +10 -5
  70. package/dist/mjs/version.js +1 -1
  71. package/package.json +2 -3
  72. package/src/interfaces/query-params/leave-requests-query-params.interface.ts +1 -2
  73. package/src/interfaces/shift.interface.ts +1 -1
  74. package/src/models/SDKError.model.ts +20 -0
  75. package/src/models/index.ts +29 -0
  76. package/src/models/location.model.ts +2 -8
  77. package/src/models/shift.model.ts +1 -1
  78. package/src/models/terminal.model.ts +2 -6
  79. package/src/rotacloud.ts +1 -0
  80. package/src/services/accounts.service.ts +3 -5
  81. package/src/services/attendance.service.ts +10 -17
  82. package/src/services/auth.service.ts +3 -5
  83. package/src/services/availability.service.ts +1 -5
  84. package/src/services/daily-budgets.service.ts +1 -5
  85. package/src/services/daily-revenue.service.ts +1 -5
  86. package/src/services/day-notes.service.ts +10 -18
  87. package/src/services/days-off.service.ts +2 -10
  88. package/src/services/groups.service.ts +10 -18
  89. package/src/services/leave-embargoes.service.ts +10 -17
  90. package/src/services/leave-request.service.ts +15 -22
  91. package/src/services/leave.service.ts +11 -17
  92. package/src/services/locations.service.ts +11 -17
  93. package/src/services/roles.service.ts +11 -17
  94. package/src/services/service.ts +29 -2
  95. package/src/services/settings.service.ts +4 -5
  96. package/src/services/shifts.service.ts +28 -34
  97. package/src/services/users.service.ts +11 -17
  98. package/src/version.ts +1 -1
  99. package/dist/cjs/models/error-response.model.d.ts +0 -8
  100. package/dist/cjs/models/error-response.model.js +0 -13
  101. package/dist/mjs/models/error-response.model.d.ts +0 -8
  102. package/dist/mjs/models/error-response.model.js +0 -8
  103. package/src/models/error-response.model.ts +0 -14
@@ -1,5 +1,4 @@
1
1
  import { Service } from './index.js';
2
- import { ErrorResponse } from '../models/error-response.model.js';
3
2
  import { Group } from '../models/group.model.js';
4
3
  export class GroupsService extends Service {
5
4
  constructor() {
@@ -7,10 +6,14 @@ export class GroupsService extends Service {
7
6
  this.apiPath = '/groups';
8
7
  }
9
8
  create(data, options) {
10
- return super.fetch({ url: this.apiPath, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: this.apiPath, data, method: 'POST' })
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)));
11
12
  }
12
13
  get(id, options) {
13
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
14
+ return super
15
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)));
14
17
  }
15
18
  async *list(query, options) {
16
19
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -34,9 +37,11 @@ export class GroupsService extends Service {
34
37
  data,
35
38
  method: 'POST',
36
39
  })
37
- .then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
40
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)));
38
41
  }
39
42
  delete(id, options) {
40
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
43
+ return super
44
+ .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
45
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
41
46
  }
42
47
  }
@@ -1,16 +1,19 @@
1
1
  import { Service } from './index.js';
2
2
  import { LeaveEmbargo } from '../models/leave-embargo.model.js';
3
- import { ErrorResponse } from '../models/error-response.model.js';
4
3
  export class LeaveEmbargoesService extends Service {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.apiPath = '/leave_embargoes';
8
7
  }
9
8
  create(data, options) {
10
- return super.fetch({ url: this.apiPath, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: this.apiPath, data, method: 'POST' })
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)));
11
12
  }
12
13
  get(id, options) {
13
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
14
+ return super
15
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)));
14
17
  }
15
18
  async *list(query, options) {
16
19
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -34,9 +37,11 @@ export class LeaveEmbargoesService extends Service {
34
37
  data,
35
38
  method: 'POST',
36
39
  })
37
- .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
40
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)));
38
41
  }
39
42
  delete(id, options) {
40
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
43
+ return super
44
+ .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
45
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
41
46
  }
42
47
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { ApiLeaveRequest } from '../interfaces/index.js';
3
3
  import { Service, Options, RequirementsOf } from './index.js';
4
- import { LeaveQueryParams } from '../interfaces/query-params/leave-query-params.interface.js';
4
+ import { LeaveRequestsQueryParams } from '../interfaces/query-params/leave-requests-query-params.interface.js';
5
5
  import { LeaveRequest } from '../models/leave-request.model.js';
6
6
  declare type RequiredProps = 'start_date' | 'end_date' | 'type' | 'user';
7
7
  export declare class LeaveRequestService extends Service {
@@ -16,9 +16,9 @@ export declare class LeaveRequestService extends Service {
16
16
  rawResponse: true;
17
17
  }): Promise<AxiosResponse<ApiLeaveRequest, any>>;
18
18
  get(id: number, options: Options): Promise<LeaveRequest>;
19
- list(query?: LeaveQueryParams, options?: Options): AsyncGenerator<LeaveRequest, void, unknown>;
20
- listAll(query?: LeaveQueryParams, options?: Options): Promise<LeaveRequest[]>;
21
- listByPage(query?: LeaveQueryParams, options?: Options): AsyncGenerator<AxiosResponse<ApiLeaveRequest[], any>, any, unknown>;
19
+ list(query?: LeaveRequestsQueryParams, options?: Options): AsyncGenerator<LeaveRequest, void, unknown>;
20
+ listAll(query?: LeaveRequestsQueryParams, options?: Options): Promise<LeaveRequest[]>;
21
+ listByPage(query?: LeaveRequestsQueryParams, options?: Options): AsyncGenerator<AxiosResponse<ApiLeaveRequest[], any>, any, unknown>;
22
22
  update(id: number, data: Partial<ApiLeaveRequest>): Promise<LeaveRequest>;
23
23
  update(id: number, data: Partial<ApiLeaveRequest>, options: {
24
24
  rawResponse: true;
@@ -1,5 +1,4 @@
1
1
  import { Service } from './index.js';
2
- import { ErrorResponse } from '../models/error-response.model.js';
3
2
  import { LeaveRequest } from '../models/leave-request.model.js';
4
3
  export class LeaveRequestService extends Service {
5
4
  constructor() {
@@ -7,10 +6,14 @@ export class LeaveRequestService extends Service {
7
6
  this.apiPath = '/leave_requests';
8
7
  }
9
8
  create(data, options) {
10
- return super.fetch({ url: this.apiPath, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: this.apiPath, data, method: 'POST' })
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)));
11
12
  }
12
13
  get(id, options) {
13
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
14
+ return super
15
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)));
14
17
  }
15
18
  async *list(query, options) {
16
19
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -34,9 +37,11 @@ export class LeaveRequestService extends Service {
34
37
  data,
35
38
  method: 'POST',
36
39
  })
37
- .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
40
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)));
38
41
  }
39
42
  delete(id, options) {
40
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
43
+ return super
44
+ .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
45
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
41
46
  }
42
47
  }
@@ -1,6 +1,5 @@
1
1
  import { Service } from './index.js';
2
2
  import { Leave } from '../models/leave.model.js';
3
- import { ErrorResponse } from '../models/error-response.model.js';
4
3
  import { LeaveType } from '../models/leave-type.model.js';
5
4
  export class LeaveService extends Service {
6
5
  constructor() {
@@ -8,10 +7,14 @@ export class LeaveService extends Service {
8
7
  this.apiPath = '/leave';
9
8
  }
10
9
  create(data, options) {
11
- return super.fetch({ url: this.apiPath, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : [...res.data.map((leave) => new Leave(leave))]), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
10
+ return super
11
+ .fetch({ url: this.apiPath, data, method: 'POST' })
12
+ .then((res) => Promise.resolve(options?.rawResponse ? res : [...res.data.map((leave) => new Leave(leave))]));
12
13
  }
13
14
  get(id, options) {
14
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new Leave(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
15
+ return super
16
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
17
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Leave(res.data)));
15
18
  }
16
19
  async *list(query, options) {
17
20
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -40,9 +43,11 @@ export class LeaveService extends Service {
40
43
  data,
41
44
  method: 'POST',
42
45
  })
43
- .then((res) => Promise.resolve(options?.rawResponse ? res : new Leave(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
46
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Leave(res.data)));
44
47
  }
45
48
  delete(id, options) {
46
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
49
+ return super
50
+ .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
51
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
47
52
  }
48
53
  }
@@ -1,16 +1,19 @@
1
1
  import { Service } from './index.js';
2
2
  import { Location } from '../models/location.model.js';
3
- import { ErrorResponse } from '../models/error-response.model.js';
4
3
  export class LocationsService extends Service {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.apiPath = '/locations';
8
7
  }
9
8
  create(data, options) {
10
- return super.fetch({ url: `${this.apiPath}`, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: `${this.apiPath}`, data, method: 'POST' })
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)));
11
12
  }
12
13
  get(id, options) {
13
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
14
+ return super
15
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)));
14
17
  }
15
18
  async *list(query, options) {
16
19
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -34,9 +37,11 @@ export class LocationsService extends Service {
34
37
  data,
35
38
  method: 'POST',
36
39
  })
37
- .then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
40
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)));
38
41
  }
39
42
  delete(id, options) {
40
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
43
+ return super
44
+ .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
45
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
41
46
  }
42
47
  }
@@ -1,16 +1,19 @@
1
1
  import { Service } from './index.js';
2
2
  import { Role } from '../models/role.model.js';
3
- import { ErrorResponse } from '../models/error-response.model.js';
4
3
  export class RolesService extends Service {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.apiPath = '/roles';
8
7
  }
9
8
  create(data, options) {
10
- return super.fetch({ url: this.apiPath, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: this.apiPath, data, method: 'POST' })
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)));
11
12
  }
12
13
  get(id, options) {
13
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
14
+ return super
15
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)));
14
17
  }
15
18
  async *list(query, options) {
16
19
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -34,9 +37,11 @@ export class RolesService extends Service {
34
37
  data,
35
38
  method: 'POST',
36
39
  })
37
- .then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
40
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)));
38
41
  }
39
42
  delete(id, options) {
40
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
43
+ return super
44
+ .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
45
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
41
46
  }
42
47
  }
@@ -25,6 +25,8 @@ export interface Options {
25
25
  }
26
26
  export declare abstract class Service<ApiResponse = any> {
27
27
  protected client: AxiosInstance;
28
+ private initialiseAxios;
29
+ private parseClientError;
28
30
  isLeaveRequest(endpoint?: string): boolean;
29
31
  private buildQueryStr;
30
32
  private parsePageLinkHeader;
@@ -2,6 +2,7 @@ import axios from 'axios';
2
2
  import axiosRetry from 'axios-retry';
3
3
  import { RotaCloud } from '../rotacloud.js';
4
4
  import { Version } from '../version.js';
5
+ import { SDKError } from '../models/SDKError.model.js';
5
6
  export var RetryStrategy;
6
7
  (function (RetryStrategy) {
7
8
  RetryStrategy["Exponential"] = "expo";
@@ -22,7 +23,27 @@ const DEFAULT_RETRY_STRATEGY_OPTIONS = {
22
23
  };
23
24
  export class Service {
24
25
  constructor() {
25
- this.client = axios.create();
26
+ this.client = this.initialiseAxios();
27
+ }
28
+ initialiseAxios() {
29
+ const client = axios.create();
30
+ client.interceptors.response.use((response) => response, (error) => {
31
+ const parsedError = this.parseClientError(error);
32
+ return Promise.reject(parsedError);
33
+ });
34
+ return client;
35
+ }
36
+ parseClientError(error) {
37
+ if (!axios.isAxiosError(error))
38
+ return error;
39
+ const axiosErrorLocation = error.response || error.request;
40
+ const apiErrorMessage = axiosErrorLocation.data?.error;
41
+ const sdkErrorParams = {
42
+ code: axiosErrorLocation.status,
43
+ message: apiErrorMessage || error.message,
44
+ data: axiosErrorLocation.data,
45
+ };
46
+ return new SDKError(sdkErrorParams);
26
47
  }
27
48
  isLeaveRequest(endpoint) {
28
49
  return endpoint === '/leave_requests';
@@ -1,13 +1,14 @@
1
1
  import { Settings } from '../models/settings.model.js';
2
2
  import { Service } from './index.js';
3
- import { ErrorResponse } from '../models/error-response.model.js';
4
3
  class SettingsService extends Service {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.apiPath = '/settings';
8
7
  }
9
8
  get(query, options) {
10
- return super.fetch({ url: `${this.apiPath}`, params: query }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new Settings(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: `${this.apiPath}`, params: query }, options)
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Settings(res.data)));
11
12
  }
12
13
  }
13
14
  export { SettingsService };
@@ -24,11 +24,11 @@ export declare class ShiftsService extends Service {
24
24
  rawResponse: true;
25
25
  } & Options): Promise<AxiosResponse<ApiShift, any>>;
26
26
  update(id: number, data: Partial<ApiShift>, options: Options): Promise<Shift>;
27
- delete(id: number): Promise<number>;
28
- delete(id: number, options: {
27
+ delete(ids: number | number[]): Promise<number>;
28
+ delete(ids: number | number[], options: {
29
29
  rawResponse: true;
30
30
  } & Options): Promise<AxiosResponse<any, any>>;
31
- delete(id: number, options: Options): Promise<number>;
31
+ delete(ids: number | number[], options: Options): Promise<number>;
32
32
  acknowledge(data: number[]): Promise<number>;
33
33
  acknowledge(data: number[], options: {
34
34
  rawResponse: true;
@@ -1,16 +1,19 @@
1
1
  import { Service } from './index.js';
2
2
  import { Shift } from '../models/shift.model.js';
3
- import { ErrorResponse } from '../models/error-response.model.js';
4
3
  export class ShiftsService extends Service {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.apiPath = '/shifts';
8
7
  }
9
8
  create(data, options) {
10
- return super.fetch({ url: this.apiPath, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : new Shift(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: this.apiPath, data, method: 'POST' })
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Shift(res.data)));
11
12
  }
12
13
  get(id, options) {
13
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new Shift(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
14
+ return super
15
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Shift(res.data)));
14
17
  }
15
18
  async *list(query, options) {
16
19
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -34,18 +37,27 @@ export class ShiftsService extends Service {
34
37
  data,
35
38
  method: 'POST',
36
39
  })
37
- .then((res) => Promise.resolve(options?.rawResponse ? res : new Shift(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
40
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Shift(res.data)));
38
41
  }
39
- delete(id, options) {
40
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
42
+ delete(ids, options) {
43
+ const params = typeof ids !== 'number'
44
+ ? { url: this.apiPath, data: ids, method: 'DELETE' }
45
+ : { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
46
+ return super.fetch(params).then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
41
47
  }
42
48
  acknowledge(data, options) {
43
- return super.fetch({ url: '/shifts_acknowledged', data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
49
+ return super
50
+ .fetch({ url: '/shifts_acknowledged', data, method: 'POST' })
51
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
44
52
  }
45
53
  publish(data, options) {
46
- return super.fetch({ url: '/shifts_published', data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
54
+ return super
55
+ .fetch({ url: '/shifts_published', data, method: 'POST' })
56
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
47
57
  }
48
58
  unpublish(data, options) {
49
- return super.fetch({ url: '/shifts_published', data, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
59
+ return super
60
+ .fetch({ url: '/shifts_published', data, method: 'DELETE' })
61
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
50
62
  }
51
63
  }
@@ -1,16 +1,19 @@
1
1
  import { Service } from './index.js';
2
2
  import { User } from '../models/user.model.js';
3
- import { ErrorResponse } from '../models/error-response.model.js';
4
3
  class UsersService extends Service {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.apiPath = '/users';
8
7
  }
9
8
  create(data, options) {
10
- return super.fetch({ url: this.apiPath, data, method: 'POST' }).then((res) => Promise.resolve(options?.rawResponse ? res : new User(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
9
+ return super
10
+ .fetch({ url: this.apiPath, data, method: 'POST' })
11
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new User(res.data)));
11
12
  }
12
13
  get(id, options) {
13
- return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new User(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
14
+ return super
15
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new User(res.data)));
14
17
  }
15
18
  async *list(query, options) {
16
19
  for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
@@ -34,10 +37,12 @@ class UsersService extends Service {
34
37
  data,
35
38
  method: 'POST',
36
39
  })
37
- .then((res) => Promise.resolve(options?.rawResponse ? res : new User(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
40
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new User(res.data)));
38
41
  }
39
42
  delete(id, options) {
40
- return super.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' }).then((res) => Promise.resolve(options?.rawResponse ? res : res.status), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
43
+ return super
44
+ .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
45
+ .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
41
46
  }
42
47
  }
43
48
  export { UsersService };
@@ -1 +1 @@
1
- export const Version = { version: '1.0.39' };
1
+ export const Version = { version: '1.0.41' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rotacloud",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "The RotaCloud SDK for the RotaCloud API",
5
5
  "engines": {
6
6
  "node": ">=14.17.0"
@@ -47,7 +47,6 @@
47
47
  "dependencies": {
48
48
  "@types/node": "^16.11.6",
49
49
  "axios": "^0.23.0",
50
- "axios-retry": "^3.3.1",
51
- "cross-var": "^1.1.0"
50
+ "axios-retry": "^3.3.1"
52
51
  }
53
52
  }
@@ -1,5 +1,4 @@
1
1
  export interface LeaveRequestsQueryParams {
2
- users?: number[];
3
- status?: string;
2
+ status?: 'requested' | 'approved' | 'denied' | 'expired';
4
3
  include_deleted?: boolean;
5
4
  }
@@ -8,7 +8,7 @@ export interface ApiShift {
8
8
  start_time: number;
9
9
  end_time: number;
10
10
  minutes_break: number;
11
- user: number;
11
+ user: number | null;
12
12
  location: number;
13
13
  role: number | null;
14
14
  notes: string | null;
@@ -0,0 +1,20 @@
1
+ export interface SDKErrorConfig {
2
+ message?: string;
3
+ code?: number;
4
+ data?: unknown;
5
+ }
6
+ export class SDKError extends Error {
7
+ readonly code?: number;
8
+ readonly data?: unknown;
9
+ override name = this.constructor.name;
10
+
11
+ constructor(errorConfig: SDKErrorConfig) {
12
+ super(errorConfig.message);
13
+
14
+ Error.captureStackTrace?.(this, SDKError);
15
+ // optional chaining needed as is v8 specific https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#static_methods
16
+
17
+ this.data = errorConfig.data;
18
+ this.code = errorConfig.code;
19
+ }
20
+ }
@@ -0,0 +1,29 @@
1
+ export * from './account.model.js';
2
+ export * from './attendance.model.js';
3
+ export * from './auth.model.js';
4
+ export * from './availability-pattern.model.js';
5
+ export * from './availability.model.js';
6
+ export * from './daily-budgets.model.js';
7
+ export * from './daily-revenue.model.js';
8
+ export * from './day-note.model.js';
9
+ export * from './days-off-pattern.model.js';
10
+ export * from './days-off.model.js';
11
+ export * from './document.model.js';
12
+ export * from './SDKError.model.js';
13
+ export * from './group.model.js';
14
+ export * from './holiday-allowance-custom.model.js';
15
+ export * from './holiday-allowance.model.js';
16
+ export * from './leave-embargo.model.js';
17
+ export * from './leave-request.model.js';
18
+ export * from './leave-type.model.js';
19
+ export * from './leave.model.js';
20
+ export * from './location.model.js';
21
+ export * from './logbook-category.model.js';
22
+ export * from './logbook-event.model.js';
23
+ export * from './memo.model.js';
24
+ export * from './pay-period.model.js';
25
+ export * from './role.model.js';
26
+ export * from './settings.model.js';
27
+ export * from './shift.model.js';
28
+ export * from './terminal.model.js';
29
+ export * from './user.model.js';
@@ -1,17 +1,11 @@
1
- import { ApiLocation } from '../interfaces/index.js';
2
-
3
- export class LatLngObject {
4
- public lat: number;
5
- public lng: number;
6
- public radius: number;
7
- }
1
+ import { ApiLocation, ApiLocationCoordinate } from '../interfaces/index.js';
8
2
 
9
3
  export class Location {
10
4
  public id: number;
11
5
  public name: string;
12
6
  public deleted: boolean;
13
7
  public address: string;
14
- public location: LatLngObject;
8
+ public location: ApiLocationCoordinate;
15
9
  public timezone: number;
16
10
  public users: number[];
17
11
  public managers: number[];
@@ -10,7 +10,7 @@ export class Shift {
10
10
  public start_time: number;
11
11
  public end_time: number;
12
12
  public minutes_break: number;
13
- public user: number;
13
+ public user: number | null;
14
14
  public location: number;
15
15
  public role: number | null;
16
16
  public notes: string | null;
@@ -1,8 +1,4 @@
1
- export class LatLngObject {
2
- public lat: number;
3
- public lng: number;
4
- public radius: number;
5
- }
1
+ import { ApiLocationCoordinate } from '../interfaces/index.js';
6
2
 
7
3
  export class Terminal {
8
4
  public id: number;
@@ -13,7 +9,7 @@ export class Terminal {
13
9
  public device: string;
14
10
  public version: string;
15
11
  public ip: string;
16
- public location: LatLngObject;
12
+ public location: ApiLocationCoordinate;
17
13
  public timezone: number;
18
14
  public require_photo: boolean;
19
15
  public require_photo_breaks: boolean;
package/src/rotacloud.ts CHANGED
@@ -66,3 +66,4 @@ export class RotaCloud {
66
66
  export { RetryStrategy, RetryOptions } from './services/service.js';
67
67
  export * from './interfaces/index.js';
68
68
  export * from './interfaces/query-params/index.js';
69
+ export * from './models/index.js';
@@ -3,7 +3,6 @@ import { Account } from '../models/account.model.js';
3
3
  import { Service, Options } from './index.js';
4
4
 
5
5
  import { ApiAccount } from '../interfaces/index.js';
6
- import { ErrorResponse } from '../models/error-response.model.js';
7
6
 
8
7
  class AccountsService extends Service {
9
8
  private apiPath = '/accounts';
@@ -12,10 +11,9 @@ class AccountsService extends Service {
12
11
  get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<ApiAccount, any>>;
13
12
  get(id: number, options: Options): Promise<Account>;
14
13
  get(id: number, options?: Options) {
15
- return super.fetch<ApiAccount>({ url: `${this.apiPath}/${id}` }, options).then(
16
- (res) => Promise.resolve(options?.rawResponse ? res : new Account(res.data)),
17
- (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err))
18
- );
14
+ return super
15
+ .fetch<ApiAccount>({ url: `${this.apiPath}/${id}` }, options)
16
+ .then((res) => Promise.resolve(options?.rawResponse ? res : new Account(res.data)));
19
17
  }
20
18
 
21
19
  async *list(options?: Options) {