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,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { Terminal, TerminalLocation } from '../interfaces/index.js';
3
- import { Service, Options } from './index.js';
3
+ import { Service, Options, OptionsExtended } from './index.js';
4
4
 
5
5
  interface LaunchTerminal {
6
6
  terminal: number;
@@ -13,20 +13,23 @@ interface PingTerminal {
13
13
  device: string;
14
14
  }
15
15
 
16
- export class TerminalsActiveService extends Service {
16
+ export class TerminalsActiveService extends Service<Terminal> {
17
17
  private apiPath = '/terminals_active';
18
18
 
19
19
  launchTerminal(data: LaunchTerminal): Promise<Terminal>;
20
- launchTerminal(data: LaunchTerminal, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
20
+ launchTerminal(data: LaunchTerminal, options: { rawResponse: true } & Options): Promise<AxiosResponse<Terminal>>;
21
21
  launchTerminal(data: LaunchTerminal, options: Options): Promise<Terminal>;
22
22
  launchTerminal(data: LaunchTerminal, options?: Options) {
23
23
  return super
24
- .fetch<Terminal>({
25
- url: `${this.apiPath}`,
26
- data,
27
- method: 'POST',
28
- })
29
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
24
+ .fetch<Terminal>(
25
+ {
26
+ url: this.apiPath,
27
+ data,
28
+ method: 'POST',
29
+ },
30
+ options,
31
+ )
32
+ .then((res) => (options?.rawResponse ? res : res.data));
30
33
  }
31
34
 
32
35
  pingTerminal(id: number, data: PingTerminal): Promise<number>;
@@ -34,22 +37,27 @@ export class TerminalsActiveService extends Service {
34
37
  id: number,
35
38
  data: PingTerminal,
36
39
  options: { rawResponse: true } & Options,
37
- ): Promise<AxiosResponse<any, any>>;
40
+ ): Promise<AxiosResponse<number>>;
38
41
  pingTerminal(id: number, data: PingTerminal, options: Options): Promise<number>;
39
42
  pingTerminal(id: number, data: PingTerminal, options?: Options) {
40
43
  return super
41
- .fetch({ url: `${this.apiPath}/${id}`, data, method: 'POST' })
42
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
44
+ .fetch<number>({ url: `${this.apiPath}/${id}`, data, method: 'POST' }, options)
45
+ .then((res) => (options?.rawResponse ? res : res.data));
43
46
  }
44
47
 
45
- async *list(options?: Options) {
46
- for await (const res of super.iterator<Terminal>({ url: this.apiPath }, options)) {
47
- yield res;
48
- }
48
+ list(): AsyncGenerator<Terminal>;
49
+ list<F extends keyof Terminal>(
50
+ options: { fields: F[] } & OptionsExtended<Terminal>,
51
+ ): AsyncGenerator<Pick<Terminal, F>>;
52
+ list(options?: OptionsExtended<Terminal>): AsyncGenerator<Terminal>;
53
+ async *list(options?: OptionsExtended<Terminal>) {
54
+ yield* super.iterator({ url: this.apiPath }, options);
49
55
  }
50
56
 
51
- listAll(options?: Options): Promise<Terminal[]>;
52
- async listAll(options?: Options) {
57
+ listAll(): Promise<Terminal[]>;
58
+ listAll<F extends keyof Terminal>(options: { fields: F[] } & OptionsExtended<Terminal>): Promise<Pick<Terminal, F>[]>;
59
+ listAll(options?: OptionsExtended<Terminal>): Promise<Terminal[]>;
60
+ async listAll(options?: OptionsExtended<Terminal>) {
53
61
  const users = [] as Terminal[];
54
62
  for await (const user of this.list(options)) {
55
63
  users.push(user);
@@ -57,16 +65,21 @@ export class TerminalsActiveService extends Service {
57
65
  return users;
58
66
  }
59
67
 
60
- listByPage(options?: Options) {
61
- return super.iterator<Terminal>({ url: this.apiPath }, options).byPage();
68
+ listByPage(): AsyncGenerator<AxiosResponse<Terminal[]>>;
69
+ listByPage<F extends keyof Terminal>(
70
+ options: { fields: F[] } & OptionsExtended<Terminal>,
71
+ ): AsyncGenerator<AxiosResponse<Pick<Terminal, F>[]>>;
72
+ listByPage(options?: OptionsExtended<Terminal>): AsyncGenerator<AxiosResponse<Terminal[]>>;
73
+ listByPage(options?: OptionsExtended<Terminal>) {
74
+ return super.iterator({ url: this.apiPath }, options).byPage();
62
75
  }
63
76
 
64
77
  closeTerminal(id: number): Promise<number>;
65
- closeTerminal(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
78
+ closeTerminal(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
66
79
  closeTerminal(id: number, options: Options): Promise<number>;
67
80
  closeTerminal(id: number, options?: Options) {
68
81
  return super
69
- .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
70
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
82
+ .fetch<void>({ url: `${this.apiPath}/${id}`, method: 'DELETE' }, options)
83
+ .then((res) => (options?.rawResponse ? res : res.status));
71
84
  }
72
85
  }
@@ -1,10 +1,10 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { Terminal } 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
  type RequiredProps = 'name' | 'timezone';
6
6
 
7
- export class TerminalsService extends Service {
7
+ export class TerminalsService extends Service<Terminal> {
8
8
  private apiPath = '/terminals';
9
9
 
10
10
  create(data: RequirementsOf<Terminal, RequiredProps>): Promise<Terminal>;
@@ -16,16 +16,24 @@ export class TerminalsService extends Service {
16
16
  create(data: RequirementsOf<Terminal, RequiredProps>, options?: Options) {
17
17
  return super
18
18
  .fetch<Terminal>({ url: this.apiPath, data, method: 'POST' })
19
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
19
+ .then((res) => (options?.rawResponse ? res : res.data));
20
20
  }
21
21
 
22
22
  get(id: number): Promise<Terminal>;
23
- get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Terminal, any>>;
24
- get(id: number, options: Options): Promise<Terminal>;
23
+ get<F extends keyof Terminal>(
24
+ id: number,
25
+ options: { fields: F[]; rawResponse: true } & OptionsExtended<Terminal>,
26
+ ): Promise<AxiosResponse<Pick<Terminal, F>>>;
27
+ get<F extends keyof Terminal>(
28
+ id: number,
29
+ options: { fields: F[] } & OptionsExtended<Terminal>,
30
+ ): Promise<Pick<Terminal, F>>;
31
+ get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Terminal>>;
32
+ get(id: number, options?: OptionsExtended<Terminal>): Promise<Terminal>;
25
33
  get(id: number, options?: Options) {
26
34
  return super
27
35
  .fetch<Terminal>({ url: `${this.apiPath}/${id}` }, options)
28
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
36
+ .then((res) => (options?.rawResponse ? res : res.data));
29
37
  }
30
38
 
31
39
  update(id: number, data: Partial<Terminal>): Promise<Terminal>;
@@ -42,26 +50,31 @@ export class TerminalsService extends Service {
42
50
  data,
43
51
  method: 'POST',
44
52
  })
45
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
53
+ .then((res) => (options?.rawResponse ? res : res.data));
46
54
  }
47
55
 
48
56
  closeTerminal(id: number): Promise<number>;
49
- closeTerminal(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<number, any>>;
57
+ closeTerminal(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
50
58
  closeTerminal(id: number, options: Options): Promise<number>;
51
59
  closeTerminal(id: number, options?: Options) {
52
60
  return super
53
- .fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
54
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
61
+ .fetch<void>({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
62
+ .then((res) => (options?.rawResponse ? res : res.status));
55
63
  }
56
64
 
57
- async *list(options?: Options) {
58
- for await (const res of super.iterator<Terminal>({ url: this.apiPath }, options)) {
59
- yield res;
60
- }
65
+ list(): AsyncGenerator<Terminal>;
66
+ list<F extends keyof Terminal>(
67
+ options: { fields: F[] } & OptionsExtended<Terminal>,
68
+ ): AsyncGenerator<Pick<Terminal, F>>;
69
+ list(options?: OptionsExtended<Terminal>): AsyncGenerator<Terminal>;
70
+ async *list(options?: OptionsExtended<Terminal>) {
71
+ yield* super.iterator({ url: this.apiPath }, options);
61
72
  }
62
73
 
63
- listAll(options?: Options): Promise<Terminal[]>;
64
- async listAll(options?: Options) {
74
+ listAll(): Promise<Terminal[]>;
75
+ listAll<F extends keyof Terminal>(options: { fields: F[] } & OptionsExtended<Terminal>): Promise<Pick<Terminal, F>[]>;
76
+ listAll(options?: OptionsExtended<Terminal>): Promise<Terminal[]>;
77
+ async listAll(options?: OptionsExtended<Terminal>) {
65
78
  const users = [] as Terminal[];
66
79
  for await (const user of this.list(options)) {
67
80
  users.push(user);
@@ -69,7 +82,12 @@ export class TerminalsService extends Service {
69
82
  return users;
70
83
  }
71
84
 
72
- listByPage(options?: Options) {
73
- return super.iterator<Terminal>({ url: this.apiPath }, options).byPage();
85
+ listByPage(): AsyncGenerator<AxiosResponse<Terminal[]>>;
86
+ listByPage<F extends keyof Terminal>(
87
+ options: { fields: F[] } & OptionsExtended<Terminal>,
88
+ ): AsyncGenerator<AxiosResponse<Pick<Terminal, F>[]>>;
89
+ listByPage(options?: OptionsExtended<Terminal>): AsyncGenerator<AxiosResponse<Terminal[]>>;
90
+ listByPage(options?: OptionsExtended<Terminal>) {
91
+ return super.iterator({ url: this.apiPath }, options).byPage();
74
92
  }
75
93
  }
@@ -0,0 +1,34 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Service, Options } from './index.js';
3
+
4
+ import { TimeZone } from '../interfaces/index.js';
5
+
6
+ export class TimeZoneService extends Service<TimeZone> {
7
+ private apiPath = '/timezones';
8
+
9
+ get(id: number): Promise<TimeZone>;
10
+ get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<TimeZone, any>>;
11
+ get(id: number, options: Options): Promise<TimeZone>;
12
+ get(id: number, options?: Options) {
13
+ return super
14
+ .fetch<TimeZone>({ url: `${this.apiPath}/${id}` }, options)
15
+ .then((res) => (options?.rawResponse ? res : res.data));
16
+ }
17
+
18
+ async *list(options?: Options) {
19
+ yield* super.iterator({ url: this.apiPath }, options);
20
+ }
21
+
22
+ listAll(options?: Options): Promise<TimeZone[]>;
23
+ async listAll(options?: Options) {
24
+ const timezones = [] as TimeZone[];
25
+ for await (const timezone of this.list(options)) {
26
+ timezones.push(timezone);
27
+ }
28
+ return timezones;
29
+ }
30
+
31
+ listByPage(options?: Options) {
32
+ return super.iterator({ url: this.apiPath }, options).byPage();
33
+ }
34
+ }
@@ -17,7 +17,7 @@ export class ToilAccrualsService extends Service {
17
17
  create(data: RequirementsOf<ToilAccrual, RequiredProps>, options?: Options) {
18
18
  return super
19
19
  .fetch<ToilAccrual>({ url: this.apiPath, data, method: 'POST' })
20
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
20
+ .then((res) => (options?.rawResponse ? res : res.data));
21
21
  }
22
22
 
23
23
  get(id: number): Promise<ToilAccrual>;
@@ -26,16 +26,14 @@ export class ToilAccrualsService extends Service {
26
26
  get(id: number, options?: Options) {
27
27
  return super
28
28
  .fetch<ToilAccrual>({ url: `${this.apiPath}/${id}` }, options)
29
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
29
+ .then((res) => (options?.rawResponse ? res : res.data));
30
30
  }
31
31
 
32
- async *list(query: ToilAccrualsQueryParams, options?: Options) {
33
- for await (const res of super.iterator<ToilAccrual>({ url: this.apiPath, params: query }, options)) {
34
- yield res;
35
- }
32
+ async *list(query?: ToilAccrualsQueryParams, options?: Options) {
33
+ yield* super.iterator<ToilAccrual>({ url: this.apiPath, params: query }, options);
36
34
  }
37
35
 
38
- async listAll(query: ToilAccrualsQueryParams, options?: Options): Promise<ToilAccrual[]> {
36
+ async listAll(query?: ToilAccrualsQueryParams, options?: Options): Promise<ToilAccrual[]> {
39
37
  const toilAccruals = [] as ToilAccrual[];
40
38
  for await (const accrual of this.list(query, options)) {
41
39
  toilAccruals.push(accrual);
@@ -43,16 +41,16 @@ export class ToilAccrualsService extends Service {
43
41
  return toilAccruals;
44
42
  }
45
43
 
46
- listByPage(query: ToilAccrualsQueryParams, options?: Options) {
44
+ listByPage(query?: ToilAccrualsQueryParams, options?: Options) {
47
45
  return super.iterator<ToilAccrual>({ url: this.apiPath, params: query }, options).byPage();
48
46
  }
49
47
 
50
48
  delete(id: number): Promise<number>;
51
- delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
49
+ delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
52
50
  delete(id: number, options: Options): Promise<number>;
53
51
  delete(id: number, options?: Options) {
54
52
  return super
55
- .fetch<ToilAccrual>({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
56
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
53
+ .fetch<void>({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
54
+ .then((res) => (options?.rawResponse ? res : res.status));
57
55
  }
58
56
  }
@@ -2,13 +2,11 @@ import { Options, Service } from './service';
2
2
  import { ToilAllowanceQueryParams } from '../interfaces/query-params/toil-allowance-query-params.interface';
3
3
  import { ToilAllowance } from '../interfaces/toil-allowance.interface';
4
4
 
5
- export class ToilAllowanceService extends Service {
5
+ export class ToilAllowanceService extends Service<ToilAllowance> {
6
6
  private apiPath = '/toil_allowance';
7
7
 
8
8
  async *list(year: number, query: ToilAllowanceQueryParams, options?: Options) {
9
- for await (const res of super.iterator<ToilAllowance>({ url: `${this.apiPath}/${year}`, params: query }, options)) {
10
- yield res;
11
- }
9
+ yield* super.iterator({ url: `${this.apiPath}/${year}`, params: query }, options);
12
10
  }
13
11
 
14
12
  async listAll(year: number, query: ToilAllowanceQueryParams, options?: Options): Promise<ToilAllowance[]> {
@@ -20,6 +18,6 @@ export class ToilAllowanceService extends Service {
20
18
  }
21
19
 
22
20
  listByPage(year: number, query: ToilAllowanceQueryParams, options?: Options) {
23
- return super.iterator<ToilAllowance[]>({ url: `${this.apiPath}/${year}`, params: query }, options).byPage();
21
+ return super.iterator({ url: `${this.apiPath}/${year}`, params: query }, options).byPage();
24
22
  }
25
23
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { UserBreak, UserClockedIn, UserClockedOut, TerminalLocation } 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
  interface UserClockIn {
6
6
  method: string;
@@ -24,26 +24,35 @@ interface UserBreakRequest {
24
24
  type RequiredPropsClockIn = 'method';
25
25
  type RequiredPropsBreak = 'method' | 'action';
26
26
 
27
- export class UsersClockInService extends Service {
27
+ export class UsersClockInService extends Service<UserClockedIn> {
28
28
  private apiPath = '/users_clocked_in';
29
29
 
30
30
  getClockedInUser(id: number): Promise<UserClockedIn>;
31
- getClockedInUser(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<UserClockedIn, any>>;
31
+ getClockedInUser(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<UserClockedIn>>;
32
32
  getClockedInUser(id: number, options: Options): Promise<UserClockedIn>;
33
33
  getClockedInUser(id: number, options?: Options) {
34
34
  return super
35
35
  .fetch<UserClockedIn>({ url: `${this.apiPath}/${id}` }, options)
36
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
36
+ .then((res) => (options?.rawResponse ? res : res.data));
37
37
  }
38
38
 
39
- async *list(options?: Options) {
39
+ list(): AsyncGenerator<UserClockedIn>;
40
+ list<F extends keyof UserClockedIn>(
41
+ options: { fields: F[] } & OptionsExtended<UserClockedIn>,
42
+ ): AsyncGenerator<Pick<UserClockedIn, F>>;
43
+ list(options?: OptionsExtended<UserClockedIn>): AsyncGenerator<UserClockedIn>;
44
+ async *list(options?: OptionsExtended<UserClockedIn>) {
40
45
  for await (const res of super.iterator<UserClockedIn>({ url: this.apiPath }, options)) {
41
46
  yield res;
42
47
  }
43
48
  }
44
49
 
45
- listAll(options?: Options): Promise<UserClockedIn[]>;
46
- async listAll(options?: Options) {
50
+ listAll(): Promise<UserClockedIn[]>;
51
+ listAll<F extends keyof UserClockedIn>(
52
+ options: { fields: F[] } & OptionsExtended<UserClockedIn>,
53
+ ): Promise<Pick<UserClockedIn, F>[]>;
54
+ listAll(options?: OptionsExtended<UserClockedIn>): Promise<UserClockedIn[]>;
55
+ async listAll(options?: OptionsExtended<UserClockedIn>) {
47
56
  const users = [] as UserClockedIn[];
48
57
  for await (const user of this.list(options)) {
49
58
  users.push(user);
@@ -51,7 +60,12 @@ export class UsersClockInService extends Service {
51
60
  return users;
52
61
  }
53
62
 
54
- listByPage(options?: Options) {
63
+ listByPage(): AsyncGenerator<AxiosResponse<UserClockedIn[]>>;
64
+ listByPage<F extends keyof UserClockedIn>(
65
+ options: { fields: F[] } & OptionsExtended<UserClockedIn>,
66
+ ): AsyncGenerator<AxiosResponse<Pick<UserClockedIn, F>[]>>;
67
+ listByPage(options?: OptionsExtended<UserClockedIn>): AsyncGenerator<AxiosResponse<UserClockedIn[]>>;
68
+ listByPage(options?: OptionsExtended<UserClockedIn>) {
55
69
  return super.iterator<UserClockedIn>({ url: this.apiPath }, options).byPage();
56
70
  }
57
71
 
@@ -59,12 +73,12 @@ export class UsersClockInService extends Service {
59
73
  clockIn(
60
74
  data: RequirementsOf<UserClockIn, RequiredPropsClockIn>,
61
75
  options: { rawResponse: true } & Options,
62
- ): Promise<AxiosResponse<UserClockedIn, any>>;
76
+ ): Promise<AxiosResponse<UserClockedIn>>;
63
77
  clockIn(data: RequirementsOf<UserClockIn, RequiredPropsClockIn>, options: Options): Promise<UserClockedIn>;
64
78
  clockIn(data: RequirementsOf<UserClockIn, RequiredPropsClockIn>, options?: Options) {
65
79
  return super
66
80
  .fetch<UserClockedIn>({ url: this.apiPath, data, method: 'POST' })
67
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
81
+ .then((res) => (options?.rawResponse ? res : res.data));
68
82
  }
69
83
 
70
84
  clockOut(id: number, data: UserClockOut): Promise<UserClockedOut>;
@@ -72,12 +86,12 @@ export class UsersClockInService extends Service {
72
86
  id: number,
73
87
  data: UserClockOut,
74
88
  options: { rawResponse: true } & Options,
75
- ): Promise<AxiosResponse<UserClockedOut, any>>;
89
+ ): Promise<AxiosResponse<UserClockedOut>>;
76
90
  clockOut(id: number, data: UserClockOut, options: Options): Promise<UserClockedOut>;
77
91
  clockOut(id: number, data: UserClockOut, options?: Options) {
78
92
  return super
79
93
  .fetch<UserClockedOut>({ url: `${this.apiPath}/${id}`, data, method: 'DELETE' })
80
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
94
+ .then((res) => (options?.rawResponse ? res : res.data));
81
95
  }
82
96
 
83
97
  startBreak(id: number, data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>): Promise<UserBreak>;
@@ -85,7 +99,7 @@ export class UsersClockInService extends Service {
85
99
  id: number,
86
100
  data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>,
87
101
  options: { rawResponse: true } & Options,
88
- ): Promise<AxiosResponse<UserBreak, any>>;
102
+ ): Promise<AxiosResponse<UserBreak>>;
89
103
  startBreak(
90
104
  id: number,
91
105
  data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>,
@@ -94,7 +108,7 @@ export class UsersClockInService extends Service {
94
108
  startBreak(id: number, data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>, options?: Options) {
95
109
  return super
96
110
  .fetch<UserBreak>({ url: `${this.apiPath}/${id}`, data, method: 'POST' })
97
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
111
+ .then((res) => (options?.rawResponse ? res : res.data));
98
112
  }
99
113
 
100
114
  endBreak(id: number, data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>): Promise<UserBreak>;
@@ -102,7 +116,7 @@ export class UsersClockInService extends Service {
102
116
  id: number,
103
117
  data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>,
104
118
  options: { rawResponse: true } & Options,
105
- ): Promise<AxiosResponse<UserBreak, any>>;
119
+ ): Promise<AxiosResponse<UserBreak>>;
106
120
  endBreak(
107
121
  id: number,
108
122
  data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>,
@@ -111,6 +125,6 @@ export class UsersClockInService extends Service {
111
125
  endBreak(id: number, data: RequirementsOf<UserBreakRequest, RequiredPropsBreak>, options?: Options) {
112
126
  return super
113
127
  .fetch<UserBreak>({ url: `${this.apiPath}/${id}`, data, method: 'POST' })
114
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
128
+ .then((res) => (options?.rawResponse ? res : res.data));
115
129
  }
116
130
  }
@@ -1,43 +1,57 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { User } 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 { UsersQueryParams } from '../interfaces/query-params/users-query-params.interface.js';
6
6
 
7
7
  type RequiredProps = 'first_name' | 'last_name';
8
8
 
9
- export class UsersService extends Service {
9
+ export class UsersService extends Service<User> {
10
10
  private apiPath = '/users';
11
11
 
12
12
  create(data: RequirementsOf<User, RequiredProps>): Promise<User>;
13
13
  create(
14
14
  data: RequirementsOf<User, RequiredProps>,
15
15
  options: { rawResponse: true } & Options,
16
- ): Promise<AxiosResponse<User, any>>;
16
+ ): Promise<AxiosResponse<User>>;
17
17
  create(data: RequirementsOf<User, RequiredProps>, options: Options): Promise<User>;
18
18
  create(data: RequirementsOf<User, RequiredProps>, options?: Options) {
19
19
  return super
20
- .fetch<User>({ url: this.apiPath, data, method: 'POST' })
21
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
20
+ .fetch<User>({ 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<User>;
25
- get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<User, any>>;
26
- get(id: number, options: Options): Promise<User>;
27
- get(id: number, options?: Options) {
25
+ get<F extends keyof User>(
26
+ id: number,
27
+ options: { fields: F[]; rawResponse: true } & OptionsExtended<User>,
28
+ ): Promise<AxiosResponse<Pick<User, F>>>;
29
+ get<F extends keyof User>(id: number, options: { fields: F[] } & OptionsExtended<User>): Promise<Pick<User, F>>;
30
+ get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<User>>;
31
+ get(id: number, options?: OptionsExtended<User>): Promise<User>;
32
+ get(id: number, options?: OptionsExtended<User>) {
28
33
  return super
29
34
  .fetch<User>({ 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: UsersQueryParams, options?: Options) {
34
- for await (const res of super.iterator<User>({ url: this.apiPath, params: query }, options)) {
35
- yield res;
36
- }
38
+ list(query?: UsersQueryParams): AsyncGenerator<User>;
39
+ list<F extends keyof User>(
40
+ query: UsersQueryParams,
41
+ options: { fields: F[] } & OptionsExtended<User>,
42
+ ): AsyncGenerator<Pick<User, F>>;
43
+ list(query?: UsersQueryParams, options?: OptionsExtended<User>): AsyncGenerator<User>;
44
+ async *list(query?: UsersQueryParams, options?: OptionsExtended<User>) {
45
+ yield* super.iterator({ url: this.apiPath, params: query }, options);
37
46
  }
38
47
 
39
- listAll(query: UsersQueryParams, options?: Options): Promise<User[]>;
40
- async listAll(query: UsersQueryParams, options?: Options) {
48
+ listAll(query?: UsersQueryParams): Promise<User[]>;
49
+ listAll<F extends keyof User>(
50
+ query: UsersQueryParams,
51
+ options: { fields: F[] } & OptionsExtended<User>,
52
+ ): Promise<Pick<User, F>[]>;
53
+ listAll(query?: UsersQueryParams, options?: OptionsExtended<User>): Promise<User[]>;
54
+ async listAll(query?: UsersQueryParams, options?: OptionsExtended<User>) {
41
55
  const users = [] as User[];
42
56
  for await (const user of this.list(query, options)) {
43
57
  users.push(user);
@@ -45,8 +59,14 @@ export class UsersService extends Service {
45
59
  return users;
46
60
  }
47
61
 
48
- listByPage(query: UsersQueryParams, options?: Options) {
49
- return super.iterator<User>({ url: this.apiPath, params: query }, options).byPage();
62
+ listByPage(query?: UsersQueryParams): AsyncGenerator<AxiosResponse<User[]>>;
63
+ listByPage<F extends keyof User>(
64
+ query: UsersQueryParams,
65
+ options: { fields: F[] } & OptionsExtended<User>,
66
+ ): AsyncGenerator<AxiosResponse<Pick<User, F>[]>>;
67
+ listByPage(query?: UsersQueryParams, options?: OptionsExtended<User>): AsyncGenerator<AxiosResponse<User[]>>;
68
+ listByPage(query?: UsersQueryParams, options?: OptionsExtended<User>) {
69
+ return super.iterator({ url: this.apiPath, params: query }, options).byPage();
50
70
  }
51
71
 
52
72
  update(id: number, data: Partial<User>): Promise<User>;
@@ -54,20 +74,23 @@ export class UsersService extends Service {
54
74
  update(id: number, data: Partial<User>, options: Options): Promise<User>;
55
75
  update(id: number, data: Partial<User>, options?: Options) {
56
76
  return super
57
- .fetch<User>({
58
- url: `${this.apiPath}/${id}`,
59
- data,
60
- method: 'POST',
61
- })
62
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
77
+ .fetch<User>(
78
+ {
79
+ url: `${this.apiPath}/${id}`,
80
+ data,
81
+ method: 'POST',
82
+ },
83
+ options,
84
+ )
85
+ .then((res) => (options?.rawResponse ? res : res.data));
63
86
  }
64
87
 
65
88
  delete(id: number): Promise<number>;
66
- delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<any, any>>;
89
+ delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
67
90
  delete(id: number, options: Options): Promise<number>;
68
91
  delete(id: number, options?: Options) {
69
92
  return super
70
- .fetch<User>({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
71
- .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));
72
95
  }
73
96
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const Version = { version: '1.1.1' };
1
+ export const Version = { version: '1.2.0' };
@@ -1,5 +0,0 @@
1
- export interface InternalQueryParams {
2
- expand?: string[];
3
- fields?: string[];
4
- limit?: number;
5
- }
@@ -1,5 +0,0 @@
1
- export interface InternalQueryParams {
2
- expand?: string[];
3
- fields?: string[];
4
- limit?: number;
5
- }
@@ -1,5 +0,0 @@
1
- export interface InternalQueryParams {
2
- expand?: string[];
3
- fields?: string[];
4
- limit?: number;
5
- }