rotacloud 1.1.1 → 1.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.
Files changed (158) hide show
  1. package/dist/cjs/interfaces/index.d.ts +1 -0
  2. package/dist/cjs/interfaces/index.js +1 -0
  3. package/dist/cjs/interfaces/query-params/index.d.ts +0 -1
  4. package/dist/cjs/interfaces/query-params/index.js +0 -1
  5. package/dist/cjs/interfaces/terminal.interface.d.ts +1 -0
  6. package/dist/cjs/interfaces/time-zone.interface.d.ts +7 -0
  7. package/dist/cjs/rotacloud.d.ts +2 -1
  8. package/dist/cjs/rotacloud.js +1 -0
  9. package/dist/cjs/services/accounts.service.d.ts +26 -7
  10. package/dist/cjs/services/accounts.service.js +10 -20
  11. package/dist/cjs/services/attendance.service.d.ts +30 -11
  12. package/dist/cjs/services/attendance.service.js +16 -26
  13. package/dist/cjs/services/auth.service.js +1 -3
  14. package/dist/cjs/services/availability.service.d.ts +3 -3
  15. package/dist/cjs/services/availability.service.js +8 -18
  16. package/dist/cjs/services/daily-budgets.service.d.ts +19 -7
  17. package/dist/cjs/services/daily-budgets.service.js +12 -22
  18. package/dist/cjs/services/daily-revenue.service.d.ts +18 -6
  19. package/dist/cjs/services/daily-revenue.service.js +11 -21
  20. package/dist/cjs/services/day-notes.service.d.ts +27 -8
  21. package/dist/cjs/services/day-notes.service.js +15 -25
  22. package/dist/cjs/services/days-off.service.d.ts +17 -5
  23. package/dist/cjs/services/days-off.service.js +13 -23
  24. package/dist/cjs/services/groups.service.d.ts +27 -8
  25. package/dist/cjs/services/groups.service.js +12 -22
  26. package/dist/cjs/services/index.d.ts +1 -0
  27. package/dist/cjs/services/index.js +1 -0
  28. package/dist/cjs/services/leave-embargoes.service.d.ts +27 -8
  29. package/dist/cjs/services/leave-embargoes.service.js +16 -26
  30. package/dist/cjs/services/leave-request.service.d.ts +27 -8
  31. package/dist/cjs/services/leave-request.service.js +15 -25
  32. package/dist/cjs/services/leave.service.d.ts +28 -10
  33. package/dist/cjs/services/leave.service.js +13 -46
  34. package/dist/cjs/services/locations.service.d.ts +27 -8
  35. package/dist/cjs/services/locations.service.js +16 -26
  36. package/dist/cjs/services/pins.service.d.ts +12 -5
  37. package/dist/cjs/services/pins.service.js +1 -1
  38. package/dist/cjs/services/roles.service.d.ts +27 -8
  39. package/dist/cjs/services/roles.service.js +16 -26
  40. package/dist/cjs/services/service.d.ts +12 -3
  41. package/dist/cjs/services/service.js +1 -2
  42. package/dist/cjs/services/settings.service.d.ts +1 -1
  43. package/dist/cjs/services/settings.service.js +1 -1
  44. package/dist/cjs/services/shifts.service.d.ts +30 -11
  45. package/dist/cjs/services/shifts.service.js +21 -31
  46. package/dist/cjs/services/terminals-active.service.d.ts +20 -8
  47. package/dist/cjs/services/terminals-active.service.js +16 -26
  48. package/dist/cjs/services/terminals.service.d.ts +27 -8
  49. package/dist/cjs/services/terminals.service.js +13 -23
  50. package/dist/cjs/services/time-zone.service.d.ts +14 -0
  51. package/dist/cjs/services/time-zone.service.js +82 -0
  52. package/dist/cjs/services/toil-accruals.service.d.ts +4 -4
  53. package/dist/cjs/services/toil-accruals.service.js +12 -22
  54. package/dist/cjs/services/toil-allowance.service.d.ts +3 -3
  55. package/dist/cjs/services/toil-allowance.service.js +9 -19
  56. package/dist/cjs/services/users-clock-in.service.d.ts +22 -10
  57. package/dist/cjs/services/users-clock-in.service.js +5 -5
  58. package/dist/cjs/services/users.service.d.ts +28 -9
  59. package/dist/cjs/services/users.service.js +16 -26
  60. package/dist/cjs/version.js +1 -1
  61. package/dist/mjs/interfaces/index.d.ts +1 -0
  62. package/dist/mjs/interfaces/index.js +1 -0
  63. package/dist/mjs/interfaces/query-params/index.d.ts +0 -1
  64. package/dist/mjs/interfaces/query-params/index.js +0 -1
  65. package/dist/mjs/interfaces/terminal.interface.d.ts +1 -0
  66. package/dist/mjs/interfaces/time-zone.interface.d.ts +7 -0
  67. package/dist/mjs/rotacloud.d.ts +2 -1
  68. package/dist/mjs/rotacloud.js +2 -1
  69. package/dist/mjs/services/accounts.service.d.ts +26 -7
  70. package/dist/mjs/services/accounts.service.js +2 -4
  71. package/dist/mjs/services/attendance.service.d.ts +30 -11
  72. package/dist/mjs/services/attendance.service.js +8 -10
  73. package/dist/mjs/services/auth.service.js +1 -3
  74. package/dist/mjs/services/availability.service.d.ts +3 -3
  75. package/dist/mjs/services/availability.service.js +3 -5
  76. package/dist/mjs/services/daily-budgets.service.d.ts +19 -7
  77. package/dist/mjs/services/daily-budgets.service.js +4 -6
  78. package/dist/mjs/services/daily-revenue.service.d.ts +18 -6
  79. package/dist/mjs/services/daily-revenue.service.js +3 -5
  80. package/dist/mjs/services/day-notes.service.d.ts +27 -8
  81. package/dist/mjs/services/day-notes.service.js +7 -9
  82. package/dist/mjs/services/days-off.service.d.ts +17 -5
  83. package/dist/mjs/services/days-off.service.js +5 -7
  84. package/dist/mjs/services/groups.service.d.ts +27 -8
  85. package/dist/mjs/services/groups.service.js +4 -6
  86. package/dist/mjs/services/index.d.ts +1 -0
  87. package/dist/mjs/services/index.js +1 -0
  88. package/dist/mjs/services/leave-embargoes.service.d.ts +27 -8
  89. package/dist/mjs/services/leave-embargoes.service.js +8 -10
  90. package/dist/mjs/services/leave-request.service.d.ts +27 -8
  91. package/dist/mjs/services/leave-request.service.js +7 -9
  92. package/dist/mjs/services/leave.service.d.ts +28 -10
  93. package/dist/mjs/services/leave.service.js +5 -12
  94. package/dist/mjs/services/locations.service.d.ts +27 -8
  95. package/dist/mjs/services/locations.service.js +8 -10
  96. package/dist/mjs/services/pins.service.d.ts +12 -5
  97. package/dist/mjs/services/pins.service.js +1 -1
  98. package/dist/mjs/services/roles.service.d.ts +27 -8
  99. package/dist/mjs/services/roles.service.js +8 -10
  100. package/dist/mjs/services/service.d.ts +12 -3
  101. package/dist/mjs/services/service.js +0 -2
  102. package/dist/mjs/services/settings.service.d.ts +1 -1
  103. package/dist/mjs/services/settings.service.js +1 -1
  104. package/dist/mjs/services/shifts.service.d.ts +30 -11
  105. package/dist/mjs/services/shifts.service.js +13 -15
  106. package/dist/mjs/services/terminals-active.service.d.ts +20 -8
  107. package/dist/mjs/services/terminals-active.service.js +8 -10
  108. package/dist/mjs/services/terminals.service.d.ts +27 -8
  109. package/dist/mjs/services/terminals.service.js +5 -7
  110. package/dist/mjs/services/time-zone.service.d.ts +14 -0
  111. package/dist/mjs/services/time-zone.service.js +25 -0
  112. package/dist/mjs/services/toil-accruals.service.d.ts +4 -4
  113. package/dist/mjs/services/toil-accruals.service.js +4 -6
  114. package/dist/mjs/services/toil-allowance.service.d.ts +3 -3
  115. package/dist/mjs/services/toil-allowance.service.js +1 -3
  116. package/dist/mjs/services/users-clock-in.service.d.ts +22 -10
  117. package/dist/mjs/services/users-clock-in.service.js +5 -5
  118. package/dist/mjs/services/users.service.d.ts +28 -9
  119. package/dist/mjs/services/users.service.js +8 -10
  120. package/dist/mjs/version.js +1 -1
  121. package/package.json +1 -1
  122. package/src/interfaces/index.ts +1 -0
  123. package/src/interfaces/query-params/index.ts +0 -1
  124. package/src/interfaces/terminal.interface.ts +1 -0
  125. package/src/interfaces/time-zone.interface.ts +7 -0
  126. package/src/rotacloud.ts +2 -0
  127. package/src/services/accounts.service.ts +30 -14
  128. package/src/services/attendance.service.ts +57 -28
  129. package/src/services/auth.service.ts +1 -3
  130. package/src/services/availability.service.ts +14 -13
  131. package/src/services/daily-budgets.service.ts +41 -20
  132. package/src/services/daily-revenue.service.ts +37 -19
  133. package/src/services/day-notes.service.ts +51 -25
  134. package/src/services/days-off.service.ts +46 -25
  135. package/src/services/groups.service.ts +40 -20
  136. package/src/services/index.ts +1 -0
  137. package/src/services/leave-embargoes.service.ts +54 -25
  138. package/src/services/leave-request.service.ts +53 -24
  139. package/src/services/leave.service.ts +41 -27
  140. package/src/services/locations.service.ts +54 -25
  141. package/src/services/pins.service.ts +11 -6
  142. package/src/services/roles.service.ts +49 -25
  143. package/src/services/service.ts +35 -9
  144. package/src/services/settings.service.ts +2 -2
  145. package/src/services/shifts.service.ts +62 -36
  146. package/src/services/terminals-active.service.ts +36 -23
  147. package/src/services/terminals.service.ts +36 -18
  148. package/src/services/time-zone.service.ts +34 -0
  149. package/src/services/toil-accruals.service.ts +9 -11
  150. package/src/services/toil-allowance.service.ts +3 -5
  151. package/src/services/users-clock-in.service.ts +30 -16
  152. package/src/services/users.service.ts +49 -26
  153. package/src/version.ts +1 -1
  154. package/dist/cjs/interfaces/query-params/internal-query-params.interface.d.ts +0 -5
  155. package/dist/mjs/interfaces/query-params/internal-query-params.interface.d.ts +0 -5
  156. package/src/interfaces/query-params/internal-query-params.interface.ts +0 -5
  157. /package/dist/cjs/interfaces/{query-params/internal-query-params.interface.js → time-zone.interface.js} +0 -0
  158. /package/dist/mjs/interfaces/{query-params/internal-query-params.interface.js → time-zone.interface.js} +0 -0
@@ -1,12 +1,12 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { Location } from '../interfaces/index.js';
3
- import { Service, Options, RequirementsOf } from './index.js';
3
+ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
4
 
5
5
  import { LocationsQueryParams } from '../interfaces/query-params/locations-query-params.interface.js';
6
6
 
7
7
  type RequiredProps = 'name';
8
8
 
9
- export class LocationsService extends Service {
9
+ export class LocationsService extends Service<Location> {
10
10
  private apiPath = '/locations';
11
11
 
12
12
  create(data: RequirementsOf<Location, RequiredProps>): Promise<Location>;
@@ -17,27 +17,44 @@ export class LocationsService extends Service {
17
17
  create(data: RequirementsOf<Location, RequiredProps>, options: Options): Promise<Location>;
18
18
  create(data: RequirementsOf<Location, RequiredProps>, options?: Options) {
19
19
  return super
20
- .fetch<Location>({ url: `${this.apiPath}`, data, method: 'POST' })
21
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
20
+ .fetch<Location>({ url: `${this.apiPath}`, data, method: 'POST' }, options)
21
+ .then((res) => (options?.rawResponse ? res : res.data));
22
22
  }
23
23
 
24
24
  get(id: number): Promise<Location>;
25
- get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Location, any>>;
26
- get(id: number, options: Options): Promise<Location>;
27
- get(id: number, options?: Options) {
25
+ get<F extends keyof Location>(
26
+ id: number,
27
+ options: { fields: F[]; rawResponse: true } & OptionsExtended<Location>,
28
+ ): Promise<AxiosResponse<Pick<Location, F>>>;
29
+ get<F extends keyof Location>(
30
+ id: number,
31
+ options: { fields: F[] } & OptionsExtended<Location>,
32
+ ): Promise<Pick<Location, F>>;
33
+ get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Location>>;
34
+ get(id: number, options?: OptionsExtended<Location>): Promise<Location>;
35
+ get(id: number, options?: OptionsExtended<Location>) {
28
36
  return super
29
37
  .fetch<Location>({ url: `${this.apiPath}/${id}` }, options)
30
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
38
+ .then((res) => (options?.rawResponse ? res : res.data));
31
39
  }
32
40
 
33
- async *list(query?: LocationsQueryParams, options?: Options) {
34
- for await (const res of super.iterator<Location>({ url: this.apiPath, params: query }, options)) {
35
- yield res;
36
- }
41
+ list(query?: LocationsQueryParams): AsyncGenerator<Location>;
42
+ list<F extends keyof Location>(
43
+ query: LocationsQueryParams,
44
+ options: { fields: F[] } & OptionsExtended<Location>,
45
+ ): AsyncGenerator<Pick<Location, F>>;
46
+ list(query?: LocationsQueryParams, options?: OptionsExtended<Location>): AsyncGenerator<Location>;
47
+ async *list(query?: LocationsQueryParams, options?: OptionsExtended<Location>) {
48
+ yield* super.iterator({ url: this.apiPath, params: query }, options);
37
49
  }
38
50
 
39
- listAll(query?: LocationsQueryParams, options?: Options): Promise<Location[]>;
40
- async listAll(query: LocationsQueryParams, options?: Options) {
51
+ listAll(query?: LocationsQueryParams): Promise<Location[]>;
52
+ listAll<F extends keyof Location>(
53
+ query: LocationsQueryParams,
54
+ options: { fields: F[] } & OptionsExtended<Location>,
55
+ ): Promise<Pick<Location, F>[]>;
56
+ listAll(query?: LocationsQueryParams, options?: OptionsExtended<Location>): Promise<Location[]>;
57
+ async listAll(query?: LocationsQueryParams, options?: OptionsExtended<Location>) {
41
58
  const locations = [] as Location[];
42
59
  for await (const location of this.list(query, options)) {
43
60
  locations.push(location);
@@ -45,8 +62,17 @@ export class LocationsService extends Service {
45
62
  return locations;
46
63
  }
47
64
 
48
- listByPage(query?: LocationsQueryParams, options?: Options) {
49
- return super.iterator<Location>({ url: this.apiPath, params: query }, options).byPage();
65
+ listByPage(query?: LocationsQueryParams): AsyncGenerator<AxiosResponse<Location[]>>;
66
+ listByPage<F extends keyof Location>(
67
+ query: LocationsQueryParams,
68
+ options: { fields: F[] } & OptionsExtended<Location>,
69
+ ): AsyncGenerator<AxiosResponse<Pick<Location, F>[]>>;
70
+ listByPage(
71
+ query: LocationsQueryParams,
72
+ options?: OptionsExtended<Location>,
73
+ ): AsyncGenerator<AxiosResponse<Location[]>>;
74
+ listByPage(query?: LocationsQueryParams, options?: OptionsExtended<Location>) {
75
+ return super.iterator({ url: this.apiPath, params: query }, options).byPage();
50
76
  }
51
77
 
52
78
  update(id: number, data: Partial<Location>): Promise<Location>;
@@ -58,20 +84,23 @@ export class LocationsService extends Service {
58
84
  update(id: number, data: Partial<Location>, options: Options): Promise<Location>;
59
85
  update(id: number, data: Partial<Location>, options?: Options) {
60
86
  return super
61
- .fetch<Location>({
62
- url: `${this.apiPath}/${id}`,
63
- data,
64
- method: 'POST',
65
- })
66
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
87
+ .fetch<Location>(
88
+ {
89
+ url: `${this.apiPath}/${id}`,
90
+ data,
91
+ method: 'POST',
92
+ },
93
+ options,
94
+ )
95
+ .then((res) => (options?.rawResponse ? res : res.data));
67
96
  }
68
97
 
69
98
  delete(id: number): Promise<number>;
70
- delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
99
+ delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
71
100
  delete(id: number, options: Options): Promise<number>;
72
101
  delete(id: number, options?: Options) {
73
102
  return super
74
- .fetch<Location>({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
75
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
103
+ .fetch<void>({ url: `${this.apiPath}/${id}`, method: 'DELETE' }, options)
104
+ .then((res) => (options?.rawResponse ? res : res.status));
76
105
  }
77
106
  }
@@ -1,16 +1,21 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { Pin } from '../interfaces/index.js';
3
- import { Service, Options } from './index.js';
3
+ import { Service, Options, OptionsExtended } from './index.js';
4
4
 
5
- export class PinsService extends Service {
5
+ export class PinsService extends Service<Pin> {
6
6
  private apiPath = '/pins';
7
7
 
8
8
  get(id: string): Promise<Pin>;
9
- get(id: string, options?: { rawResponse: true } & Options): Promise<AxiosResponse<Pin, any>>;
10
- get(id: string, options?: Options): Promise<Pin>;
11
- get(id: string, options?: Options) {
9
+ get<F extends keyof Pin>(
10
+ id: string,
11
+ options: { fields: F[]; rawResponse: true } & OptionsExtended<Pin>,
12
+ ): Promise<AxiosResponse<Pick<Pin, F>>>;
13
+ get<F extends keyof Pin>(id: string, options: { fields: F[] } & OptionsExtended<Pin>): Promise<Pick<Pin, F>>;
14
+ get(id: string, options: { rawResponse: true } & Options): Promise<AxiosResponse<Pin>>;
15
+ get(id: string, options?: OptionsExtended<Pin>): Promise<Pin>;
16
+ get(id: string, options?: OptionsExtended<Pin>) {
12
17
  return super
13
18
  .fetch<Pin>({ url: `${this.apiPath}/${id}` }, options)
14
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
19
+ .then((res) => (options?.rawResponse ? res : res.data));
15
20
  }
16
21
  }
@@ -1,12 +1,12 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { Role } from '../interfaces/index.js';
3
- import { Service, Options, RequirementsOf } from './index.js';
3
+ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
4
 
5
5
  import { RolesQueryParams } from '../interfaces/query-params/roles-query-params.interface.js';
6
6
 
7
7
  type RequiredProps = 'name';
8
8
 
9
- export class RolesService extends Service {
9
+ export class RolesService extends Service<Role> {
10
10
  private apiPath = '/roles';
11
11
 
12
12
  create(data: RequirementsOf<Role, RequiredProps>): Promise<Role>;
@@ -17,27 +17,41 @@ export class RolesService extends Service {
17
17
  create(data: RequirementsOf<Role, RequiredProps>, options: Options): Promise<Role>;
18
18
  create(data: RequirementsOf<Role, RequiredProps>, options?: Options) {
19
19
  return super
20
- .fetch<Role>({ url: this.apiPath, data, method: 'POST' })
21
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
20
+ .fetch<Role>({ url: this.apiPath, data, method: 'POST' }, options)
21
+ .then((res) => (options?.rawResponse ? res : res.data));
22
22
  }
23
23
 
24
24
  get(id: number): Promise<Role>;
25
- get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Role, any>>;
26
- get(id: number, options: Options): Promise<Role>;
27
- get(id: number, options?: Options) {
25
+ get<F extends keyof Role>(
26
+ id: number,
27
+ options: { fields: F[]; rawResponse: true } & OptionsExtended<Role>,
28
+ ): Promise<AxiosResponse<Pick<Role, F>>>;
29
+ get<F extends keyof Role>(id: number, options: { fields: F[] } & OptionsExtended<Role>): Promise<Pick<Role, F>>;
30
+ get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Role>>;
31
+ get(id: number, options?: OptionsExtended<Role>): Promise<Role>;
32
+ get(id: number, options?: OptionsExtended<Role>) {
28
33
  return super
29
34
  .fetch<Role>({ url: `${this.apiPath}/${id}` }, options)
30
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
35
+ .then((res) => (options?.rawResponse ? res : res.data));
31
36
  }
32
37
 
33
- async *list(query?: RolesQueryParams, options?: Options) {
34
- for await (const res of super.iterator<Role>({ url: this.apiPath, params: query }, options)) {
35
- yield res;
36
- }
38
+ list(query?: RolesQueryParams): AsyncGenerator<Role>;
39
+ list<F extends keyof Role>(
40
+ query: RolesQueryParams,
41
+ options: { fields: F[] } & OptionsExtended<Role>,
42
+ ): AsyncGenerator<Pick<Role, F>>;
43
+ list(query?: RolesQueryParams, options?: OptionsExtended<Role>): AsyncGenerator<Role>;
44
+ async *list(query?: RolesQueryParams, options?: OptionsExtended<Role>) {
45
+ yield* super.iterator({ url: this.apiPath, params: query }, options);
37
46
  }
38
47
 
39
- listAll(query?: RolesQueryParams, options?: Options): Promise<Role[]>;
40
- async listAll(query: RolesQueryParams, options?: Options) {
48
+ listAll(query?: RolesQueryParams): Promise<Role[]>;
49
+ listAll<F extends keyof Role>(
50
+ query: RolesQueryParams,
51
+ options: { fields: F[] } & OptionsExtended<Role>,
52
+ ): Promise<Pick<Role, F>[]>;
53
+ listAll(query?: RolesQueryParams, options?: OptionsExtended<Role>): Promise<Role[]>;
54
+ async listAll(query?: RolesQueryParams, options?: OptionsExtended<Role>) {
41
55
  const roles = [] as Role[];
42
56
  for await (const role of this.list(query, options)) {
43
57
  roles.push(role);
@@ -45,28 +59,38 @@ export class RolesService extends Service {
45
59
  return roles;
46
60
  }
47
61
 
48
- listByPage(query?: RolesQueryParams, options?: Options) {
49
- return super.iterator<Role>({ url: this.apiPath, params: query }, options).byPage();
62
+ listByPage(query?: RolesQueryParams): AsyncGenerator<AxiosResponse<Role[]>>;
63
+ listByPage<F extends keyof Role>(
64
+ query: RolesQueryParams,
65
+ options: { fields: F[] } & OptionsExtended<Role>,
66
+ ): AsyncGenerator<AxiosResponse<Pick<Role, F>[]>>;
67
+ listByPage(query?: RolesQueryParams, options?: OptionsExtended<Role>): AsyncGenerator<AxiosResponse<Role[]>>;
68
+ listByPage(query?: RolesQueryParams, options?: OptionsExtended<Role>) {
69
+ return super.iterator({ url: this.apiPath, params: query }, options).byPage();
50
70
  }
71
+
51
72
  update(id: number, data: Partial<Role>): Promise<Role>;
52
73
  update(id: number, data: Partial<Role>, options: { rawResponse: true } & Options): Promise<AxiosResponse<Role, any>>;
53
74
  update(id: number, data: Partial<Role>, options: Options): Promise<Role>;
54
75
  update(id: number, data: Partial<Role>, options?: Options) {
55
76
  return super
56
- .fetch<Role>({
57
- url: `${this.apiPath}/${id}`,
58
- data,
59
- method: 'POST',
60
- })
61
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
77
+ .fetch<Role>(
78
+ {
79
+ url: `${this.apiPath}/${id}`,
80
+ data,
81
+ method: 'POST',
82
+ },
83
+ options,
84
+ )
85
+ .then((res) => (options?.rawResponse ? res : res.data));
62
86
  }
63
87
 
64
88
  delete(id: number): Promise<number>;
65
- delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
89
+ delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
66
90
  delete(id: number, options: Options): Promise<number>;
67
91
  delete(id: number, options?: Options) {
68
92
  return super
69
- .fetch<Role>({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
70
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
93
+ .fetch<void>({ url: `${this.apiPath}/${id}`, method: 'DELETE' }, options)
94
+ .then((res) => (options?.rawResponse ? res : res.status));
71
95
  }
72
96
  }
@@ -29,13 +29,15 @@ export type RetryOptions =
29
29
 
30
30
  export interface Options {
31
31
  rawResponse?: boolean;
32
- expand?: string[];
33
- fields?: string[];
34
32
  limit?: number;
35
33
  offset?: number;
36
34
  dryRun?: boolean;
37
35
  }
38
36
 
37
+ export type OptionsExtended<T = unknown> = Options & {
38
+ fields?: (keyof T)[];
39
+ };
40
+
39
41
  const DEFAULT_RETRIES = 3;
40
42
  const DEFAULT_RETRY_DELAY = 2000;
41
43
 
@@ -51,7 +53,7 @@ const DEFAULT_RETRY_STRATEGY_OPTIONS: Record<RetryStrategy, RetryOptions> = {
51
53
  },
52
54
  };
53
55
 
54
- type ParameterPrimitive = string | boolean | number | null;
56
+ type ParameterPrimitive = string | boolean | number | null | symbol;
55
57
  type ParameterValue = ParameterPrimitive | ParameterPrimitive[] | undefined;
56
58
 
57
59
  export abstract class Service<ApiResponse = any> {
@@ -65,7 +67,7 @@ export abstract class Service<ApiResponse = any> {
65
67
  const parsedError = this.parseClientError(error);
66
68
 
67
69
  return Promise.reject(parsedError);
68
- }
70
+ },
69
71
  );
70
72
  return client;
71
73
  }
@@ -87,9 +89,11 @@ export abstract class Service<ApiResponse = any> {
87
89
  return endpoint === '/leave_requests';
88
90
  }
89
91
 
90
- private buildQueryParams(options?: Options, extraParams?: Record<string, ParameterValue>) {
92
+ private buildQueryParams<T = ApiResponse>(
93
+ options?: OptionsExtended<T>,
94
+ extraParams?: Record<string, ParameterValue>,
95
+ ) {
91
96
  const queryParams: Record<string, ParameterValue> = {
92
- expand: options?.expand,
93
97
  fields: options?.fields,
94
98
  limit: options?.limit,
95
99
  offset: options?.offset,
@@ -109,7 +113,21 @@ export abstract class Service<ApiResponse = any> {
109
113
  return new URLSearchParams(reducedParams);
110
114
  }
111
115
 
112
- fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig, options?: Options): Promise<AxiosResponse<T>> {
116
+ fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig): Promise<AxiosResponse<T>>;
117
+ fetch<T = ApiResponse>(
118
+ reqConfig: AxiosRequestConfig,
119
+ options: { fields: Required<OptionsExtended<T>>['fields'] } & OptionsExtended<T>,
120
+ ): Promise<AxiosResponse<Pick<T, (typeof options)['fields'][number]>>>;
121
+ fetch<T extends unknown[] = ApiResponse[], E = T[number]>(
122
+ reqConfig: AxiosRequestConfig,
123
+ options: { fields: Required<OptionsExtended<E>>['fields'] } & OptionsExtended<E>,
124
+ ): Promise<AxiosResponse<Pick<E, (typeof options)['fields'][number]>[]>>;
125
+ fetch<T extends unknown[] = ApiResponse[]>(
126
+ reqConfig: AxiosRequestConfig,
127
+ options?: Options,
128
+ ): Promise<AxiosResponse<T>>;
129
+ fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig, options?: Options): Promise<AxiosResponse<T | Partial<T>>>;
130
+ fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig, options?: Options) {
113
131
  const headers: Record<string, string> = {
114
132
  Authorization: RotaCloud.config.apiKey
115
133
  ? `Bearer ${RotaCloud.config.apiKey}`
@@ -161,9 +179,17 @@ export abstract class Service<ApiResponse = any> {
161
179
  }
162
180
 
163
181
  /** Iterates through every page for a potentially paginated request */
164
- private async *fetchPages<T>(
182
+ private fetchPages<T = ApiResponse>(
183
+ reqConfig: AxiosRequestConfig<T[]>,
184
+ options: { fields: Required<OptionsExtended<T>>['fields'] } & OptionsExtended<T>,
185
+ ): AsyncGenerator<AxiosResponse<Pick<T, (typeof options)['fields'][number]>[]>>;
186
+ private fetchPages<T = ApiResponse>(
187
+ reqConfig: AxiosRequestConfig<T[]>,
188
+ options?: Options,
189
+ ): AsyncGenerator<AxiosResponse<T[]>>;
190
+ private async *fetchPages<T = ApiResponse>(
165
191
  reqConfig: AxiosRequestConfig<T[]>,
166
- options: Options | undefined
192
+ options?: Options,
167
193
  ): AsyncGenerator<AxiosResponse<T[]>> {
168
194
  const fallbackLimit = 20;
169
195
  const res = await this.fetch<T[]>(reqConfig, options);
@@ -5,7 +5,7 @@ import { Settings } from '../interfaces/index.js';
5
5
 
6
6
  import { SettingsQueryParams } from '../rotacloud.js';
7
7
 
8
- export class SettingsService extends Service {
8
+ export class SettingsService extends Service<Settings> {
9
9
  private apiPath = '/settings';
10
10
 
11
11
  get(query: SettingsQueryParams): Promise<Settings>;
@@ -14,6 +14,6 @@ export class SettingsService extends Service {
14
14
  get(query: SettingsQueryParams, options?: Options) {
15
15
  return super
16
16
  .fetch<Settings>({ url: `${this.apiPath}`, params: query }, options)
17
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
17
+ .then((res) => (options?.rawResponse ? res : res.data));
18
18
  }
19
19
  }
@@ -1,12 +1,12 @@
1
1
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import { Shift } from '../interfaces/index.js';
3
- import { Service, Options, RequirementsOf } from './index.js';
3
+ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
4
 
5
5
  import { ShiftsQueryParams } from '../interfaces/query-params/shifts-query-params.interface.js';
6
6
 
7
7
  type RequiredProps = 'end_time' | 'start_time' | 'location';
8
8
 
9
- export class ShiftsService extends Service {
9
+ export class ShiftsService extends Service<Shift> {
10
10
  private apiPath = '/shifts';
11
11
 
12
12
  create(data: RequirementsOf<Shift, RequiredProps>): Promise<Shift>;
@@ -17,27 +17,41 @@ export class ShiftsService extends Service {
17
17
  create(data: RequirementsOf<Shift, RequiredProps>, options: Options): Promise<Shift>;
18
18
  create(data: RequirementsOf<Shift, RequiredProps>, options?: Options) {
19
19
  return super
20
- .fetch<Shift>({ url: this.apiPath, data, method: 'POST' })
21
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
20
+ .fetch<Shift>({ url: this.apiPath, data, method: 'POST' }, options)
21
+ .then((res) => (options?.rawResponse ? res : res.data));
22
22
  }
23
23
 
24
24
  get(id: number): Promise<Shift>;
25
- get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Shift, any>>;
26
- get(id: number, options: Options): Promise<Shift>;
27
- get(id: number, options?: Options) {
25
+ get<F extends keyof Shift>(
26
+ id: number,
27
+ options: { fields: F[]; rawResponse: true } & OptionsExtended<Shift>,
28
+ ): Promise<AxiosResponse<Pick<Shift, F>>>;
29
+ get<F extends keyof Shift>(id: number, options: { fields: F[] } & OptionsExtended<Shift>): Promise<Pick<Shift, F>>;
30
+ get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Shift>>;
31
+ get(id: number, options?: OptionsExtended<Shift>): Promise<Shift>;
32
+ get(id: number, options?: OptionsExtended<Shift>) {
28
33
  return super
29
34
  .fetch<Shift>({ url: `${this.apiPath}/${id}` }, options)
30
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
35
+ .then((res) => (options?.rawResponse ? res : res.data));
31
36
  }
32
37
 
33
- async *list(query: ShiftsQueryParams, options?: Options) {
34
- for await (const res of super.iterator<Shift>({ url: this.apiPath, params: query }, options)) {
35
- yield res;
36
- }
38
+ list(query: ShiftsQueryParams): AsyncGenerator<Shift>;
39
+ list<F extends keyof Shift>(
40
+ query: ShiftsQueryParams,
41
+ options: { fields: F[] } & OptionsExtended<Shift>,
42
+ ): AsyncGenerator<Pick<Shift, F>>;
43
+ list(query: ShiftsQueryParams, options?: OptionsExtended<Shift>): AsyncGenerator<Shift>;
44
+ async *list(query: ShiftsQueryParams, options?: OptionsExtended<Shift>) {
45
+ yield* super.iterator({ url: this.apiPath, params: query }, options);
37
46
  }
38
47
 
39
- listAll(query: ShiftsQueryParams, options?: Options): Promise<Shift[]>;
40
- async listAll(query: ShiftsQueryParams, options?: Options) {
48
+ listAll(query: ShiftsQueryParams): Promise<Shift[]>;
49
+ listAll<F extends keyof Shift>(
50
+ query: ShiftsQueryParams,
51
+ options: { fields: F[] } & OptionsExtended<Shift>,
52
+ ): Promise<Pick<Shift, F>[]>;
53
+ listAll(query: ShiftsQueryParams, options?: OptionsExtended<Shift>): Promise<Shift[]>;
54
+ async listAll(query: ShiftsQueryParams, options?: OptionsExtended<Shift>) {
41
55
  const shifts = [] as Shift[];
42
56
  for await (const shift of this.list(query, options)) {
43
57
  shifts.push(shift);
@@ -45,7 +59,13 @@ export class ShiftsService extends Service {
45
59
  return shifts;
46
60
  }
47
61
 
48
- listByPage(query: ShiftsQueryParams, options?: Options) {
62
+ listByPage(query: ShiftsQueryParams): AsyncGenerator<AxiosResponse<Shift[]>>;
63
+ listByPage<F extends keyof Shift>(
64
+ query: ShiftsQueryParams,
65
+ options: { fields: F[] } & OptionsExtended<Shift>,
66
+ ): AsyncGenerator<AxiosResponse<Pick<Shift, F>[]>>;
67
+ listByPage(query: ShiftsQueryParams, options?: OptionsExtended<Shift>): AsyncGenerator<AxiosResponse<Shift[]>>;
68
+ listByPage(query: ShiftsQueryParams, options?: OptionsExtended<Shift>) {
49
69
  return super.iterator<Shift>({ url: this.apiPath, params: query }, options).byPage();
50
70
  }
51
71
 
@@ -65,20 +85,26 @@ export class ShiftsService extends Service {
65
85
  update(shifts: RequirementsOf<Shift, 'id'> | RequirementsOf<Shift, 'id'>[], options?: Options) {
66
86
  if (!Array.isArray(shifts)) {
67
87
  return super
68
- .fetch<Shift>({
69
- url: `${this.apiPath}/${shifts.id}`,
70
- data: shifts,
71
- method: 'POST',
72
- })
88
+ .fetch<Shift>(
89
+ {
90
+ url: `${this.apiPath}/${shifts.id}`,
91
+ data: shifts,
92
+ method: 'POST',
93
+ },
94
+ options,
95
+ )
73
96
  .then((res) => (options?.rawResponse ? res : res.data));
74
97
  }
75
98
 
76
99
  return super
77
- .fetch<{ code: number; data?: Shift; error?: string }[]>({
78
- url: this.apiPath,
79
- data: shifts,
80
- method: 'POST',
81
- })
100
+ .fetch<{ code: number; data?: Shift; error?: string }[]>(
101
+ {
102
+ url: this.apiPath,
103
+ data: shifts,
104
+ method: 'POST',
105
+ },
106
+ options,
107
+ )
82
108
  .then((res) => {
83
109
  if (options?.rawResponse) return res;
84
110
 
@@ -94,40 +120,40 @@ export class ShiftsService extends Service {
94
120
  }
95
121
 
96
122
  delete(ids: number | number[]): Promise<number>;
97
- delete(ids: number | number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
123
+ delete(ids: number | number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
98
124
  delete(ids: number | number[], options: Options): Promise<number>;
99
125
  delete(ids: number | number[], options?: Options) {
100
126
  const params: AxiosRequestConfig = Array.isArray(ids)
101
127
  ? { url: this.apiPath, data: { ids }, method: 'DELETE' }
102
128
  : { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
103
129
 
104
- return super.fetch<Shift>(params).then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
130
+ return super.fetch<void>(params, options).then((res) => (options?.rawResponse ? res : res.status));
105
131
  }
106
132
 
107
133
  acknowledge(data: number[]): Promise<number>;
108
- acknowledge(data: number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
134
+ acknowledge(data: number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
109
135
  acknowledge(data: number[], options: Options): Promise<number>;
110
136
  acknowledge(data: number[], options?: Options) {
111
137
  return super
112
- .fetch<Shift>({ url: '/shifts_acknowledged', data, method: 'POST' })
113
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
138
+ .fetch<Shift>({ url: '/shifts_acknowledged', data, method: 'POST' }, options)
139
+ .then((res) => (options?.rawResponse ? res : res.status));
114
140
  }
115
141
 
116
142
  publish(data: { shifts: number[] }): Promise<number>;
117
- publish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
143
+ publish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
118
144
  publish(data: { shifts: number[] }, options: Options): Promise<number>;
119
145
  publish(data: { shifts: number[] }, options?: Options) {
120
146
  return super
121
- .fetch<Shift>({ url: '/shifts_published', data, method: 'POST' })
122
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
147
+ .fetch<Shift>({ url: '/shifts_published', data, method: 'POST' }, options)
148
+ .then((res) => (options?.rawResponse ? res : res.status));
123
149
  }
124
150
 
125
151
  unpublish(data: { shifts: number[] }): Promise<number>;
126
- unpublish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
152
+ unpublish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
127
153
  unpublish(data: { shifts: number[] }, options: Options): Promise<number>;
128
154
  unpublish(data: { shifts: number[] }, options?: Options) {
129
155
  return super
130
- .fetch<Shift>({ url: '/shifts_published', data, method: 'DELETE' })
131
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
156
+ .fetch<Shift>({ url: '/shifts_published', data, method: 'DELETE' }, options)
157
+ .then((res) => (options?.rawResponse ? res : res.status));
132
158
  }
133
159
  }