rotacloud 1.1.2 → 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 (137) hide show
  1. package/dist/cjs/interfaces/query-params/index.d.ts +0 -1
  2. package/dist/cjs/interfaces/query-params/index.js +0 -1
  3. package/dist/cjs/services/accounts.service.d.ts +26 -7
  4. package/dist/cjs/services/accounts.service.js +10 -20
  5. package/dist/cjs/services/attendance.service.d.ts +30 -11
  6. package/dist/cjs/services/attendance.service.js +16 -26
  7. package/dist/cjs/services/auth.service.js +1 -3
  8. package/dist/cjs/services/availability.service.d.ts +3 -3
  9. package/dist/cjs/services/availability.service.js +8 -18
  10. package/dist/cjs/services/daily-budgets.service.d.ts +19 -7
  11. package/dist/cjs/services/daily-budgets.service.js +12 -22
  12. package/dist/cjs/services/daily-revenue.service.d.ts +18 -6
  13. package/dist/cjs/services/daily-revenue.service.js +11 -21
  14. package/dist/cjs/services/day-notes.service.d.ts +27 -8
  15. package/dist/cjs/services/day-notes.service.js +15 -25
  16. package/dist/cjs/services/days-off.service.d.ts +17 -5
  17. package/dist/cjs/services/days-off.service.js +13 -23
  18. package/dist/cjs/services/groups.service.d.ts +27 -8
  19. package/dist/cjs/services/groups.service.js +12 -22
  20. package/dist/cjs/services/leave-embargoes.service.d.ts +27 -8
  21. package/dist/cjs/services/leave-embargoes.service.js +16 -26
  22. package/dist/cjs/services/leave-request.service.d.ts +27 -8
  23. package/dist/cjs/services/leave-request.service.js +15 -25
  24. package/dist/cjs/services/leave.service.d.ts +28 -10
  25. package/dist/cjs/services/leave.service.js +13 -46
  26. package/dist/cjs/services/locations.service.d.ts +27 -8
  27. package/dist/cjs/services/locations.service.js +16 -26
  28. package/dist/cjs/services/pins.service.d.ts +12 -5
  29. package/dist/cjs/services/pins.service.js +1 -1
  30. package/dist/cjs/services/roles.service.d.ts +27 -8
  31. package/dist/cjs/services/roles.service.js +16 -26
  32. package/dist/cjs/services/service.d.ts +12 -3
  33. package/dist/cjs/services/service.js +1 -2
  34. package/dist/cjs/services/settings.service.d.ts +1 -1
  35. package/dist/cjs/services/settings.service.js +1 -1
  36. package/dist/cjs/services/shifts.service.d.ts +30 -11
  37. package/dist/cjs/services/shifts.service.js +21 -31
  38. package/dist/cjs/services/terminals-active.service.d.ts +20 -8
  39. package/dist/cjs/services/terminals-active.service.js +16 -26
  40. package/dist/cjs/services/terminals.service.d.ts +27 -8
  41. package/dist/cjs/services/terminals.service.js +13 -23
  42. package/dist/cjs/services/time-zone.service.d.ts +2 -2
  43. package/dist/cjs/services/time-zone.service.js +10 -20
  44. package/dist/cjs/services/toil-accruals.service.d.ts +4 -4
  45. package/dist/cjs/services/toil-accruals.service.js +12 -22
  46. package/dist/cjs/services/toil-allowance.service.d.ts +3 -3
  47. package/dist/cjs/services/toil-allowance.service.js +9 -19
  48. package/dist/cjs/services/users-clock-in.service.d.ts +22 -10
  49. package/dist/cjs/services/users-clock-in.service.js +5 -5
  50. package/dist/cjs/services/users.service.d.ts +28 -9
  51. package/dist/cjs/services/users.service.js +16 -26
  52. package/dist/cjs/version.js +1 -1
  53. package/dist/mjs/interfaces/query-params/index.d.ts +0 -1
  54. package/dist/mjs/interfaces/query-params/index.js +0 -1
  55. package/dist/mjs/services/accounts.service.d.ts +26 -7
  56. package/dist/mjs/services/accounts.service.js +2 -4
  57. package/dist/mjs/services/attendance.service.d.ts +30 -11
  58. package/dist/mjs/services/attendance.service.js +8 -10
  59. package/dist/mjs/services/auth.service.js +1 -3
  60. package/dist/mjs/services/availability.service.d.ts +3 -3
  61. package/dist/mjs/services/availability.service.js +3 -5
  62. package/dist/mjs/services/daily-budgets.service.d.ts +19 -7
  63. package/dist/mjs/services/daily-budgets.service.js +4 -6
  64. package/dist/mjs/services/daily-revenue.service.d.ts +18 -6
  65. package/dist/mjs/services/daily-revenue.service.js +3 -5
  66. package/dist/mjs/services/day-notes.service.d.ts +27 -8
  67. package/dist/mjs/services/day-notes.service.js +7 -9
  68. package/dist/mjs/services/days-off.service.d.ts +17 -5
  69. package/dist/mjs/services/days-off.service.js +5 -7
  70. package/dist/mjs/services/groups.service.d.ts +27 -8
  71. package/dist/mjs/services/groups.service.js +4 -6
  72. package/dist/mjs/services/leave-embargoes.service.d.ts +27 -8
  73. package/dist/mjs/services/leave-embargoes.service.js +8 -10
  74. package/dist/mjs/services/leave-request.service.d.ts +27 -8
  75. package/dist/mjs/services/leave-request.service.js +7 -9
  76. package/dist/mjs/services/leave.service.d.ts +28 -10
  77. package/dist/mjs/services/leave.service.js +5 -12
  78. package/dist/mjs/services/locations.service.d.ts +27 -8
  79. package/dist/mjs/services/locations.service.js +8 -10
  80. package/dist/mjs/services/pins.service.d.ts +12 -5
  81. package/dist/mjs/services/pins.service.js +1 -1
  82. package/dist/mjs/services/roles.service.d.ts +27 -8
  83. package/dist/mjs/services/roles.service.js +8 -10
  84. package/dist/mjs/services/service.d.ts +12 -3
  85. package/dist/mjs/services/service.js +0 -2
  86. package/dist/mjs/services/settings.service.d.ts +1 -1
  87. package/dist/mjs/services/settings.service.js +1 -1
  88. package/dist/mjs/services/shifts.service.d.ts +30 -11
  89. package/dist/mjs/services/shifts.service.js +13 -15
  90. package/dist/mjs/services/terminals-active.service.d.ts +20 -8
  91. package/dist/mjs/services/terminals-active.service.js +8 -10
  92. package/dist/mjs/services/terminals.service.d.ts +27 -8
  93. package/dist/mjs/services/terminals.service.js +5 -7
  94. package/dist/mjs/services/time-zone.service.d.ts +2 -2
  95. package/dist/mjs/services/time-zone.service.js +2 -4
  96. package/dist/mjs/services/toil-accruals.service.d.ts +4 -4
  97. package/dist/mjs/services/toil-accruals.service.js +4 -6
  98. package/dist/mjs/services/toil-allowance.service.d.ts +3 -3
  99. package/dist/mjs/services/toil-allowance.service.js +1 -3
  100. package/dist/mjs/services/users-clock-in.service.d.ts +22 -10
  101. package/dist/mjs/services/users-clock-in.service.js +5 -5
  102. package/dist/mjs/services/users.service.d.ts +28 -9
  103. package/dist/mjs/services/users.service.js +8 -10
  104. package/dist/mjs/version.js +1 -1
  105. package/package.json +1 -1
  106. package/src/interfaces/query-params/index.ts +0 -1
  107. package/src/services/accounts.service.ts +30 -14
  108. package/src/services/attendance.service.ts +57 -28
  109. package/src/services/auth.service.ts +1 -3
  110. package/src/services/availability.service.ts +14 -13
  111. package/src/services/daily-budgets.service.ts +41 -20
  112. package/src/services/daily-revenue.service.ts +37 -19
  113. package/src/services/day-notes.service.ts +51 -25
  114. package/src/services/days-off.service.ts +46 -25
  115. package/src/services/groups.service.ts +40 -20
  116. package/src/services/leave-embargoes.service.ts +54 -25
  117. package/src/services/leave-request.service.ts +53 -24
  118. package/src/services/leave.service.ts +41 -27
  119. package/src/services/locations.service.ts +54 -25
  120. package/src/services/pins.service.ts +11 -6
  121. package/src/services/roles.service.ts +49 -25
  122. package/src/services/service.ts +35 -9
  123. package/src/services/settings.service.ts +2 -2
  124. package/src/services/shifts.service.ts +62 -36
  125. package/src/services/terminals-active.service.ts +36 -23
  126. package/src/services/terminals.service.ts +36 -18
  127. package/src/services/time-zone.service.ts +4 -6
  128. package/src/services/toil-accruals.service.ts +9 -11
  129. package/src/services/toil-allowance.service.ts +3 -5
  130. package/src/services/users-clock-in.service.ts +30 -16
  131. package/src/services/users.service.ts +49 -26
  132. package/src/version.ts +1 -1
  133. package/dist/cjs/interfaces/query-params/internal-query-params.interface.d.ts +0 -5
  134. package/dist/cjs/interfaces/query-params/internal-query-params.interface.js +0 -2
  135. package/dist/mjs/interfaces/query-params/internal-query-params.interface.d.ts +0 -5
  136. package/dist/mjs/interfaces/query-params/internal-query-params.interface.js +0 -1
  137. package/src/interfaces/query-params/internal-query-params.interface.ts +0 -5
@@ -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
  }
@@ -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
  }
@@ -3,7 +3,7 @@ import { Service, Options } from './index.js';
3
3
 
4
4
  import { TimeZone } from '../interfaces/index.js';
5
5
 
6
- export class TimeZoneService extends Service {
6
+ export class TimeZoneService extends Service<TimeZone> {
7
7
  private apiPath = '/timezones';
8
8
 
9
9
  get(id: number): Promise<TimeZone>;
@@ -12,13 +12,11 @@ export class TimeZoneService extends Service {
12
12
  get(id: number, options?: Options) {
13
13
  return super
14
14
  .fetch<TimeZone>({ url: `${this.apiPath}/${id}` }, options)
15
- .then((res) => Promise.resolve(options?.rawResponse ? res : res.data));
15
+ .then((res) => (options?.rawResponse ? res : res.data));
16
16
  }
17
17
 
18
18
  async *list(options?: Options) {
19
- for await (const res of super.iterator<TimeZone>({ url: this.apiPath }, options)) {
20
- yield res;
21
- }
19
+ yield* super.iterator({ url: this.apiPath }, options);
22
20
  }
23
21
 
24
22
  listAll(options?: Options): Promise<TimeZone[]>;
@@ -31,6 +29,6 @@ export class TimeZoneService extends Service {
31
29
  }
32
30
 
33
31
  listByPage(options?: Options) {
34
- return super.iterator<TimeZone>({ url: this.apiPath }, options).byPage();
32
+ return super.iterator({ url: this.apiPath }, options).byPage();
35
33
  }
36
34
  }