rotacloud 1.0.30 → 1.0.32

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 (124) hide show
  1. package/README.md +27 -1
  2. package/dist/cjs/interfaces/{day-notes.interface.d.ts → day-note.interface.d.ts} +1 -1
  3. package/dist/cjs/interfaces/{day-notes.interface.js → day-note.interface.js} +0 -0
  4. package/dist/cjs/interfaces/index.d.ts +3 -2
  5. package/dist/cjs/interfaces/index.js +3 -2
  6. package/dist/cjs/interfaces/query-params/day-notes-query-params.interface.d.ts +2 -2
  7. package/dist/cjs/interfaces/query-params/index.d.ts +1 -0
  8. package/dist/cjs/interfaces/query-params/index.js +1 -0
  9. package/dist/cjs/interfaces/query-params/settings-query-params.interface.d.ts +3 -0
  10. package/dist/cjs/interfaces/query-params/settings-query-params.interface.js +2 -0
  11. package/dist/cjs/interfaces/query-params/shifts-query-params.interface.d.ts +2 -2
  12. package/dist/cjs/interfaces/sdk-config.interface.d.ts +2 -0
  13. package/dist/cjs/interfaces/settings.interface.d.ts +64 -0
  14. package/dist/cjs/interfaces/settings.interface.js +2 -0
  15. package/dist/cjs/models/{day-notes.model.d.ts → day-note.model.d.ts} +3 -3
  16. package/dist/cjs/models/day-note.model.js +14 -0
  17. package/dist/cjs/models/settings.model.d.ts +2 -6
  18. package/dist/cjs/models/settings.model.js +3 -0
  19. package/dist/cjs/rotacloud.d.ts +6 -2
  20. package/dist/cjs/rotacloud.js +12 -6
  21. package/dist/cjs/services/accounts.service.js +11 -16
  22. package/dist/cjs/services/attendance.service.js +11 -16
  23. package/dist/cjs/services/daily-budgets.service.js +11 -16
  24. package/dist/cjs/services/daily-revenue.service.js +11 -16
  25. package/dist/cjs/services/day-notes.service.d.ts +31 -0
  26. package/dist/cjs/services/day-notes.service.js +103 -0
  27. package/dist/cjs/services/days-off.service.js +11 -16
  28. package/dist/cjs/services/groups.service.d.ts +3 -3
  29. package/dist/cjs/services/groups.service.js +11 -16
  30. package/dist/cjs/services/index.d.ts +1 -0
  31. package/dist/cjs/services/index.js +1 -0
  32. package/dist/cjs/services/leave-embargoes.service.js +11 -16
  33. package/dist/cjs/services/leave-request.service.d.ts +3 -3
  34. package/dist/cjs/services/leave-request.service.js +13 -18
  35. package/dist/cjs/services/leave.service.js +11 -16
  36. package/dist/cjs/services/locations.service.d.ts +3 -3
  37. package/dist/cjs/services/locations.service.js +11 -16
  38. package/dist/cjs/services/roles.service.d.ts +3 -3
  39. package/dist/cjs/services/roles.service.js +11 -16
  40. package/dist/cjs/services/service.d.ts +19 -1
  41. package/dist/cjs/services/service.js +38 -3
  42. package/dist/cjs/services/settings.service.d.ts +14 -0
  43. package/dist/cjs/services/settings.service.js +16 -0
  44. package/dist/cjs/services/shifts.service.js +11 -16
  45. package/dist/cjs/services/users.service.js +11 -16
  46. package/dist/cjs/version.js +1 -1
  47. package/dist/mjs/interfaces/{day-notes.interface.d.ts → day-note.interface.d.ts} +1 -1
  48. package/dist/mjs/interfaces/{day-notes.interface.js → day-note.interface.js} +0 -0
  49. package/dist/mjs/interfaces/index.d.ts +3 -2
  50. package/dist/mjs/interfaces/index.js +3 -2
  51. package/dist/mjs/interfaces/query-params/day-notes-query-params.interface.d.ts +2 -2
  52. package/dist/mjs/interfaces/query-params/index.d.ts +1 -0
  53. package/dist/mjs/interfaces/query-params/index.js +1 -0
  54. package/dist/mjs/interfaces/query-params/settings-query-params.interface.d.ts +3 -0
  55. package/dist/mjs/interfaces/query-params/settings-query-params.interface.js +1 -0
  56. package/dist/mjs/interfaces/query-params/shifts-query-params.interface.d.ts +2 -2
  57. package/dist/mjs/interfaces/sdk-config.interface.d.ts +2 -0
  58. package/dist/mjs/interfaces/settings.interface.d.ts +64 -0
  59. package/dist/mjs/interfaces/settings.interface.js +1 -0
  60. package/dist/mjs/models/{day-notes.model.d.ts → day-note.model.d.ts} +3 -3
  61. package/dist/mjs/models/day-note.model.js +10 -0
  62. package/dist/mjs/models/settings.model.d.ts +2 -6
  63. package/dist/mjs/models/settings.model.js +3 -0
  64. package/dist/mjs/rotacloud.d.ts +6 -2
  65. package/dist/mjs/rotacloud.js +14 -6
  66. package/dist/mjs/services/accounts.service.js +4 -9
  67. package/dist/mjs/services/attendance.service.js +4 -9
  68. package/dist/mjs/services/daily-budgets.service.js +4 -9
  69. package/dist/mjs/services/daily-revenue.service.js +4 -9
  70. package/dist/mjs/services/day-notes.service.d.ts +31 -0
  71. package/dist/mjs/services/day-notes.service.js +42 -0
  72. package/dist/mjs/services/days-off.service.js +4 -9
  73. package/dist/mjs/services/groups.service.d.ts +3 -3
  74. package/dist/mjs/services/groups.service.js +4 -9
  75. package/dist/mjs/services/index.d.ts +1 -0
  76. package/dist/mjs/services/index.js +1 -0
  77. package/dist/mjs/services/leave-embargoes.service.js +4 -9
  78. package/dist/mjs/services/leave-request.service.d.ts +3 -3
  79. package/dist/mjs/services/leave-request.service.js +6 -11
  80. package/dist/mjs/services/leave.service.js +4 -9
  81. package/dist/mjs/services/locations.service.d.ts +3 -3
  82. package/dist/mjs/services/locations.service.js +4 -9
  83. package/dist/mjs/services/roles.service.d.ts +3 -3
  84. package/dist/mjs/services/roles.service.js +4 -9
  85. package/dist/mjs/services/service.d.ts +19 -1
  86. package/dist/mjs/services/service.js +37 -2
  87. package/dist/mjs/services/settings.service.d.ts +14 -0
  88. package/dist/mjs/services/settings.service.js +13 -0
  89. package/dist/mjs/services/shifts.service.js +4 -9
  90. package/dist/mjs/services/users.service.js +4 -9
  91. package/dist/mjs/version.js +1 -1
  92. package/package.json +2 -1
  93. package/src/interfaces/{day-notes.interface.ts → day-note.interface.ts} +1 -1
  94. package/src/interfaces/index.ts +3 -2
  95. package/src/interfaces/query-params/day-notes-query-params.interface.ts +2 -2
  96. package/src/interfaces/query-params/index.ts +1 -0
  97. package/src/interfaces/query-params/settings-query-params.interface.ts +3 -0
  98. package/src/interfaces/query-params/shifts-query-params.interface.ts +2 -2
  99. package/src/interfaces/sdk-config.interface.ts +3 -0
  100. package/src/interfaces/settings.interface.ts +63 -0
  101. package/src/models/day-note.model.ts +19 -0
  102. package/src/models/settings.model.ts +5 -3
  103. package/src/rotacloud.ts +16 -5
  104. package/src/services/accounts.service.ts +4 -8
  105. package/src/services/attendance.service.ts +4 -8
  106. package/src/services/daily-budgets.service.ts +4 -8
  107. package/src/services/daily-revenue.service.ts +4 -8
  108. package/src/services/day-notes.service.ts +81 -0
  109. package/src/services/days-off.service.ts +4 -8
  110. package/src/services/groups.service.ts +7 -11
  111. package/src/services/index.ts +1 -0
  112. package/src/services/leave-embargoes.service.ts +4 -8
  113. package/src/services/leave-request.service.ts +8 -12
  114. package/src/services/leave.service.ts +4 -8
  115. package/src/services/locations.service.ts +7 -11
  116. package/src/services/roles.service.ts +7 -11
  117. package/src/services/service.ts +57 -3
  118. package/src/services/settings.service.ts +23 -0
  119. package/src/services/shifts.service.ts +4 -8
  120. package/src/services/users.service.ts +4 -8
  121. package/src/version.ts +1 -1
  122. package/dist/cjs/models/day-notes.model.js +0 -9
  123. package/dist/mjs/models/day-notes.model.js +0 -5
  124. package/src/models/day-notes.model.ts +0 -14
@@ -35,27 +35,23 @@ export class LeaveRequestService extends Service {
35
35
  );
36
36
  }
37
37
 
38
- async *list(query: LeaveQueryParams, options?: Options) {
38
+ async *list(query?: LeaveQueryParams, options?: Options) {
39
39
  for await (const res of super.iterator<ApiLeaveRequest>({ url: this.apiPath, params: query }, options)) {
40
40
  yield new LeaveRequest(res);
41
41
  }
42
42
  }
43
43
 
44
- listAll(query: LeaveQueryParams, options?: Options): Promise<LeaveRequest[]>;
44
+ listAll(query?: LeaveQueryParams, options?: Options): Promise<LeaveRequest[]>;
45
45
  async listAll(query: LeaveQueryParams, options?: Options) {
46
- try {
47
- const leave = [] as LeaveRequest[];
48
- for await (const leaveRequestRecord of this.list(query, options)) {
49
- leave.push(leaveRequestRecord);
50
- }
51
- return leave;
52
- } catch (err) {
53
- return err;
46
+ const leave = [] as LeaveRequest[];
47
+ for await (const leaveRequestRecord of this.list(query, options)) {
48
+ leave.push(leaveRequestRecord);
54
49
  }
50
+ return leave;
55
51
  }
56
52
 
57
- listByPage(options?: Options) {
58
- return super.iterator<ApiLeaveRequest>({ url: `${this.apiPath}` }, options).byPage();
53
+ listByPage(query?: LeaveQueryParams, options?: Options) {
54
+ return super.iterator<ApiLeaveRequest>({ url: `${this.apiPath}`, params: query }, options).byPage();
59
55
  }
60
56
 
61
57
  update(id: number, data: Partial<ApiLeaveRequest>): Promise<LeaveRequest>;
@@ -44,15 +44,11 @@ export class LeaveService extends Service {
44
44
 
45
45
  listAll(query: LeaveQueryParams, options?: Options): Promise<Leave[]>;
46
46
  async listAll(query: LeaveQueryParams, options?: Options) {
47
- try {
48
- const leave = [] as Leave[];
49
- for await (const leaveRecord of this.list(query, options)) {
50
- leave.push(leaveRecord);
51
- }
52
- return leave;
53
- } catch (err) {
54
- return err;
47
+ const leave = [] as Leave[];
48
+ for await (const leaveRecord of this.list(query, options)) {
49
+ leave.push(leaveRecord);
55
50
  }
51
+ return leave;
56
52
  }
57
53
 
58
54
  async *listLeaveTypes(query: LeaveQueryParams, options?: Options) {
@@ -34,26 +34,22 @@ export class LocationsService extends Service {
34
34
  );
35
35
  }
36
36
 
37
- async *list(query: LocationsQueryParams, options?: Options) {
37
+ async *list(query?: LocationsQueryParams, options?: Options) {
38
38
  for await (const res of super.iterator<ApiLocation>({ url: this.apiPath, params: query }, options)) {
39
39
  yield new Location(res);
40
40
  }
41
41
  }
42
42
 
43
- listAll(query: LocationsQueryParams, options?: Options): Promise<Location[]>;
43
+ listAll(query?: LocationsQueryParams, options?: Options): Promise<Location[]>;
44
44
  async listAll(query: LocationsQueryParams, options?: Options) {
45
- try {
46
- const locations = [] as Location[];
47
- for await (const location of this.list(query, options)) {
48
- locations.push(location);
49
- }
50
- return locations;
51
- } catch (err) {
52
- return err;
45
+ const locations = [] as Location[];
46
+ for await (const location of this.list(query, options)) {
47
+ locations.push(location);
53
48
  }
49
+ return locations;
54
50
  }
55
51
 
56
- listByPage(query: LocationsQueryParams, options?: Options) {
52
+ listByPage(query?: LocationsQueryParams, options?: Options) {
57
53
  return super.iterator<ApiLocation>({ url: this.apiPath, params: query }, options).byPage();
58
54
  }
59
55
 
@@ -34,26 +34,22 @@ export class RolesService extends Service {
34
34
  );
35
35
  }
36
36
 
37
- async *list(query: RolesQueryParams, options?: Options) {
37
+ async *list(query?: RolesQueryParams, options?: Options) {
38
38
  for await (const res of super.iterator<ApiRole>({ url: this.apiPath, params: query }, options)) {
39
39
  yield new Role(res);
40
40
  }
41
41
  }
42
42
 
43
- listAll(query: RolesQueryParams, options?: Options): Promise<Role[]>;
43
+ listAll(query?: RolesQueryParams, options?: Options): Promise<Role[]>;
44
44
  async listAll(query: RolesQueryParams, options?: Options) {
45
- try {
46
- const roles = [] as Role[];
47
- for await (const role of this.list(query, options)) {
48
- roles.push(role);
49
- }
50
- return roles;
51
- } catch (err) {
52
- return err;
45
+ const roles = [] as Role[];
46
+ for await (const role of this.list(query, options)) {
47
+ roles.push(role);
53
48
  }
49
+ return roles;
54
50
  }
55
51
 
56
- listByPage(query: RolesQueryParams, options?: Options) {
52
+ listByPage(query?: RolesQueryParams, options?: Options) {
57
53
  return super.iterator<ApiRole>({ url: this.apiPath, params: query }, options).byPage();
58
54
  }
59
55
  update(id: number, data: Partial<ApiRole>): Promise<Role>;
@@ -1,9 +1,46 @@
1
- import axios, { AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
1
+ import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
2
+ import axiosRetry from 'axios-retry';
2
3
  import { RotaCloud } from '../rotacloud.js';
3
4
  import { Version } from '../version.js';
4
5
 
5
6
  export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
6
7
 
8
+ export enum RetryStrategy {
9
+ Exponential = 'expo',
10
+ Static = 'static',
11
+ }
12
+
13
+ export type RetryOptions =
14
+ | {
15
+ /** Use exponential back-off */
16
+ exponential?: false;
17
+ /** The maximum number of retries before erroring */
18
+ maxRetries: number;
19
+ /** Delay in milliseconds between retry attempts - not used in exponential back-off */
20
+ delay: number;
21
+ }
22
+ | {
23
+ /** Use exponential back-off */
24
+ exponential: true;
25
+ /** The maximum number of retries before erroring */
26
+ maxRetries: number;
27
+ };
28
+
29
+ const DEFAULT_RETRIES = 3;
30
+ const DEFAULT_RETRY_DELAY = 2000;
31
+
32
+ const DEFAULT_RETRY_STRATEGY_OPTIONS: Record<RetryStrategy, RetryOptions> = {
33
+ [RetryStrategy.Exponential]: {
34
+ exponential: true,
35
+ maxRetries: DEFAULT_RETRIES,
36
+ },
37
+ [RetryStrategy.Static]: {
38
+ exponential: false,
39
+ maxRetries: DEFAULT_RETRIES,
40
+ delay: DEFAULT_RETRY_DELAY,
41
+ },
42
+ };
43
+
7
44
  export interface Options {
8
45
  rawResponse?: boolean;
9
46
  expand?: string[];
@@ -22,7 +59,7 @@ type ParameterPrimitive = string | boolean | number | null;
22
59
  type ParameterValue = ParameterPrimitive | ParameterPrimitive[] | undefined;
23
60
 
24
61
  export abstract class Service<ApiResponse = any> {
25
- // rate limit tracking could be implemented here statically
62
+ protected client: AxiosInstance = axios.create();
26
63
 
27
64
  public isLeaveRequest(endpoint?: string): boolean {
28
65
  return endpoint === '/leave_requests';
@@ -80,7 +117,24 @@ export abstract class Service<ApiResponse = any> {
80
117
  },
81
118
  };
82
119
 
83
- const response = await axios.request<T>(reqObject);
120
+ if (RotaCloud.config.retry) {
121
+ const retryConfig =
122
+ typeof RotaCloud.config.retry === 'string'
123
+ ? DEFAULT_RETRY_STRATEGY_OPTIONS[RotaCloud.config.retry]
124
+ : RotaCloud.config.retry;
125
+
126
+ axiosRetry(this.client, {
127
+ retries: retryConfig.maxRetries,
128
+ retryDelay: (retryCount) => {
129
+ if (retryConfig.exponential) {
130
+ return axiosRetry.exponentialDelay(retryCount);
131
+ }
132
+ return retryConfig.delay;
133
+ },
134
+ });
135
+ }
136
+
137
+ const response = await this.client.request<T>(reqObject);
84
138
  return response;
85
139
  }
86
140
 
@@ -0,0 +1,23 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Settings } from '../models/settings.model.js';
3
+ import { Service, Options } from './index.js';
4
+
5
+ import { ApiSettings } from '../interfaces/index.js';
6
+ import { ErrorResponse } from '../models/error-response.model.js';
7
+ import { SettingsQueryParams } from '../rotacloud.js';
8
+
9
+ class SettingsService extends Service {
10
+ private apiPath = '/settings';
11
+
12
+ get(query: SettingsQueryParams): Promise<Settings>;
13
+ get(query: SettingsQueryParams, options: { rawResponse: true } & Options): Promise<AxiosResponse<ApiSettings, any>>;
14
+ get(query: SettingsQueryParams, options: Options): Promise<Settings>;
15
+ get(query: SettingsQueryParams, options?: Options) {
16
+ return super.fetch<ApiSettings>({ url: `${this.apiPath}`, params: query }, options).then(
17
+ (res) => Promise.resolve(options?.rawResponse ? res : new Settings(res.data)),
18
+ (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err))
19
+ );
20
+ }
21
+ }
22
+
23
+ export { SettingsService };
@@ -42,15 +42,11 @@ export class ShiftsService extends Service {
42
42
 
43
43
  listAll(query: ShiftsQueryParams, options?: Options): Promise<Shift[]>;
44
44
  async listAll(query: ShiftsQueryParams, options?: Options) {
45
- try {
46
- const shifts = [] as Shift[];
47
- for await (const shift of this.list(query, options)) {
48
- shifts.push(shift);
49
- }
50
- return shifts;
51
- } catch (err) {
52
- return err;
45
+ const shifts = [] as Shift[];
46
+ for await (const shift of this.list(query, options)) {
47
+ shifts.push(shift);
53
48
  }
49
+ return shifts;
54
50
  }
55
51
 
56
52
  listByPage(query: ShiftsQueryParams, options?: Options) {
@@ -42,15 +42,11 @@ class UsersService extends Service {
42
42
 
43
43
  listAll(query: UsersQueryParams, options?: Options): Promise<User[]>;
44
44
  async listAll(query: UsersQueryParams, options?: Options) {
45
- try {
46
- const users = [] as User[];
47
- for await (const user of this.list(query, options)) {
48
- users.push(user);
49
- }
50
- return users;
51
- } catch (err) {
52
- return err;
45
+ const users = [] as User[];
46
+ for await (const user of this.list(query, options)) {
47
+ users.push(user);
53
48
  }
49
+ return users;
54
50
  }
55
51
 
56
52
  listByPage(query: UsersQueryParams, options?: Options) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const Version = { version: '1.0.30' };
1
+ export const Version = { version: '1.0.32' };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DayNotes = void 0;
4
- class DayNotes {
5
- constructor(dayNotes) {
6
- this.id = dayNotes.id;
7
- }
8
- }
9
- exports.DayNotes = DayNotes;
@@ -1,5 +0,0 @@
1
- export class DayNotes {
2
- constructor(dayNotes) {
3
- this.id = dayNotes.id;
4
- }
5
- }
@@ -1,14 +0,0 @@
1
- import { ApiDayNotes } from '../interfaces/index.js';
2
-
3
- export class DayNotes {
4
- public id: number;
5
- public start_date: string;
6
- public end_date: string;
7
- public locations: number[];
8
- public title: string;
9
- public message: string;
10
-
11
- constructor(dayNotes: ApiDayNotes) {
12
- this.id = dayNotes.id;
13
- }
14
- }