rotacloud 1.0.40 → 1.0.41
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.
- package/dist/cjs/models/SDKError.model.d.ts +11 -0
- package/dist/cjs/models/SDKError.model.js +15 -0
- package/dist/cjs/models/index.d.ts +1 -1
- package/dist/cjs/models/index.js +1 -1
- package/dist/cjs/services/accounts.service.js +3 -2
- package/dist/cjs/services/attendance.service.js +10 -5
- package/dist/cjs/services/auth.service.js +3 -2
- package/dist/cjs/services/availability.service.js +1 -2
- package/dist/cjs/services/daily-budgets.service.js +1 -2
- package/dist/cjs/services/daily-revenue.service.js +1 -2
- package/dist/cjs/services/day-notes.service.js +10 -5
- package/dist/cjs/services/days-off.service.js +2 -3
- package/dist/cjs/services/groups.service.js +10 -5
- package/dist/cjs/services/leave-embargoes.service.js +10 -5
- package/dist/cjs/services/leave-request.service.js +10 -5
- package/dist/cjs/services/leave.service.js +10 -5
- package/dist/cjs/services/locations.service.js +10 -5
- package/dist/cjs/services/roles.service.js +10 -5
- package/dist/cjs/services/service.d.ts +2 -0
- package/dist/cjs/services/service.js +23 -1
- package/dist/cjs/services/settings.service.js +3 -2
- package/dist/cjs/services/shifts.service.d.ts +3 -3
- package/dist/cjs/services/shifts.service.js +21 -9
- package/dist/cjs/services/users.service.js +10 -5
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/models/SDKError.model.d.ts +11 -0
- package/dist/mjs/models/SDKError.model.js +10 -0
- package/dist/mjs/models/index.d.ts +1 -1
- package/dist/mjs/models/index.js +1 -1
- package/dist/mjs/services/accounts.service.js +3 -2
- package/dist/mjs/services/attendance.service.js +10 -5
- package/dist/mjs/services/auth.service.js +3 -2
- package/dist/mjs/services/availability.service.js +1 -2
- package/dist/mjs/services/daily-budgets.service.js +1 -2
- package/dist/mjs/services/daily-revenue.service.js +1 -2
- package/dist/mjs/services/day-notes.service.js +10 -5
- package/dist/mjs/services/days-off.service.js +2 -3
- package/dist/mjs/services/groups.service.js +10 -5
- package/dist/mjs/services/leave-embargoes.service.js +10 -5
- package/dist/mjs/services/leave-request.service.js +10 -5
- package/dist/mjs/services/leave.service.js +10 -5
- package/dist/mjs/services/locations.service.js +10 -5
- package/dist/mjs/services/roles.service.js +10 -5
- package/dist/mjs/services/service.d.ts +2 -0
- package/dist/mjs/services/service.js +22 -1
- package/dist/mjs/services/settings.service.js +3 -2
- package/dist/mjs/services/shifts.service.d.ts +3 -3
- package/dist/mjs/services/shifts.service.js +21 -9
- package/dist/mjs/services/users.service.js +10 -5
- package/dist/mjs/version.js +1 -1
- package/package.json +1 -1
- package/src/models/SDKError.model.ts +20 -0
- package/src/models/index.ts +1 -1
- package/src/services/accounts.service.ts +3 -5
- package/src/services/attendance.service.ts +10 -17
- package/src/services/auth.service.ts +3 -5
- package/src/services/availability.service.ts +1 -5
- package/src/services/daily-budgets.service.ts +1 -5
- package/src/services/daily-revenue.service.ts +1 -5
- package/src/services/day-notes.service.ts +10 -18
- package/src/services/days-off.service.ts +2 -10
- package/src/services/groups.service.ts +10 -18
- package/src/services/leave-embargoes.service.ts +10 -17
- package/src/services/leave-request.service.ts +10 -17
- package/src/services/leave.service.ts +11 -17
- package/src/services/locations.service.ts +11 -17
- package/src/services/roles.service.ts +11 -17
- package/src/services/service.ts +29 -2
- package/src/services/settings.service.ts +4 -5
- package/src/services/shifts.service.ts +28 -34
- package/src/services/users.service.ts +11 -17
- package/src/version.ts +1 -1
- package/dist/cjs/models/error-response.model.d.ts +0 -8
- package/dist/cjs/models/error-response.model.js +0 -13
- package/dist/mjs/models/error-response.model.d.ts +0 -8
- package/dist/mjs/models/error-response.model.js +0 -8
- package/src/models/error-response.model.ts +0 -14
|
@@ -31,17 +31,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
31
31
|
exports.ShiftsService = void 0;
|
|
32
32
|
const index_js_1 = require("./index.js");
|
|
33
33
|
const shift_model_js_1 = require("../models/shift.model.js");
|
|
34
|
-
const error_response_model_js_1 = require("../models/error-response.model.js");
|
|
35
34
|
class ShiftsService extends index_js_1.Service {
|
|
36
35
|
constructor() {
|
|
37
36
|
super(...arguments);
|
|
38
37
|
this.apiPath = '/shifts';
|
|
39
38
|
}
|
|
40
39
|
create(data, options) {
|
|
41
|
-
return super
|
|
40
|
+
return super
|
|
41
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
42
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new shift_model_js_1.Shift(res.data)));
|
|
42
43
|
}
|
|
43
44
|
get(id, options) {
|
|
44
|
-
return super
|
|
45
|
+
return super
|
|
46
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
47
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new shift_model_js_1.Shift(res.data)));
|
|
45
48
|
}
|
|
46
49
|
list(query, options) {
|
|
47
50
|
const _super = Object.create(null, {
|
|
@@ -94,19 +97,28 @@ class ShiftsService extends index_js_1.Service {
|
|
|
94
97
|
data,
|
|
95
98
|
method: 'POST',
|
|
96
99
|
})
|
|
97
|
-
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new shift_model_js_1.Shift(res.data))
|
|
100
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new shift_model_js_1.Shift(res.data)));
|
|
98
101
|
}
|
|
99
|
-
delete(
|
|
100
|
-
|
|
102
|
+
delete(ids, options) {
|
|
103
|
+
const params = typeof ids !== 'number'
|
|
104
|
+
? { url: this.apiPath, data: ids, method: 'DELETE' }
|
|
105
|
+
: { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
|
|
106
|
+
return super.fetch(params).then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
|
|
101
107
|
}
|
|
102
108
|
acknowledge(data, options) {
|
|
103
|
-
return super
|
|
109
|
+
return super
|
|
110
|
+
.fetch({ url: '/shifts_acknowledged', data, method: 'POST' })
|
|
111
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
|
|
104
112
|
}
|
|
105
113
|
publish(data, options) {
|
|
106
|
-
return super
|
|
114
|
+
return super
|
|
115
|
+
.fetch({ url: '/shifts_published', data, method: 'POST' })
|
|
116
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
|
|
107
117
|
}
|
|
108
118
|
unpublish(data, options) {
|
|
109
|
-
return super
|
|
119
|
+
return super
|
|
120
|
+
.fetch({ url: '/shifts_published', data, method: 'DELETE' })
|
|
121
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
|
|
110
122
|
}
|
|
111
123
|
}
|
|
112
124
|
exports.ShiftsService = ShiftsService;
|
|
@@ -31,17 +31,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
31
31
|
exports.UsersService = void 0;
|
|
32
32
|
const index_js_1 = require("./index.js");
|
|
33
33
|
const user_model_js_1 = require("../models/user.model.js");
|
|
34
|
-
const error_response_model_js_1 = require("../models/error-response.model.js");
|
|
35
34
|
class UsersService extends index_js_1.Service {
|
|
36
35
|
constructor() {
|
|
37
36
|
super(...arguments);
|
|
38
37
|
this.apiPath = '/users';
|
|
39
38
|
}
|
|
40
39
|
create(data, options) {
|
|
41
|
-
return super
|
|
40
|
+
return super
|
|
41
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
42
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new user_model_js_1.User(res.data)));
|
|
42
43
|
}
|
|
43
44
|
get(id, options) {
|
|
44
|
-
return super
|
|
45
|
+
return super
|
|
46
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
47
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new user_model_js_1.User(res.data)));
|
|
45
48
|
}
|
|
46
49
|
list(query, options) {
|
|
47
50
|
const _super = Object.create(null, {
|
|
@@ -94,10 +97,12 @@ class UsersService extends index_js_1.Service {
|
|
|
94
97
|
data,
|
|
95
98
|
method: 'POST',
|
|
96
99
|
})
|
|
97
|
-
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new user_model_js_1.User(res.data))
|
|
100
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new user_model_js_1.User(res.data)));
|
|
98
101
|
}
|
|
99
102
|
delete(id, options) {
|
|
100
|
-
return super
|
|
103
|
+
return super
|
|
104
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
105
|
+
.then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
exports.UsersService = UsersService;
|
package/dist/cjs/version.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface SDKErrorConfig {
|
|
2
|
+
message?: string;
|
|
3
|
+
code?: number;
|
|
4
|
+
data?: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare class SDKError extends Error {
|
|
7
|
+
readonly code?: number;
|
|
8
|
+
readonly data?: unknown;
|
|
9
|
+
name: string;
|
|
10
|
+
constructor(errorConfig: SDKErrorConfig);
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class SDKError extends Error {
|
|
2
|
+
constructor(errorConfig) {
|
|
3
|
+
super(errorConfig.message);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
Error.captureStackTrace?.(this, SDKError);
|
|
6
|
+
// optional chaining needed as is v8 specific https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#static_methods
|
|
7
|
+
this.data = errorConfig.data;
|
|
8
|
+
this.code = errorConfig.code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -9,7 +9,7 @@ export * from './day-note.model.js';
|
|
|
9
9
|
export * from './days-off-pattern.model.js';
|
|
10
10
|
export * from './days-off.model.js';
|
|
11
11
|
export * from './document.model.js';
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './SDKError.model.js';
|
|
13
13
|
export * from './group.model.js';
|
|
14
14
|
export * from './holiday-allowance-custom.model.js';
|
|
15
15
|
export * from './holiday-allowance.model.js';
|
package/dist/mjs/models/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export * from './day-note.model.js';
|
|
|
9
9
|
export * from './days-off-pattern.model.js';
|
|
10
10
|
export * from './days-off.model.js';
|
|
11
11
|
export * from './document.model.js';
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './SDKError.model.js';
|
|
13
13
|
export * from './group.model.js';
|
|
14
14
|
export * from './holiday-allowance-custom.model.js';
|
|
15
15
|
export * from './holiday-allowance.model.js';
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Account } from '../models/account.model.js';
|
|
2
2
|
import { Service } from './index.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
class AccountsService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
7
6
|
this.apiPath = '/accounts';
|
|
8
7
|
}
|
|
9
8
|
get(id, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Account(res.data)));
|
|
11
12
|
}
|
|
12
13
|
async *list(options) {
|
|
13
14
|
for await (const res of super.iterator({ url: this.apiPath }, options)) {
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { Attendance } from '../models/attendance.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class AttendanceService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
7
6
|
this.apiPath = '/attendance';
|
|
8
7
|
}
|
|
9
8
|
create(data, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Attendance(res.data)));
|
|
11
12
|
}
|
|
12
13
|
get(id, options) {
|
|
13
|
-
return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) =>
|
|
14
|
+
return super.fetch({ url: `${this.apiPath}/${id}` }, options).then((res) => {
|
|
15
|
+
return Promise.resolve(options?.rawResponse ? res : new Attendance(res.data));
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
18
|
async *list(query, options) {
|
|
16
19
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -34,9 +37,11 @@ export class AttendanceService extends Service {
|
|
|
34
37
|
data,
|
|
35
38
|
method: 'POST',
|
|
36
39
|
})
|
|
37
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new Attendance(res.data))
|
|
40
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Attendance(res.data)));
|
|
38
41
|
}
|
|
39
42
|
delete(id, options) {
|
|
40
|
-
return super
|
|
43
|
+
return super
|
|
44
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { Auth } from '../models/auth.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class AuthService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
7
6
|
this.apiPath = '/auth';
|
|
8
7
|
}
|
|
9
8
|
get(options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: this.apiPath }, options)
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Auth(res.data)));
|
|
11
12
|
}
|
|
12
13
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { Availability } from '../models/availability.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class AvailabilityService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
@@ -13,7 +12,7 @@ export class AvailabilityService extends Service {
|
|
|
13
12
|
data,
|
|
14
13
|
method: 'POST',
|
|
15
14
|
})
|
|
16
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new Availability(res.data))
|
|
15
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Availability(res.data)));
|
|
17
16
|
}
|
|
18
17
|
create(data, options) {
|
|
19
18
|
return this.update(data, options);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { DailyBudgets } from '../models/daily-budgets.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class DailyBudgetsService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
@@ -28,6 +27,6 @@ export class DailyBudgetsService extends Service {
|
|
|
28
27
|
data,
|
|
29
28
|
method: 'POST',
|
|
30
29
|
})
|
|
31
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status)
|
|
30
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
32
31
|
}
|
|
33
32
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { DailyRevenue } from '../models/daily-revenue.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class DailyRevenueService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
@@ -28,6 +27,6 @@ export class DailyRevenueService extends Service {
|
|
|
28
27
|
data,
|
|
29
28
|
method: 'POST',
|
|
30
29
|
})
|
|
31
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status)
|
|
30
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
32
31
|
}
|
|
33
32
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
3
2
|
import { DayNote } from '../models/day-note.model.js';
|
|
4
3
|
export class DayNotesService extends Service {
|
|
5
4
|
constructor() {
|
|
@@ -7,10 +6,14 @@ export class DayNotesService extends Service {
|
|
|
7
6
|
this.apiPath = '/day_notes';
|
|
8
7
|
}
|
|
9
8
|
create(data, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new DayNote(res.data)));
|
|
11
12
|
}
|
|
12
13
|
get(id, options) {
|
|
13
|
-
return super
|
|
14
|
+
return super
|
|
15
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
16
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new DayNote(res.data)));
|
|
14
17
|
}
|
|
15
18
|
async *list(query, options) {
|
|
16
19
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -34,9 +37,11 @@ export class DayNotesService extends Service {
|
|
|
34
37
|
data,
|
|
35
38
|
method: 'POST',
|
|
36
39
|
})
|
|
37
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new DayNote(res.data))
|
|
40
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new DayNote(res.data)));
|
|
38
41
|
}
|
|
39
42
|
delete(id, options) {
|
|
40
|
-
return super
|
|
43
|
+
return super
|
|
44
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
3
2
|
import { DaysOff } from '../models/days-off.model.js';
|
|
4
3
|
export class DaysOffService extends Service {
|
|
5
4
|
constructor() {
|
|
@@ -16,7 +15,7 @@ export class DaysOffService extends Service {
|
|
|
16
15
|
},
|
|
17
16
|
method: 'POST',
|
|
18
17
|
})
|
|
19
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status)
|
|
18
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
20
19
|
}
|
|
21
20
|
async *list(query, options) {
|
|
22
21
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -43,6 +42,6 @@ export class DaysOffService extends Service {
|
|
|
43
42
|
users,
|
|
44
43
|
},
|
|
45
44
|
})
|
|
46
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status)
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
3
2
|
import { Group } from '../models/group.model.js';
|
|
4
3
|
export class GroupsService extends Service {
|
|
5
4
|
constructor() {
|
|
@@ -7,10 +6,14 @@ export class GroupsService extends Service {
|
|
|
7
6
|
this.apiPath = '/groups';
|
|
8
7
|
}
|
|
9
8
|
create(data, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)));
|
|
11
12
|
}
|
|
12
13
|
get(id, options) {
|
|
13
|
-
return super
|
|
14
|
+
return super
|
|
15
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
16
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)));
|
|
14
17
|
}
|
|
15
18
|
async *list(query, options) {
|
|
16
19
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -34,9 +37,11 @@ export class GroupsService extends Service {
|
|
|
34
37
|
data,
|
|
35
38
|
method: 'POST',
|
|
36
39
|
})
|
|
37
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data))
|
|
40
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Group(res.data)));
|
|
38
41
|
}
|
|
39
42
|
delete(id, options) {
|
|
40
|
-
return super
|
|
43
|
+
return super
|
|
44
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { LeaveEmbargo } from '../models/leave-embargo.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class LeaveEmbargoesService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
7
6
|
this.apiPath = '/leave_embargoes';
|
|
8
7
|
}
|
|
9
8
|
create(data, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)));
|
|
11
12
|
}
|
|
12
13
|
get(id, options) {
|
|
13
|
-
return super
|
|
14
|
+
return super
|
|
15
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
16
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)));
|
|
14
17
|
}
|
|
15
18
|
async *list(query, options) {
|
|
16
19
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -34,9 +37,11 @@ export class LeaveEmbargoesService extends Service {
|
|
|
34
37
|
data,
|
|
35
38
|
method: 'POST',
|
|
36
39
|
})
|
|
37
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data))
|
|
40
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveEmbargo(res.data)));
|
|
38
41
|
}
|
|
39
42
|
delete(id, options) {
|
|
40
|
-
return super
|
|
43
|
+
return super
|
|
44
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
3
2
|
import { LeaveRequest } from '../models/leave-request.model.js';
|
|
4
3
|
export class LeaveRequestService extends Service {
|
|
5
4
|
constructor() {
|
|
@@ -7,10 +6,14 @@ export class LeaveRequestService extends Service {
|
|
|
7
6
|
this.apiPath = '/leave_requests';
|
|
8
7
|
}
|
|
9
8
|
create(data, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)));
|
|
11
12
|
}
|
|
12
13
|
get(id, options) {
|
|
13
|
-
return super
|
|
14
|
+
return super
|
|
15
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
16
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)));
|
|
14
17
|
}
|
|
15
18
|
async *list(query, options) {
|
|
16
19
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -34,9 +37,11 @@ export class LeaveRequestService extends Service {
|
|
|
34
37
|
data,
|
|
35
38
|
method: 'POST',
|
|
36
39
|
})
|
|
37
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data))
|
|
40
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new LeaveRequest(res.data)));
|
|
38
41
|
}
|
|
39
42
|
delete(id, options) {
|
|
40
|
-
return super
|
|
43
|
+
return super
|
|
44
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { Leave } from '../models/leave.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
import { LeaveType } from '../models/leave-type.model.js';
|
|
5
4
|
export class LeaveService extends Service {
|
|
6
5
|
constructor() {
|
|
@@ -8,10 +7,14 @@ export class LeaveService extends Service {
|
|
|
8
7
|
this.apiPath = '/leave';
|
|
9
8
|
}
|
|
10
9
|
create(data, options) {
|
|
11
|
-
return super
|
|
10
|
+
return super
|
|
11
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
12
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : [...res.data.map((leave) => new Leave(leave))]));
|
|
12
13
|
}
|
|
13
14
|
get(id, options) {
|
|
14
|
-
return super
|
|
15
|
+
return super
|
|
16
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
17
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Leave(res.data)));
|
|
15
18
|
}
|
|
16
19
|
async *list(query, options) {
|
|
17
20
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -40,9 +43,11 @@ export class LeaveService extends Service {
|
|
|
40
43
|
data,
|
|
41
44
|
method: 'POST',
|
|
42
45
|
})
|
|
43
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new Leave(res.data))
|
|
46
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Leave(res.data)));
|
|
44
47
|
}
|
|
45
48
|
delete(id, options) {
|
|
46
|
-
return super
|
|
49
|
+
return super
|
|
50
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
51
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
47
52
|
}
|
|
48
53
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { Location } from '../models/location.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class LocationsService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
7
6
|
this.apiPath = '/locations';
|
|
8
7
|
}
|
|
9
8
|
create(data, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: `${this.apiPath}`, data, method: 'POST' })
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)));
|
|
11
12
|
}
|
|
12
13
|
get(id, options) {
|
|
13
|
-
return super
|
|
14
|
+
return super
|
|
15
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
16
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)));
|
|
14
17
|
}
|
|
15
18
|
async *list(query, options) {
|
|
16
19
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -34,9 +37,11 @@ export class LocationsService extends Service {
|
|
|
34
37
|
data,
|
|
35
38
|
method: 'POST',
|
|
36
39
|
})
|
|
37
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data))
|
|
40
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Location(res.data)));
|
|
38
41
|
}
|
|
39
42
|
delete(id, options) {
|
|
40
|
-
return super
|
|
43
|
+
return super
|
|
44
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Service } from './index.js';
|
|
2
2
|
import { Role } from '../models/role.model.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
export class RolesService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
7
6
|
this.apiPath = '/roles';
|
|
8
7
|
}
|
|
9
8
|
create(data, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: this.apiPath, data, method: 'POST' })
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)));
|
|
11
12
|
}
|
|
12
13
|
get(id, options) {
|
|
13
|
-
return super
|
|
14
|
+
return super
|
|
15
|
+
.fetch({ url: `${this.apiPath}/${id}` }, options)
|
|
16
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)));
|
|
14
17
|
}
|
|
15
18
|
async *list(query, options) {
|
|
16
19
|
for await (const res of super.iterator({ url: this.apiPath, params: query }, options)) {
|
|
@@ -34,9 +37,11 @@ export class RolesService extends Service {
|
|
|
34
37
|
data,
|
|
35
38
|
method: 'POST',
|
|
36
39
|
})
|
|
37
|
-
.then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data))
|
|
40
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Role(res.data)));
|
|
38
41
|
}
|
|
39
42
|
delete(id, options) {
|
|
40
|
-
return super
|
|
43
|
+
return super
|
|
44
|
+
.fetch({ url: `${this.apiPath}/${id}`, method: 'DELETE' })
|
|
45
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : res.status));
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -25,6 +25,8 @@ export interface Options {
|
|
|
25
25
|
}
|
|
26
26
|
export declare abstract class Service<ApiResponse = any> {
|
|
27
27
|
protected client: AxiosInstance;
|
|
28
|
+
private initialiseAxios;
|
|
29
|
+
private parseClientError;
|
|
28
30
|
isLeaveRequest(endpoint?: string): boolean;
|
|
29
31
|
private buildQueryStr;
|
|
30
32
|
private parsePageLinkHeader;
|
|
@@ -2,6 +2,7 @@ import axios from 'axios';
|
|
|
2
2
|
import axiosRetry from 'axios-retry';
|
|
3
3
|
import { RotaCloud } from '../rotacloud.js';
|
|
4
4
|
import { Version } from '../version.js';
|
|
5
|
+
import { SDKError } from '../models/SDKError.model.js';
|
|
5
6
|
export var RetryStrategy;
|
|
6
7
|
(function (RetryStrategy) {
|
|
7
8
|
RetryStrategy["Exponential"] = "expo";
|
|
@@ -22,7 +23,27 @@ const DEFAULT_RETRY_STRATEGY_OPTIONS = {
|
|
|
22
23
|
};
|
|
23
24
|
export class Service {
|
|
24
25
|
constructor() {
|
|
25
|
-
this.client =
|
|
26
|
+
this.client = this.initialiseAxios();
|
|
27
|
+
}
|
|
28
|
+
initialiseAxios() {
|
|
29
|
+
const client = axios.create();
|
|
30
|
+
client.interceptors.response.use((response) => response, (error) => {
|
|
31
|
+
const parsedError = this.parseClientError(error);
|
|
32
|
+
return Promise.reject(parsedError);
|
|
33
|
+
});
|
|
34
|
+
return client;
|
|
35
|
+
}
|
|
36
|
+
parseClientError(error) {
|
|
37
|
+
if (!axios.isAxiosError(error))
|
|
38
|
+
return error;
|
|
39
|
+
const axiosErrorLocation = error.response || error.request;
|
|
40
|
+
const apiErrorMessage = axiosErrorLocation.data?.error;
|
|
41
|
+
const sdkErrorParams = {
|
|
42
|
+
code: axiosErrorLocation.status,
|
|
43
|
+
message: apiErrorMessage || error.message,
|
|
44
|
+
data: axiosErrorLocation.data,
|
|
45
|
+
};
|
|
46
|
+
return new SDKError(sdkErrorParams);
|
|
26
47
|
}
|
|
27
48
|
isLeaveRequest(endpoint) {
|
|
28
49
|
return endpoint === '/leave_requests';
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Settings } from '../models/settings.model.js';
|
|
2
2
|
import { Service } from './index.js';
|
|
3
|
-
import { ErrorResponse } from '../models/error-response.model.js';
|
|
4
3
|
class SettingsService extends Service {
|
|
5
4
|
constructor() {
|
|
6
5
|
super(...arguments);
|
|
7
6
|
this.apiPath = '/settings';
|
|
8
7
|
}
|
|
9
8
|
get(query, options) {
|
|
10
|
-
return super
|
|
9
|
+
return super
|
|
10
|
+
.fetch({ url: `${this.apiPath}`, params: query }, options)
|
|
11
|
+
.then((res) => Promise.resolve(options?.rawResponse ? res : new Settings(res.data)));
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
export { SettingsService };
|