rotacloud 1.2.1 → 1.4.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 (47) hide show
  1. package/dist/cjs/interfaces/sdk-config.interface.d.ts +14 -0
  2. package/dist/cjs/interfaces/user.interface.d.ts +1 -0
  3. package/dist/cjs/interfaces/users-clocked-in.interface.d.ts +2 -1
  4. package/dist/cjs/rotacloud.d.ts +1 -0
  5. package/dist/cjs/rotacloud.js +72 -25
  6. package/dist/cjs/services/accounts.service.js +3 -2
  7. package/dist/cjs/services/attendance.service.js +3 -2
  8. package/dist/cjs/services/availability.service.js +3 -2
  9. package/dist/cjs/services/daily-budgets.service.js +3 -2
  10. package/dist/cjs/services/daily-revenue.service.js +3 -2
  11. package/dist/cjs/services/day-notes.service.js +3 -2
  12. package/dist/cjs/services/days-off.service.js +3 -2
  13. package/dist/cjs/services/groups.service.js +3 -2
  14. package/dist/cjs/services/leave-embargoes.service.js +3 -2
  15. package/dist/cjs/services/leave-request.service.js +3 -2
  16. package/dist/cjs/services/leave.service.js +3 -2
  17. package/dist/cjs/services/locations.service.js +3 -2
  18. package/dist/cjs/services/roles.service.js +3 -2
  19. package/dist/cjs/services/service.d.ts +1 -2
  20. package/dist/cjs/services/service.js +5 -27
  21. package/dist/cjs/services/shifts.service.js +3 -2
  22. package/dist/cjs/services/terminals-active.service.js +3 -2
  23. package/dist/cjs/services/terminals.service.js +3 -2
  24. package/dist/cjs/services/time-zone.service.js +3 -2
  25. package/dist/cjs/services/toil-accruals.service.js +3 -2
  26. package/dist/cjs/services/toil-allowance.service.js +3 -2
  27. package/dist/cjs/services/users-clock-in.service.d.ts +2 -2
  28. package/dist/cjs/services/users-clock-in.service.js +3 -2
  29. package/dist/cjs/services/users.service.js +3 -2
  30. package/dist/cjs/version.js +1 -1
  31. package/dist/mjs/interfaces/sdk-config.interface.d.ts +14 -0
  32. package/dist/mjs/interfaces/user.interface.d.ts +1 -0
  33. package/dist/mjs/interfaces/users-clocked-in.interface.d.ts +2 -1
  34. package/dist/mjs/rotacloud.d.ts +1 -0
  35. package/dist/mjs/rotacloud.js +58 -25
  36. package/dist/mjs/services/service.d.ts +1 -2
  37. package/dist/mjs/services/service.js +2 -24
  38. package/dist/mjs/services/users-clock-in.service.d.ts +2 -2
  39. package/dist/mjs/version.js +1 -1
  40. package/package.json +5 -5
  41. package/src/interfaces/sdk-config.interface.ts +20 -0
  42. package/src/interfaces/user.interface.ts +1 -0
  43. package/src/interfaces/users-clocked-in.interface.ts +2 -1
  44. package/src/rotacloud.ts +66 -27
  45. package/src/services/service.ts +2 -29
  46. package/src/services/users-clock-in.service.ts +2 -2
  47. package/src/version.ts +1 -1
@@ -1,9 +1,22 @@
1
+ import { AxiosInterceptorManager, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
1
2
  import { RetryOptions, RetryStrategy } from '../services/service.js';
3
+ type RequestInterceptor = Parameters<AxiosInterceptorManager<InternalAxiosRequestConfig>['use']>;
4
+ type ResponseInterceptor = Parameters<AxiosInterceptorManager<AxiosResponse>['use']>;
2
5
  export interface SDKBase {
3
6
  baseUri?: string;
4
7
  accountId?: number;
5
8
  userId?: number;
6
9
  retry?: false | `${RetryStrategy}` | RetryOptions;
10
+ interceptors?: {
11
+ request?: (RequestInterceptor[0] | {
12
+ success?: RequestInterceptor[0];
13
+ error?: RequestInterceptor[1];
14
+ })[];
15
+ response?: (ResponseInterceptor[0] | {
16
+ success?: ResponseInterceptor[0];
17
+ error?: ResponseInterceptor[1];
18
+ })[];
19
+ };
7
20
  [key: string]: unknown;
8
21
  }
9
22
  export interface SDKBearerAuth extends SDKBase {
@@ -15,3 +28,4 @@ export interface SDKBasicAuth extends SDKBase {
15
28
  basicAuth: string;
16
29
  }
17
30
  export type SDKConfig = SDKBasicAuth | SDKBearerAuth;
31
+ export {};
@@ -37,6 +37,7 @@ export interface User {
37
37
  notes: string | null;
38
38
  pin: string | null;
39
39
  salaried_cost_location: number | null;
40
+ permissions: string[] | null;
40
41
  }
41
42
  export interface UserBreak {
42
43
  start_time: number;
@@ -1,4 +1,4 @@
1
- import { Shift, TerminalLocation } from '../interfaces/index.js';
1
+ import { Shift, TerminalLocation, UserBreak } from '../interfaces/index.js';
2
2
  export interface UserClockedIn {
3
3
  user: number;
4
4
  location: number;
@@ -10,4 +10,5 @@ export interface UserClockedIn {
10
10
  in_location: TerminalLocation;
11
11
  in_device: string | null;
12
12
  in_terminal: number | null;
13
+ breaks_clocked: UserBreak[];
13
14
  }
@@ -3,6 +3,7 @@ import { SDKConfig } from './interfaces/index.js';
3
3
  import { PinsService } from './services/pins.service.js';
4
4
  export declare class RotaCloud {
5
5
  static config: SDKConfig;
6
+ private client;
6
7
  defaultAPIURI: string | undefined;
7
8
  accounts: AccountsService;
8
9
  attendance: AttendanceService;
@@ -10,52 +10,99 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
13
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
27
  };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
17
29
  exports.RetryStrategy = exports.RotaCloud = void 0;
30
+ const axios_1 = __importStar(require("axios"));
18
31
  const index_js_1 = require("./services/index.js");
19
32
  const pins_service_js_1 = require("./services/pins.service.js");
33
+ const index_js_2 = require("./models/index.js");
20
34
  const DEFAULT_CONFIG = {
21
35
  baseUri: 'https://api.rotacloud.com/v1',
22
36
  retry: index_js_1.RetryStrategy.Exponential,
23
37
  };
38
+ function parseClientError(error) {
39
+ var _a;
40
+ const axiosErrorLocation = error.response || error.request;
41
+ const apiErrorMessage = (_a = axiosErrorLocation.data) === null || _a === void 0 ? void 0 : _a.error;
42
+ return new index_js_2.SDKError({
43
+ code: axiosErrorLocation.status,
44
+ message: apiErrorMessage || error.message,
45
+ data: axiosErrorLocation.data,
46
+ });
47
+ }
24
48
  class RotaCloud {
25
49
  constructor(config) {
50
+ this.client = axios_1.default.create();
26
51
  this.defaultAPIURI = DEFAULT_CONFIG.baseUri;
27
- this.accounts = new index_js_1.AccountsService();
28
- this.attendance = new index_js_1.AttendanceService();
29
- this.auth = new index_js_1.AuthService();
30
- this.availability = new index_js_1.AvailabilityService();
31
- this.dailyBudgets = new index_js_1.DailyBudgetsService();
32
- this.dailyRevenue = new index_js_1.DailyRevenueService();
33
- this.dayNotes = new index_js_1.DayNotesService();
34
- this.daysOff = new index_js_1.DaysOffService();
35
- this.group = new index_js_1.GroupsService();
36
- this.leaveEmbargoes = new index_js_1.LeaveEmbargoesService();
37
- this.leaveRequests = new index_js_1.LeaveRequestService();
38
- this.leaveTypes = new index_js_1.LeaveTypesService();
39
- this.leave = new index_js_1.LeaveService();
40
- this.locations = new index_js_1.LocationsService();
41
- this.pins = new pins_service_js_1.PinsService();
42
- this.roles = new index_js_1.RolesService();
43
- this.settings = new index_js_1.SettingsService();
44
- this.shifts = new index_js_1.ShiftsService();
45
- this.terminals = new index_js_1.TerminalsService();
46
- this.terminalsActive = new index_js_1.TerminalsActiveService();
47
- this.timeZone = new index_js_1.TimeZoneService();
48
- this.toilAccruals = new index_js_1.ToilAccrualsService();
49
- this.toilAllowance = new index_js_1.ToilAllowanceService();
50
- this.usersClockInService = new index_js_1.UsersClockInService();
51
- this.users = new index_js_1.UsersService();
52
+ this.accounts = new index_js_1.AccountsService(this.client);
53
+ this.attendance = new index_js_1.AttendanceService(this.client);
54
+ this.auth = new index_js_1.AuthService(this.client);
55
+ this.availability = new index_js_1.AvailabilityService(this.client);
56
+ this.dailyBudgets = new index_js_1.DailyBudgetsService(this.client);
57
+ this.dailyRevenue = new index_js_1.DailyRevenueService(this.client);
58
+ this.dayNotes = new index_js_1.DayNotesService(this.client);
59
+ this.daysOff = new index_js_1.DaysOffService(this.client);
60
+ this.group = new index_js_1.GroupsService(this.client);
61
+ this.leaveEmbargoes = new index_js_1.LeaveEmbargoesService(this.client);
62
+ this.leaveRequests = new index_js_1.LeaveRequestService(this.client);
63
+ this.leaveTypes = new index_js_1.LeaveTypesService(this.client);
64
+ this.leave = new index_js_1.LeaveService(this.client);
65
+ this.locations = new index_js_1.LocationsService(this.client);
66
+ this.pins = new pins_service_js_1.PinsService(this.client);
67
+ this.roles = new index_js_1.RolesService(this.client);
68
+ this.settings = new index_js_1.SettingsService(this.client);
69
+ this.shifts = new index_js_1.ShiftsService(this.client);
70
+ this.terminals = new index_js_1.TerminalsService(this.client);
71
+ this.terminalsActive = new index_js_1.TerminalsActiveService(this.client);
72
+ this.timeZone = new index_js_1.TimeZoneService(this.client);
73
+ this.toilAccruals = new index_js_1.ToilAccrualsService(this.client);
74
+ this.toilAllowance = new index_js_1.ToilAllowanceService(this.client);
75
+ this.usersClockInService = new index_js_1.UsersClockInService(this.client);
76
+ this.users = new index_js_1.UsersService(this.client);
52
77
  this.config = Object.assign(Object.assign({}, DEFAULT_CONFIG), config);
53
78
  }
54
79
  get config() {
55
80
  return RotaCloud.config;
56
81
  }
57
82
  set config(configVal) {
83
+ var _a, _b, _c, _d;
58
84
  RotaCloud.config = configVal;
85
+ this.client.interceptors.request.clear();
86
+ this.client.interceptors.response.clear();
87
+ this.client.interceptors.response.use((response) => response, (error) => {
88
+ let parsedError = error;
89
+ if ((0, axios_1.isAxiosError)(error)) {
90
+ parsedError = parseClientError(error);
91
+ }
92
+ return Promise.reject(parsedError);
93
+ });
94
+ for (const requestInterceptor of (_b = (_a = this.config.interceptors) === null || _a === void 0 ? void 0 : _a.request) !== null && _b !== void 0 ? _b : []) {
95
+ const callbacks = typeof requestInterceptor === 'function'
96
+ ? [requestInterceptor]
97
+ : [requestInterceptor === null || requestInterceptor === void 0 ? void 0 : requestInterceptor.success, requestInterceptor === null || requestInterceptor === void 0 ? void 0 : requestInterceptor.error];
98
+ this.client.interceptors.request.use(...callbacks);
99
+ }
100
+ for (const responseInterceptor of (_d = (_c = this.config.interceptors) === null || _c === void 0 ? void 0 : _c.response) !== null && _d !== void 0 ? _d : []) {
101
+ const callbacks = typeof responseInterceptor === 'function'
102
+ ? [responseInterceptor]
103
+ : [responseInterceptor === null || responseInterceptor === void 0 ? void 0 : responseInterceptor.success, responseInterceptor === null || responseInterceptor === void 0 ? void 0 : responseInterceptor.error];
104
+ this.client.interceptors.response.use(...callbacks);
105
+ }
59
106
  }
60
107
  }
61
108
  exports.RotaCloud = RotaCloud;
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -15,8 +15,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
15
15
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
16
16
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
17
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
18
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
19
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
18
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
19
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
20
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
20
21
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
21
22
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
22
23
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -28,8 +28,7 @@ export type OptionsExtended<T = unknown> = Options & {
28
28
  };
29
29
  export declare abstract class Service<ApiResponse = any> {
30
30
  protected client: AxiosInstance;
31
- private initialiseAxios;
32
- private parseClientError;
31
+ constructor(client: AxiosInstance);
33
32
  private isLeaveRequest;
34
33
  private buildQueryParams;
35
34
  fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig): Promise<AxiosResponse<T>>;
@@ -3,8 +3,9 @@ var __await = (this && this.__await) || function (v) { return this instanceof __
3
3
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
4
4
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5
5
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
6
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
7
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
6
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
7
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
8
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
8
9
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
9
10
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
10
11
  function fulfill(value) { resume("next", value); }
@@ -28,11 +29,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
29
  };
29
30
  Object.defineProperty(exports, "__esModule", { value: true });
30
31
  exports.Service = exports.RetryStrategy = void 0;
31
- const axios_1 = __importDefault(require("axios"));
32
32
  const axios_retry_1 = __importDefault(require("axios-retry"));
33
33
  const rotacloud_js_1 = require("../rotacloud.js");
34
34
  const version_js_1 = require("../version.js");
35
- const SDKError_model_js_1 = require("../models/SDKError.model.js");
36
35
  var RetryStrategy;
37
36
  (function (RetryStrategy) {
38
37
  RetryStrategy["Exponential"] = "expo";
@@ -52,29 +51,8 @@ const DEFAULT_RETRY_STRATEGY_OPTIONS = {
52
51
  },
53
52
  };
54
53
  class Service {
55
- constructor() {
56
- this.client = this.initialiseAxios();
57
- }
58
- initialiseAxios() {
59
- const client = axios_1.default.create();
60
- client.interceptors.response.use((response) => response, (error) => {
61
- const parsedError = this.parseClientError(error);
62
- return Promise.reject(parsedError);
63
- });
64
- return client;
65
- }
66
- parseClientError(error) {
67
- var _a;
68
- if (!axios_1.default.isAxiosError(error))
69
- return error;
70
- const axiosErrorLocation = error.response || error.request;
71
- const apiErrorMessage = (_a = axiosErrorLocation.data) === null || _a === void 0 ? void 0 : _a.error;
72
- const sdkErrorParams = {
73
- code: axiosErrorLocation.status,
74
- message: apiErrorMessage || error.message,
75
- data: axiosErrorLocation.data,
76
- };
77
- return new SDKError_model_js_1.SDKError(sdkErrorParams);
54
+ constructor(client) {
55
+ this.client = client;
78
56
  }
79
57
  isLeaveRequest(endpoint) {
80
58
  return endpoint === '/leave_requests';
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -4,10 +4,10 @@ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
4
  interface UserClockIn {
5
5
  method: string;
6
6
  shift: number;
7
- terminal: number;
7
+ terminal?: number;
8
8
  user: number;
9
9
  photo?: string;
10
- location: TerminalLocation;
10
+ location?: TerminalLocation;
11
11
  }
12
12
  interface UserClockOut extends Omit<UserClockIn, 'user' | 'shift'> {
13
13
  }
@@ -19,8 +19,9 @@ var __await = (this && this.__await) || function (v) { return this instanceof __
19
19
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
20
20
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
21
21
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
22
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
23
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
22
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
23
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
24
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
24
25
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
25
26
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
26
27
  function fulfill(value) { resume("next", value); }
@@ -24,8 +24,9 @@ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
24
24
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
25
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
26
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
27
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
28
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
27
+ return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
28
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
29
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
30
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
31
  function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
32
  function fulfill(value) { resume("next", value); }
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Version = void 0;
4
- exports.Version = { version: '1.2.1' };
4
+ exports.Version = { version: '1.4.0' };
@@ -1,9 +1,22 @@
1
+ import { AxiosInterceptorManager, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
1
2
  import { RetryOptions, RetryStrategy } from '../services/service.js';
3
+ type RequestInterceptor = Parameters<AxiosInterceptorManager<InternalAxiosRequestConfig>['use']>;
4
+ type ResponseInterceptor = Parameters<AxiosInterceptorManager<AxiosResponse>['use']>;
2
5
  export interface SDKBase {
3
6
  baseUri?: string;
4
7
  accountId?: number;
5
8
  userId?: number;
6
9
  retry?: false | `${RetryStrategy}` | RetryOptions;
10
+ interceptors?: {
11
+ request?: (RequestInterceptor[0] | {
12
+ success?: RequestInterceptor[0];
13
+ error?: RequestInterceptor[1];
14
+ })[];
15
+ response?: (ResponseInterceptor[0] | {
16
+ success?: ResponseInterceptor[0];
17
+ error?: ResponseInterceptor[1];
18
+ })[];
19
+ };
7
20
  [key: string]: unknown;
8
21
  }
9
22
  export interface SDKBearerAuth extends SDKBase {
@@ -15,3 +28,4 @@ export interface SDKBasicAuth extends SDKBase {
15
28
  basicAuth: string;
16
29
  }
17
30
  export type SDKConfig = SDKBasicAuth | SDKBearerAuth;
31
+ export {};
@@ -37,6 +37,7 @@ export interface User {
37
37
  notes: string | null;
38
38
  pin: string | null;
39
39
  salaried_cost_location: number | null;
40
+ permissions: string[] | null;
40
41
  }
41
42
  export interface UserBreak {
42
43
  start_time: number;
@@ -1,4 +1,4 @@
1
- import { Shift, TerminalLocation } from '../interfaces/index.js';
1
+ import { Shift, TerminalLocation, UserBreak } from '../interfaces/index.js';
2
2
  export interface UserClockedIn {
3
3
  user: number;
4
4
  location: number;
@@ -10,4 +10,5 @@ export interface UserClockedIn {
10
10
  in_location: TerminalLocation;
11
11
  in_device: string | null;
12
12
  in_terminal: number | null;
13
+ breaks_clocked: UserBreak[];
13
14
  }
@@ -3,6 +3,7 @@ import { SDKConfig } from './interfaces/index.js';
3
3
  import { PinsService } from './services/pins.service.js';
4
4
  export declare class RotaCloud {
5
5
  static config: SDKConfig;
6
+ private client;
6
7
  defaultAPIURI: string | undefined;
7
8
  accounts: AccountsService;
8
9
  attendance: AttendanceService;
@@ -1,37 +1,49 @@
1
+ import axios, { isAxiosError } from 'axios';
1
2
  import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DayNotesService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveTypesService, LeaveService, LocationsService, RetryStrategy, RolesService, SettingsService, ShiftsService, TerminalsService, TerminalsActiveService, TimeZoneService, ToilAccrualsService, ToilAllowanceService, UsersService, UsersClockInService, } from './services/index.js';
2
3
  import { PinsService } from './services/pins.service.js';
4
+ import { SDKError } from './models/index.js';
3
5
  const DEFAULT_CONFIG = {
4
6
  baseUri: 'https://api.rotacloud.com/v1',
5
7
  retry: RetryStrategy.Exponential,
6
8
  };
9
+ function parseClientError(error) {
10
+ const axiosErrorLocation = error.response || error.request;
11
+ const apiErrorMessage = axiosErrorLocation.data?.error;
12
+ return new SDKError({
13
+ code: axiosErrorLocation.status,
14
+ message: apiErrorMessage || error.message,
15
+ data: axiosErrorLocation.data,
16
+ });
17
+ }
7
18
  export class RotaCloud {
8
19
  constructor(config) {
20
+ this.client = axios.create();
9
21
  this.defaultAPIURI = DEFAULT_CONFIG.baseUri;
10
- this.accounts = new AccountsService();
11
- this.attendance = new AttendanceService();
12
- this.auth = new AuthService();
13
- this.availability = new AvailabilityService();
14
- this.dailyBudgets = new DailyBudgetsService();
15
- this.dailyRevenue = new DailyRevenueService();
16
- this.dayNotes = new DayNotesService();
17
- this.daysOff = new DaysOffService();
18
- this.group = new GroupsService();
19
- this.leaveEmbargoes = new LeaveEmbargoesService();
20
- this.leaveRequests = new LeaveRequestService();
21
- this.leaveTypes = new LeaveTypesService();
22
- this.leave = new LeaveService();
23
- this.locations = new LocationsService();
24
- this.pins = new PinsService();
25
- this.roles = new RolesService();
26
- this.settings = new SettingsService();
27
- this.shifts = new ShiftsService();
28
- this.terminals = new TerminalsService();
29
- this.terminalsActive = new TerminalsActiveService();
30
- this.timeZone = new TimeZoneService();
31
- this.toilAccruals = new ToilAccrualsService();
32
- this.toilAllowance = new ToilAllowanceService();
33
- this.usersClockInService = new UsersClockInService();
34
- this.users = new UsersService();
22
+ this.accounts = new AccountsService(this.client);
23
+ this.attendance = new AttendanceService(this.client);
24
+ this.auth = new AuthService(this.client);
25
+ this.availability = new AvailabilityService(this.client);
26
+ this.dailyBudgets = new DailyBudgetsService(this.client);
27
+ this.dailyRevenue = new DailyRevenueService(this.client);
28
+ this.dayNotes = new DayNotesService(this.client);
29
+ this.daysOff = new DaysOffService(this.client);
30
+ this.group = new GroupsService(this.client);
31
+ this.leaveEmbargoes = new LeaveEmbargoesService(this.client);
32
+ this.leaveRequests = new LeaveRequestService(this.client);
33
+ this.leaveTypes = new LeaveTypesService(this.client);
34
+ this.leave = new LeaveService(this.client);
35
+ this.locations = new LocationsService(this.client);
36
+ this.pins = new PinsService(this.client);
37
+ this.roles = new RolesService(this.client);
38
+ this.settings = new SettingsService(this.client);
39
+ this.shifts = new ShiftsService(this.client);
40
+ this.terminals = new TerminalsService(this.client);
41
+ this.terminalsActive = new TerminalsActiveService(this.client);
42
+ this.timeZone = new TimeZoneService(this.client);
43
+ this.toilAccruals = new ToilAccrualsService(this.client);
44
+ this.toilAllowance = new ToilAllowanceService(this.client);
45
+ this.usersClockInService = new UsersClockInService(this.client);
46
+ this.users = new UsersService(this.client);
35
47
  this.config = {
36
48
  ...DEFAULT_CONFIG,
37
49
  ...config,
@@ -42,6 +54,27 @@ export class RotaCloud {
42
54
  }
43
55
  set config(configVal) {
44
56
  RotaCloud.config = configVal;
57
+ this.client.interceptors.request.clear();
58
+ this.client.interceptors.response.clear();
59
+ this.client.interceptors.response.use((response) => response, (error) => {
60
+ let parsedError = error;
61
+ if (isAxiosError(error)) {
62
+ parsedError = parseClientError(error);
63
+ }
64
+ return Promise.reject(parsedError);
65
+ });
66
+ for (const requestInterceptor of this.config.interceptors?.request ?? []) {
67
+ const callbacks = typeof requestInterceptor === 'function'
68
+ ? [requestInterceptor]
69
+ : [requestInterceptor?.success, requestInterceptor?.error];
70
+ this.client.interceptors.request.use(...callbacks);
71
+ }
72
+ for (const responseInterceptor of this.config.interceptors?.response ?? []) {
73
+ const callbacks = typeof responseInterceptor === 'function'
74
+ ? [responseInterceptor]
75
+ : [responseInterceptor?.success, responseInterceptor?.error];
76
+ this.client.interceptors.response.use(...callbacks);
77
+ }
45
78
  }
46
79
  }
47
80
  export { RetryStrategy } from './services/service.js';
@@ -28,8 +28,7 @@ export type OptionsExtended<T = unknown> = Options & {
28
28
  };
29
29
  export declare abstract class Service<ApiResponse = any> {
30
30
  protected client: AxiosInstance;
31
- private initialiseAxios;
32
- private parseClientError;
31
+ constructor(client: AxiosInstance);
33
32
  private isLeaveRequest;
34
33
  private buildQueryParams;
35
34
  fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig): Promise<AxiosResponse<T>>;
@@ -1,8 +1,6 @@
1
- import axios from 'axios';
2
1
  import axiosRetry from 'axios-retry';
3
2
  import { RotaCloud } from '../rotacloud.js';
4
3
  import { Version } from '../version.js';
5
- import { SDKError } from '../models/SDKError.model.js';
6
4
  export var RetryStrategy;
7
5
  (function (RetryStrategy) {
8
6
  RetryStrategy["Exponential"] = "expo";
@@ -22,28 +20,8 @@ const DEFAULT_RETRY_STRATEGY_OPTIONS = {
22
20
  },
23
21
  };
24
22
  export class Service {
25
- constructor() {
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);
23
+ constructor(client) {
24
+ this.client = client;
47
25
  }
48
26
  isLeaveRequest(endpoint) {
49
27
  return endpoint === '/leave_requests';
@@ -4,10 +4,10 @@ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
4
  interface UserClockIn {
5
5
  method: string;
6
6
  shift: number;
7
- terminal: number;
7
+ terminal?: number;
8
8
  user: number;
9
9
  photo?: string;
10
- location: TerminalLocation;
10
+ location?: TerminalLocation;
11
11
  }
12
12
  interface UserClockOut extends Omit<UserClockIn, 'user' | 'shift'> {
13
13
  }
@@ -1 +1 @@
1
- export const Version = { version: '1.2.1' };
1
+ export const Version = { version: '1.4.0' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rotacloud",
3
- "version": "1.2.1",
3
+ "version": "1.4.0",
4
4
  "description": "The RotaCloud SDK for the RotaCloud API",
5
5
  "engines": {
6
6
  "node": ">=16.10.0"
@@ -41,12 +41,12 @@
41
41
  "eslint-config-airbnb-typescript": "^17.1.0",
42
42
  "eslint-config-prettier": "^9.0.0",
43
43
  "eslint-plugin-import": "^2.28.0",
44
- "prettier": "~3.0.1",
45
- "typescript": "^5.1.6"
44
+ "prettier": "~3.2.2",
45
+ "typescript": "^5.3.3"
46
46
  },
47
47
  "dependencies": {
48
48
  "@types/node": "^16.11.7",
49
- "axios": "^1.4.0",
50
- "axios-retry": "^3.6.0"
49
+ "axios": "^1.6.5",
50
+ "axios-retry": "^4.0.0"
51
51
  }
52
52
  }
@@ -1,10 +1,30 @@
1
+ import { AxiosInterceptorManager, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
1
2
  import { RetryOptions, RetryStrategy } from '../services/service.js';
2
3
 
4
+ type RequestInterceptor = Parameters<AxiosInterceptorManager<InternalAxiosRequestConfig>['use']>;
5
+ type ResponseInterceptor = Parameters<AxiosInterceptorManager<AxiosResponse>['use']>;
6
+
3
7
  export interface SDKBase {
4
8
  baseUri?: string;
5
9
  accountId?: number;
6
10
  userId?: number;
7
11
  retry?: false | `${RetryStrategy}` | RetryOptions;
12
+ interceptors?: {
13
+ request?: (
14
+ | RequestInterceptor[0]
15
+ | {
16
+ success?: RequestInterceptor[0];
17
+ error?: RequestInterceptor[1];
18
+ }
19
+ )[];
20
+ response?: (
21
+ | ResponseInterceptor[0]
22
+ | {
23
+ success?: ResponseInterceptor[0];
24
+ error?: ResponseInterceptor[1];
25
+ }
26
+ )[];
27
+ };
8
28
  [key: string]: unknown;
9
29
  }
10
30
 
@@ -38,6 +38,7 @@ export interface User {
38
38
  notes: string | null;
39
39
  pin: string | null;
40
40
  salaried_cost_location: number | null;
41
+ permissions: string[] | null;
41
42
  }
42
43
 
43
44
  export interface UserBreak {
@@ -1,4 +1,4 @@
1
- import { Shift, TerminalLocation } from '../interfaces/index.js';
1
+ import { Shift, TerminalLocation, UserBreak } from '../interfaces/index.js';
2
2
 
3
3
  export interface UserClockedIn {
4
4
  user: number;
@@ -11,4 +11,5 @@ export interface UserClockedIn {
11
11
  in_location: TerminalLocation;
12
12
  in_device: string | null;
13
13
  in_terminal: number | null;
14
+ breaks_clocked: UserBreak[];
14
15
  }
package/src/rotacloud.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import axios, { AxiosError, isAxiosError } from 'axios';
1
2
  import {
2
3
  AccountsService,
3
4
  AttendanceService,
@@ -27,41 +28,53 @@ import {
27
28
  } from './services/index.js';
28
29
  import { SDKBase, SDKConfig } from './interfaces/index.js';
29
30
  import { PinsService } from './services/pins.service.js';
31
+ import { SDKError } from './models/index.js';
30
32
 
31
33
  const DEFAULT_CONFIG: Partial<SDKBase> = {
32
34
  baseUri: 'https://api.rotacloud.com/v1',
33
35
  retry: RetryStrategy.Exponential,
34
36
  };
35
37
 
38
+ function parseClientError(error: AxiosError): SDKError {
39
+ const axiosErrorLocation = error.response || error.request;
40
+ const apiErrorMessage = axiosErrorLocation.data?.error;
41
+ return new SDKError({
42
+ code: axiosErrorLocation.status,
43
+ message: apiErrorMessage || error.message,
44
+ data: axiosErrorLocation.data,
45
+ });
46
+ }
47
+
36
48
  export class RotaCloud {
37
- public static config: SDKConfig;
49
+ static config: SDKConfig;
50
+ private client = axios.create();
38
51
 
39
- public defaultAPIURI = DEFAULT_CONFIG.baseUri;
40
- public accounts = new AccountsService();
41
- public attendance = new AttendanceService();
42
- public auth = new AuthService();
43
- public availability = new AvailabilityService();
44
- public dailyBudgets = new DailyBudgetsService();
45
- public dailyRevenue = new DailyRevenueService();
46
- public dayNotes = new DayNotesService();
47
- public daysOff = new DaysOffService();
48
- public group = new GroupsService();
49
- public leaveEmbargoes = new LeaveEmbargoesService();
50
- public leaveRequests = new LeaveRequestService();
51
- public leaveTypes = new LeaveTypesService();
52
- public leave = new LeaveService();
53
- public locations = new LocationsService();
54
- public pins = new PinsService();
55
- public roles = new RolesService();
56
- public settings = new SettingsService();
57
- public shifts = new ShiftsService();
58
- public terminals = new TerminalsService();
59
- public terminalsActive = new TerminalsActiveService();
60
- public timeZone = new TimeZoneService();
61
- public toilAccruals = new ToilAccrualsService();
62
- public toilAllowance = new ToilAllowanceService();
63
- public usersClockInService = new UsersClockInService();
64
- public users = new UsersService();
52
+ defaultAPIURI = DEFAULT_CONFIG.baseUri;
53
+ accounts = new AccountsService(this.client);
54
+ attendance = new AttendanceService(this.client);
55
+ auth = new AuthService(this.client);
56
+ availability = new AvailabilityService(this.client);
57
+ dailyBudgets = new DailyBudgetsService(this.client);
58
+ dailyRevenue = new DailyRevenueService(this.client);
59
+ dayNotes = new DayNotesService(this.client);
60
+ daysOff = new DaysOffService(this.client);
61
+ group = new GroupsService(this.client);
62
+ leaveEmbargoes = new LeaveEmbargoesService(this.client);
63
+ leaveRequests = new LeaveRequestService(this.client);
64
+ leaveTypes = new LeaveTypesService(this.client);
65
+ leave = new LeaveService(this.client);
66
+ locations = new LocationsService(this.client);
67
+ pins = new PinsService(this.client);
68
+ roles = new RolesService(this.client);
69
+ settings = new SettingsService(this.client);
70
+ shifts = new ShiftsService(this.client);
71
+ terminals = new TerminalsService(this.client);
72
+ terminalsActive = new TerminalsActiveService(this.client);
73
+ timeZone = new TimeZoneService(this.client);
74
+ toilAccruals = new ToilAccrualsService(this.client);
75
+ toilAllowance = new ToilAllowanceService(this.client);
76
+ usersClockInService = new UsersClockInService(this.client);
77
+ users = new UsersService(this.client);
65
78
 
66
79
  constructor(config: SDKConfig) {
67
80
  this.config = {
@@ -76,6 +89,32 @@ export class RotaCloud {
76
89
 
77
90
  set config(configVal: SDKConfig) {
78
91
  RotaCloud.config = configVal;
92
+ this.client.interceptors.request.clear();
93
+ this.client.interceptors.response.clear();
94
+ this.client.interceptors.response.use(
95
+ (response) => response,
96
+ (error: unknown) => {
97
+ let parsedError = error;
98
+ if (isAxiosError(error)) {
99
+ parsedError = parseClientError(error);
100
+ }
101
+ return Promise.reject(parsedError);
102
+ },
103
+ );
104
+ for (const requestInterceptor of this.config.interceptors?.request ?? []) {
105
+ const callbacks =
106
+ typeof requestInterceptor === 'function'
107
+ ? ([requestInterceptor] as const)
108
+ : ([requestInterceptor?.success, requestInterceptor?.error] as const);
109
+ this.client.interceptors.request.use(...callbacks);
110
+ }
111
+ for (const responseInterceptor of this.config.interceptors?.response ?? []) {
112
+ const callbacks =
113
+ typeof responseInterceptor === 'function'
114
+ ? ([responseInterceptor] as const)
115
+ : ([responseInterceptor?.success, responseInterceptor?.error] as const);
116
+ this.client.interceptors.response.use(...callbacks);
117
+ }
79
118
  }
80
119
  }
81
120
 
@@ -1,8 +1,7 @@
1
- import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } 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 { SDKErrorConfig, SDKError } from '../models/SDKError.model.js';
6
5
 
7
6
  export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
8
7
 
@@ -57,33 +56,7 @@ type ParameterPrimitive = string | boolean | number | null | symbol;
57
56
  type ParameterValue = ParameterPrimitive | ParameterPrimitive[] | undefined;
58
57
 
59
58
  export abstract class Service<ApiResponse = any> {
60
- protected client: AxiosInstance = this.initialiseAxios();
61
-
62
- private initialiseAxios(): AxiosInstance {
63
- const client = axios.create();
64
- client.interceptors.response.use(
65
- (response) => response,
66
- (error) => {
67
- const parsedError = this.parseClientError(error);
68
-
69
- return Promise.reject(parsedError);
70
- },
71
- );
72
- return client;
73
- }
74
-
75
- private parseClientError(error: unknown | AxiosError): SDKError | unknown {
76
- if (!axios.isAxiosError(error)) return error;
77
- const axiosErrorLocation = error.response || error.request;
78
- const apiErrorMessage = axiosErrorLocation.data?.error;
79
- const sdkErrorParams: SDKErrorConfig = {
80
- code: axiosErrorLocation.status,
81
- message: apiErrorMessage || error.message,
82
- data: axiosErrorLocation.data,
83
- };
84
-
85
- return new SDKError(sdkErrorParams);
86
- }
59
+ constructor(protected client: AxiosInstance) {}
87
60
 
88
61
  private isLeaveRequest(endpoint?: string): boolean {
89
62
  return endpoint === '/leave_requests';
@@ -5,10 +5,10 @@ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
5
5
  interface UserClockIn {
6
6
  method: string;
7
7
  shift: number;
8
- terminal: number;
8
+ terminal?: number;
9
9
  user: number;
10
10
  photo?: string;
11
- location: TerminalLocation;
11
+ location?: TerminalLocation;
12
12
  }
13
13
 
14
14
  interface UserClockOut extends Omit<UserClockIn, 'user' | 'shift'> {}
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const Version = { version: '1.2.1' };
1
+ export const Version = { version: '1.4.0' };