rotacloud 1.0.53 → 1.0.56

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 (67) hide show
  1. package/.eslintrc.json +2 -2
  2. package/.github/workflows/check.yml +36 -0
  3. package/.github/workflows/publish.yml +10 -8
  4. package/dist/cjs/interfaces/index.js +5 -1
  5. package/dist/cjs/interfaces/query-params/index.js +5 -1
  6. package/dist/cjs/models/index.js +5 -1
  7. package/dist/cjs/rotacloud.js +5 -1
  8. package/dist/cjs/services/accounts.service.js +12 -8
  9. package/dist/cjs/services/attendance.service.d.ts +1 -1
  10. package/dist/cjs/services/attendance.service.js +13 -11
  11. package/dist/cjs/services/availability.service.js +11 -11
  12. package/dist/cjs/services/daily-budgets.service.js +12 -8
  13. package/dist/cjs/services/daily-revenue.service.js +12 -8
  14. package/dist/cjs/services/day-notes.service.js +12 -8
  15. package/dist/cjs/services/days-off.service.js +12 -8
  16. package/dist/cjs/services/groups.service.d.ts +1 -1
  17. package/dist/cjs/services/groups.service.js +12 -8
  18. package/dist/cjs/services/index.js +5 -1
  19. package/dist/cjs/services/leave-embargoes.service.d.ts +1 -1
  20. package/dist/cjs/services/leave-embargoes.service.js +12 -8
  21. package/dist/cjs/services/leave-request.service.d.ts +1 -1
  22. package/dist/cjs/services/leave-request.service.js +12 -8
  23. package/dist/cjs/services/leave.service.d.ts +1 -1
  24. package/dist/cjs/services/leave.service.js +18 -12
  25. package/dist/cjs/services/locations.service.d.ts +1 -1
  26. package/dist/cjs/services/locations.service.js +12 -8
  27. package/dist/cjs/services/roles.service.d.ts +1 -1
  28. package/dist/cjs/services/roles.service.js +12 -8
  29. package/dist/cjs/services/service.d.ts +9 -11
  30. package/dist/cjs/services/service.js +33 -55
  31. package/dist/cjs/services/shifts.service.d.ts +27 -5
  32. package/dist/cjs/services/shifts.service.js +40 -14
  33. package/dist/cjs/services/terminals-active.service.js +12 -8
  34. package/dist/cjs/services/terminals.service.d.ts +1 -1
  35. package/dist/cjs/services/terminals.service.js +12 -8
  36. package/dist/cjs/services/toil-accruals.service.d.ts +1 -1
  37. package/dist/cjs/services/toil-accruals.service.js +12 -8
  38. package/dist/cjs/services/toil-allowance.service.js +12 -8
  39. package/dist/cjs/services/users-clock-in.service.d.ts +2 -2
  40. package/dist/cjs/services/users-clock-in.service.js +12 -8
  41. package/dist/cjs/services/users.service.d.ts +1 -1
  42. package/dist/cjs/services/users.service.js +12 -8
  43. package/dist/cjs/version.js +1 -1
  44. package/dist/mjs/services/attendance.service.d.ts +1 -1
  45. package/dist/mjs/services/attendance.service.js +1 -3
  46. package/dist/mjs/services/availability.service.js +5 -7
  47. package/dist/mjs/services/groups.service.d.ts +1 -1
  48. package/dist/mjs/services/leave-embargoes.service.d.ts +1 -1
  49. package/dist/mjs/services/leave-request.service.d.ts +1 -1
  50. package/dist/mjs/services/leave.service.d.ts +1 -1
  51. package/dist/mjs/services/locations.service.d.ts +1 -1
  52. package/dist/mjs/services/roles.service.d.ts +1 -1
  53. package/dist/mjs/services/service.d.ts +9 -11
  54. package/dist/mjs/services/service.js +34 -57
  55. package/dist/mjs/services/shifts.service.d.ts +27 -5
  56. package/dist/mjs/services/shifts.service.js +28 -6
  57. package/dist/mjs/services/terminals.service.d.ts +1 -1
  58. package/dist/mjs/services/toil-accruals.service.d.ts +1 -1
  59. package/dist/mjs/services/users-clock-in.service.d.ts +2 -2
  60. package/dist/mjs/services/users.service.d.ts +1 -1
  61. package/dist/mjs/version.js +1 -1
  62. package/package.json +16 -16
  63. package/src/services/attendance.service.ts +1 -3
  64. package/src/services/availability.service.ts +2 -4
  65. package/src/services/service.ts +51 -82
  66. package/src/services/shifts.service.ts +45 -14
  67. package/src/version.ts +1 -1
@@ -51,36 +51,40 @@ class LeaveEmbargoesService extends index_js_1.Service {
51
51
  iterator: { get: () => super.iterator }
52
52
  });
53
53
  return __asyncGenerator(this, arguments, function* list_1() {
54
- var e_1, _a;
54
+ var _a, e_1, _b, _c;
55
55
  try {
56
- for (var _b = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
57
- const res = _c.value;
56
+ for (var _d = true, _e = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
57
+ _c = _f.value;
58
+ _d = false;
59
+ const res = _c;
58
60
  yield yield __await(new leave_embargo_model_js_1.LeaveEmbargo(res));
59
61
  }
60
62
  }
61
63
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
62
64
  finally {
63
65
  try {
64
- if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
66
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
65
67
  }
66
68
  finally { if (e_1) throw e_1.error; }
67
69
  }
68
70
  });
69
71
  }
70
72
  listAll(query, options) {
71
- var e_2, _a;
73
+ var _a, e_2, _b, _c;
72
74
  return __awaiter(this, void 0, void 0, function* () {
73
75
  const leave = [];
74
76
  try {
75
- for (var _b = __asyncValues(this.list(query, options)), _c; _c = yield _b.next(), !_c.done;) {
76
- const leaveEmbargoRecord = _c.value;
77
+ for (var _d = true, _e = __asyncValues(this.list(query, options)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
78
+ _c = _f.value;
79
+ _d = false;
80
+ const leaveEmbargoRecord = _c;
77
81
  leave.push(leaveEmbargoRecord);
78
82
  }
79
83
  }
80
84
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
81
85
  finally {
82
86
  try {
83
- if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
87
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
84
88
  }
85
89
  finally { if (e_2) throw e_2.error; }
86
90
  }
@@ -3,7 +3,7 @@ import { ApiLeaveRequest } from '../interfaces/index.js';
3
3
  import { Service, Options, RequirementsOf } from './index.js';
4
4
  import { LeaveRequestsQueryParams } from '../interfaces/query-params/leave-requests-query-params.interface.js';
5
5
  import { LeaveRequest } from '../models/leave-request.model.js';
6
- declare type RequiredProps = 'start_date' | 'end_date' | 'type' | 'user';
6
+ type RequiredProps = 'start_date' | 'end_date' | 'type' | 'user';
7
7
  export declare class LeaveRequestService extends Service {
8
8
  private apiPath;
9
9
  create(data: RequirementsOf<ApiLeaveRequest, RequiredProps>): Promise<LeaveRequest>;
@@ -55,36 +55,40 @@ class LeaveRequestService extends index_js_1.Service {
55
55
  iterator: { get: () => super.iterator }
56
56
  });
57
57
  return __asyncGenerator(this, arguments, function* list_1() {
58
- var e_1, _a;
58
+ var _a, e_1, _b, _c;
59
59
  try {
60
- for (var _b = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
61
- const res = _c.value;
60
+ for (var _d = true, _e = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
61
+ _c = _f.value;
62
+ _d = false;
63
+ const res = _c;
62
64
  yield yield __await(new leave_request_model_js_1.LeaveRequest(res));
63
65
  }
64
66
  }
65
67
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
66
68
  finally {
67
69
  try {
68
- if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
70
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
69
71
  }
70
72
  finally { if (e_1) throw e_1.error; }
71
73
  }
72
74
  });
73
75
  }
74
76
  listAll(query, options) {
75
- var e_2, _a;
77
+ var _a, e_2, _b, _c;
76
78
  return __awaiter(this, void 0, void 0, function* () {
77
79
  const leave = [];
78
80
  try {
79
- for (var _b = __asyncValues(this.list(query, options)), _c; _c = yield _b.next(), !_c.done;) {
80
- const leaveRequestRecord = _c.value;
81
+ for (var _d = true, _e = __asyncValues(this.list(query, options)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
82
+ _c = _f.value;
83
+ _d = false;
84
+ const leaveRequestRecord = _c;
81
85
  leave.push(leaveRequestRecord);
82
86
  }
83
87
  }
84
88
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
85
89
  finally {
86
90
  try {
87
- if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
91
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
88
92
  }
89
93
  finally { if (e_2) throw e_2.error; }
90
94
  }
@@ -4,7 +4,7 @@ import { Service, Options, RequirementsOf } from './index.js';
4
4
  import { Leave } from '../models/leave.model.js';
5
5
  import { LeaveQueryParams } from '../interfaces/query-params/leave-query-params.interface.js';
6
6
  import { LeaveType } from '../models/leave-type.model.js';
7
- declare type RequiredProps = 'users' | 'type' | 'start_date' | 'end_date';
7
+ type RequiredProps = 'users' | 'type' | 'start_date' | 'end_date';
8
8
  export declare class LeaveService extends Service {
9
9
  private apiPath;
10
10
  create(data: RequirementsOf<ApiLeave, RequiredProps>): Promise<Leave[]>;
@@ -52,36 +52,40 @@ class LeaveService extends index_js_1.Service {
52
52
  iterator: { get: () => super.iterator }
53
53
  });
54
54
  return __asyncGenerator(this, arguments, function* list_1() {
55
- var e_1, _a;
55
+ var _a, e_1, _b, _c;
56
56
  try {
57
- for (var _b = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
58
- const res = _c.value;
57
+ for (var _d = true, _e = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
58
+ _c = _f.value;
59
+ _d = false;
60
+ const res = _c;
59
61
  yield yield __await(new leave_model_js_1.Leave(res));
60
62
  }
61
63
  }
62
64
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
63
65
  finally {
64
66
  try {
65
- if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
67
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
66
68
  }
67
69
  finally { if (e_1) throw e_1.error; }
68
70
  }
69
71
  });
70
72
  }
71
73
  listAll(query, options) {
72
- var e_2, _a;
74
+ var _a, e_2, _b, _c;
73
75
  return __awaiter(this, void 0, void 0, function* () {
74
76
  const leave = [];
75
77
  try {
76
- for (var _b = __asyncValues(this.list(query, options)), _c; _c = yield _b.next(), !_c.done;) {
77
- const leaveRecord = _c.value;
78
+ for (var _d = true, _e = __asyncValues(this.list(query, options)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
79
+ _c = _f.value;
80
+ _d = false;
81
+ const leaveRecord = _c;
78
82
  leave.push(leaveRecord);
79
83
  }
80
84
  }
81
85
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
82
86
  finally {
83
87
  try {
84
- if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
88
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
85
89
  }
86
90
  finally { if (e_2) throw e_2.error; }
87
91
  }
@@ -93,17 +97,19 @@ class LeaveService extends index_js_1.Service {
93
97
  iterator: { get: () => super.iterator }
94
98
  });
95
99
  return __asyncGenerator(this, arguments, function* listLeaveTypes_1() {
96
- var e_3, _a;
100
+ var _a, e_3, _b, _c;
97
101
  try {
98
- for (var _b = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
99
- const res = _c.value;
102
+ for (var _d = true, _e = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
103
+ _c = _f.value;
104
+ _d = false;
105
+ const res = _c;
100
106
  yield yield __await(new leave_type_model_js_1.LeaveType(res));
101
107
  }
102
108
  }
103
109
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
104
110
  finally {
105
111
  try {
106
- if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
112
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
107
113
  }
108
114
  finally { if (e_3) throw e_3.error; }
109
115
  }
@@ -3,7 +3,7 @@ import { ApiLocation } from '../interfaces/index.js';
3
3
  import { Service, Options, RequirementsOf } from './index.js';
4
4
  import { Location } from '../models/location.model.js';
5
5
  import { LocationsQueryParams } from '../interfaces/query-params/locations-query-params.interface.js';
6
- declare type RequiredProps = 'name';
6
+ type RequiredProps = 'name';
7
7
  export declare class LocationsService extends Service {
8
8
  private apiPath;
9
9
  create(data: RequirementsOf<ApiLocation, RequiredProps>): Promise<Location>;
@@ -51,36 +51,40 @@ class LocationsService extends index_js_1.Service {
51
51
  iterator: { get: () => super.iterator }
52
52
  });
53
53
  return __asyncGenerator(this, arguments, function* list_1() {
54
- var e_1, _a;
54
+ var _a, e_1, _b, _c;
55
55
  try {
56
- for (var _b = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
57
- const res = _c.value;
56
+ for (var _d = true, _e = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
57
+ _c = _f.value;
58
+ _d = false;
59
+ const res = _c;
58
60
  yield yield __await(new location_model_js_1.Location(res));
59
61
  }
60
62
  }
61
63
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
62
64
  finally {
63
65
  try {
64
- if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
66
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
65
67
  }
66
68
  finally { if (e_1) throw e_1.error; }
67
69
  }
68
70
  });
69
71
  }
70
72
  listAll(query, options) {
71
- var e_2, _a;
73
+ var _a, e_2, _b, _c;
72
74
  return __awaiter(this, void 0, void 0, function* () {
73
75
  const locations = [];
74
76
  try {
75
- for (var _b = __asyncValues(this.list(query, options)), _c; _c = yield _b.next(), !_c.done;) {
76
- const location = _c.value;
77
+ for (var _d = true, _e = __asyncValues(this.list(query, options)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
78
+ _c = _f.value;
79
+ _d = false;
80
+ const location = _c;
77
81
  locations.push(location);
78
82
  }
79
83
  }
80
84
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
81
85
  finally {
82
86
  try {
83
- if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
87
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
84
88
  }
85
89
  finally { if (e_2) throw e_2.error; }
86
90
  }
@@ -3,7 +3,7 @@ import { ApiRole } from '../interfaces/index.js';
3
3
  import { Service, Options, RequirementsOf } from './index.js';
4
4
  import { Role } from '../models/role.model.js';
5
5
  import { RolesQueryParams } from '../interfaces/query-params/roles-query-params.interface.js';
6
- declare type RequiredProps = 'name';
6
+ type RequiredProps = 'name';
7
7
  export declare class RolesService extends Service {
8
8
  private apiPath;
9
9
  create(data: RequirementsOf<ApiRole, RequiredProps>): Promise<Role>;
@@ -51,36 +51,40 @@ class RolesService extends index_js_1.Service {
51
51
  iterator: { get: () => super.iterator }
52
52
  });
53
53
  return __asyncGenerator(this, arguments, function* list_1() {
54
- var e_1, _a;
54
+ var _a, e_1, _b, _c;
55
55
  try {
56
- for (var _b = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
57
- const res = _c.value;
56
+ for (var _d = true, _e = __asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
57
+ _c = _f.value;
58
+ _d = false;
59
+ const res = _c;
58
60
  yield yield __await(new role_model_js_1.Role(res));
59
61
  }
60
62
  }
61
63
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
62
64
  finally {
63
65
  try {
64
- if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
66
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
65
67
  }
66
68
  finally { if (e_1) throw e_1.error; }
67
69
  }
68
70
  });
69
71
  }
70
72
  listAll(query, options) {
71
- var e_2, _a;
73
+ var _a, e_2, _b, _c;
72
74
  return __awaiter(this, void 0, void 0, function* () {
73
75
  const roles = [];
74
76
  try {
75
- for (var _b = __asyncValues(this.list(query, options)), _c; _c = yield _b.next(), !_c.done;) {
76
- const role = _c.value;
77
+ for (var _d = true, _e = __asyncValues(this.list(query, options)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
78
+ _c = _f.value;
79
+ _d = false;
80
+ const role = _c;
77
81
  roles.push(role);
78
82
  }
79
83
  }
80
84
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
81
85
  finally {
82
86
  try {
83
- if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
87
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
84
88
  }
85
89
  finally { if (e_2) throw e_2.error; }
86
90
  }
@@ -1,10 +1,10 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
- export declare type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
2
+ export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
3
3
  export declare enum RetryStrategy {
4
4
  Exponential = "expo",
5
5
  Static = "static"
6
6
  }
7
- export declare type RetryOptions = {
7
+ export type RetryOptions = {
8
8
  /** Use exponential back-off */
9
9
  exponential?: false;
10
10
  /** The maximum number of retries before erroring */
@@ -29,16 +29,14 @@ export declare abstract class Service<ApiResponse = any> {
29
29
  protected client: AxiosInstance;
30
30
  private initialiseAxios;
31
31
  private parseClientError;
32
- isLeaveRequest(endpoint?: string): boolean;
33
- private buildQueryStr;
34
- private parsePageLinkHeader;
35
- fetch<T = ApiResponse>(httpOptions: AxiosRequestConfig, options?: Options): Promise<AxiosResponse<T>>;
36
- private listFetch;
32
+ private isLeaveRequest;
33
+ private buildQueryParams;
34
+ fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig, options?: Options): Promise<AxiosResponse<T>>;
35
+ /** Iterates through every page for a potentially paginated request */
36
+ private fetchPages;
37
37
  private listResponses;
38
- iterator<T = ApiResponse>(reqObject: AxiosRequestConfig<T[]>, options?: Options): {
39
- [Symbol.asyncIterator](): {
40
- next(): Promise<IteratorResult<T, void>>;
41
- };
38
+ iterator<T = ApiResponse>(reqConfig: AxiosRequestConfig<T[]>, options?: Options): {
39
+ [Symbol.asyncIterator]: () => AsyncGenerator<Awaited<T>, void, undefined>;
42
40
  byPage: () => AsyncGenerator<AxiosResponse<T[], any>, any, unknown>;
43
41
  };
44
42
  }
@@ -21,7 +21,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
21
21
  var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
22
22
  var i, p;
23
23
  return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
24
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
24
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
25
25
  };
26
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -37,7 +37,7 @@ var RetryStrategy;
37
37
  (function (RetryStrategy) {
38
38
  RetryStrategy["Exponential"] = "expo";
39
39
  RetryStrategy["Static"] = "static";
40
- })(RetryStrategy = exports.RetryStrategy || (exports.RetryStrategy = {}));
40
+ })(RetryStrategy || (exports.RetryStrategy = RetryStrategy = {}));
41
41
  const DEFAULT_RETRIES = 3;
42
42
  const DEFAULT_RETRY_DELAY = 2000;
43
43
  const DEFAULT_RETRY_STRATEGY_OPTIONS = {
@@ -79,10 +79,11 @@ class Service {
79
79
  isLeaveRequest(endpoint) {
80
80
  return endpoint === '/leave_requests';
81
81
  }
82
- buildQueryStr(queryParams) {
83
- if (!queryParams)
84
- return '';
85
- const reducedParams = Object.entries(queryParams).reduce((params, [key, val]) => {
82
+ buildQueryParams(options, extraParams) {
83
+ const queryParams = Object.assign(Object.assign({ expand: options === null || options === void 0 ? void 0 : options.expand, fields: options === null || options === void 0 ? void 0 : options.fields, limit: options === null || options === void 0 ? void 0 : options.limit, offset: options === null || options === void 0 ? void 0 : options.offset, dry_run: options === null || options === void 0 ? void 0 : options.dryRun }, extraParams), {
84
+ // NOTE: Should not overridable so must come after spread of params
85
+ exclude_link_header: true });
86
+ const reducedParams = Object.entries(queryParams !== null && queryParams !== void 0 ? queryParams : {}).reduce((params, [key, val]) => {
86
87
  if (val !== undefined && val !== '') {
87
88
  if (Array.isArray(val))
88
89
  params.push(...val.map((item) => [`${key}[]`, String(item)]));
@@ -91,18 +92,9 @@ class Service {
91
92
  }
92
93
  return params;
93
94
  }, []);
94
- return new URLSearchParams(reducedParams).toString();
95
+ return new URLSearchParams(reducedParams);
95
96
  }
96
- parsePageLinkHeader(linkHeader) {
97
- var _a, _b;
98
- const pageData = {};
99
- for (const link of linkHeader.split(',')) {
100
- const { rel, url } = (_b = (_a = link.match(/<(?<url>.*)>; rel="(?<rel>\w*)"/)) === null || _a === void 0 ? void 0 : _a.groups) !== null && _b !== void 0 ? _b : {};
101
- pageData[rel] = url;
102
- }
103
- return pageData;
104
- }
105
- fetch(httpOptions, options) {
97
+ fetch(reqConfig, options) {
106
98
  const headers = {
107
99
  Authorization: `Bearer ${rotacloud_js_1.RotaCloud.config.apiKey}`,
108
100
  'SDK-Version': version_js_1.Version.version,
@@ -120,9 +112,9 @@ class Service {
120
112
  }
121
113
  else {
122
114
  // need to convert user field in payload to a header for creating leave_requests when using an API key
123
- this.isLeaveRequest(httpOptions.url) ? (headers.User = `${httpOptions.data.user}`) : undefined;
115
+ this.isLeaveRequest(reqConfig.url) ? (headers.User = `${reqConfig.data.user}`) : undefined;
124
116
  }
125
- const reqObject = Object.assign(Object.assign({}, httpOptions), { baseURL: rotacloud_js_1.RotaCloud.config.baseUri, headers, params: Object.assign({ expand: options === null || options === void 0 ? void 0 : options.expand, fields: options === null || options === void 0 ? void 0 : options.fields, limit: options === null || options === void 0 ? void 0 : options.limit, offset: options === null || options === void 0 ? void 0 : options.offset, dry_run: options === null || options === void 0 ? void 0 : options.dryRun }, httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.params), paramsSerializer: this.buildQueryStr });
117
+ const finalReqConfig = Object.assign(Object.assign({}, reqConfig), { baseURL: rotacloud_js_1.RotaCloud.config.baseUri, headers, params: this.buildQueryParams(options, reqConfig.params) });
126
118
  if (rotacloud_js_1.RotaCloud.config.retry) {
127
119
  const retryConfig = typeof rotacloud_js_1.RotaCloud.config.retry === 'string'
128
120
  ? DEFAULT_RETRY_STRATEGY_OPTIONS[rotacloud_js_1.RotaCloud.config.retry]
@@ -137,60 +129,46 @@ class Service {
137
129
  },
138
130
  });
139
131
  }
140
- return this.client.request(reqObject);
132
+ return this.client.request(finalReqConfig);
141
133
  }
142
- listFetch(reqObject, options) {
143
- var _a;
144
- return __asyncGenerator(this, arguments, function* listFetch_1() {
145
- let pageRequestObject = reqObject;
146
- let currentPageUrl = pageRequestObject.url;
147
- let pageRemaining = true;
148
- while (pageRemaining) {
149
- const res = yield __await(this.fetch(pageRequestObject, options));
150
- const pageLinkMap = this.parsePageLinkHeader((_a = res.headers.link) !== null && _a !== void 0 ? _a : '');
151
- pageRemaining = Boolean(pageLinkMap.next);
152
- // NOTE: query params including paging options are included in the "next" link
153
- pageRequestObject = { url: pageLinkMap.next };
154
- yield yield __await(res);
155
- // Failsafe incase the page does not change
156
- if (currentPageUrl === pageRequestObject.url) {
157
- throw new Error('Next page link did not change');
158
- }
159
- currentPageUrl = pageRequestObject.url;
134
+ /** Iterates through every page for a potentially paginated request */
135
+ fetchPages(reqConfig, options) {
136
+ return __asyncGenerator(this, arguments, function* fetchPages_1() {
137
+ const fallbackLimit = 20;
138
+ const res = yield __await(this.fetch(reqConfig, options));
139
+ yield yield __await(res);
140
+ const limit = Number(res.headers['x-limit']) || fallbackLimit;
141
+ const entityCount = Number(res.headers['x-total-count']) || 0;
142
+ const requestOffset = Number(res.headers['x-offset']) || 0;
143
+ for (let offset = requestOffset + limit; offset < entityCount; offset += limit) {
144
+ yield yield __await(this.fetch(reqConfig, Object.assign(Object.assign({}, options), { offset })));
160
145
  }
161
146
  });
162
147
  }
163
- listResponses(reqObject, options) {
148
+ listResponses(reqConfig, options) {
164
149
  return __asyncGenerator(this, arguments, function* listResponses_1() {
165
- var e_1, _a;
150
+ var _a, e_1, _b, _c;
166
151
  try {
167
- for (var _b = __asyncValues(this.listFetch(reqObject, options)), _c; _c = yield __await(_b.next()), !_c.done;) {
168
- const res = _c.value;
152
+ for (var _d = true, _e = __asyncValues(this.fetchPages(reqConfig, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
153
+ _c = _f.value;
154
+ _d = false;
155
+ const res = _c;
169
156
  yield __await(yield* __asyncDelegator(__asyncValues(res.data)));
170
157
  }
171
158
  }
172
159
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
173
160
  finally {
174
161
  try {
175
- if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
162
+ if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
176
163
  }
177
164
  finally { if (e_1) throw e_1.error; }
178
165
  }
179
166
  });
180
167
  }
181
- iterator(reqObject, options) {
182
- const iterator = this.listResponses(reqObject, options);
168
+ iterator(reqConfig, options) {
183
169
  return {
184
- [Symbol.asyncIterator]() {
185
- return {
186
- next() {
187
- return iterator.next();
188
- },
189
- };
190
- },
191
- byPage: () => {
192
- return this.listFetch(reqObject, options);
193
- },
170
+ [Symbol.asyncIterator]: () => this.listResponses(reqConfig, options),
171
+ byPage: () => this.fetchPages(reqConfig, options),
194
172
  };
195
173
  }
196
174
  }
@@ -3,7 +3,7 @@ import { ApiShift } from '../interfaces/index.js';
3
3
  import { Service, Options, RequirementsOf } from './index.js';
4
4
  import { Shift } from '../models/shift.model.js';
5
5
  import { ShiftsQueryParams } from '../interfaces/query-params/shifts-query-params.interface.js';
6
- declare type RequiredProps = 'end_time' | 'start_time' | 'location';
6
+ type RequiredProps = 'end_time' | 'start_time' | 'location';
7
7
  export declare class ShiftsService extends Service {
8
8
  private apiPath;
9
9
  create(data: RequirementsOf<ApiShift, RequiredProps>): Promise<Shift>;
@@ -19,11 +19,33 @@ export declare class ShiftsService extends Service {
19
19
  list(query: ShiftsQueryParams, options?: Options): AsyncGenerator<Shift, void, unknown>;
20
20
  listAll(query: ShiftsQueryParams, options?: Options): Promise<Shift[]>;
21
21
  listByPage(query: ShiftsQueryParams, options?: Options): AsyncGenerator<AxiosResponse<ApiShift[], any>, any, unknown>;
22
- update(id: number, data: Partial<ApiShift>): Promise<Shift>;
23
- update(id: number, data: Partial<ApiShift>, options: {
22
+ update(shift: RequirementsOf<ApiShift, 'id'>): Promise<Shift>;
23
+ update(shift: RequirementsOf<ApiShift, 'id'>, options: {
24
24
  rawResponse: true;
25
- } & Options): Promise<AxiosResponse<ApiShift, any>>;
26
- update(id: number, data: Partial<ApiShift>, options: Options): Promise<Shift>;
25
+ } & Options): Promise<AxiosResponse<ApiShift>>;
26
+ update(shift: RequirementsOf<ApiShift, 'id'>, options: Options): Promise<Shift>;
27
+ update(shifts: RequirementsOf<ApiShift, 'id'>[]): Promise<{
28
+ success: Shift[];
29
+ failed: {
30
+ id: number;
31
+ error: string;
32
+ }[];
33
+ }>;
34
+ update(shift: RequirementsOf<ApiShift, 'id'>, options: Options): Promise<Shift>;
35
+ update(shifts: RequirementsOf<ApiShift, 'id'>[], options: {
36
+ rawResponse: true;
37
+ } & Options): Promise<AxiosResponse<{
38
+ code: number;
39
+ data?: ApiShift;
40
+ error?: string;
41
+ }[]>>;
42
+ update(shifts: RequirementsOf<ApiShift, 'id'>[], options: Options): Promise<{
43
+ success: Shift[];
44
+ failed: {
45
+ id: number;
46
+ error: string;
47
+ }[];
48
+ }>;
27
49
  delete(ids: number | number[]): Promise<number>;
28
50
  delete(ids: number | number[], options: {
29
51
  rawResponse: true;