rotacloud 1.0.30 → 1.0.31

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 (53) hide show
  1. package/README.md +27 -1
  2. package/dist/cjs/interfaces/index.d.ts +2 -1
  3. package/dist/cjs/interfaces/index.js +2 -1
  4. package/dist/cjs/interfaces/query-params/index.d.ts +1 -0
  5. package/dist/cjs/interfaces/query-params/index.js +1 -0
  6. package/dist/cjs/interfaces/query-params/settings-query-params.interface.d.ts +3 -0
  7. package/dist/cjs/interfaces/query-params/settings-query-params.interface.js +2 -0
  8. package/dist/cjs/interfaces/sdk-config.interface.d.ts +2 -0
  9. package/dist/cjs/interfaces/settings.interface.d.ts +64 -0
  10. package/dist/cjs/interfaces/settings.interface.js +2 -0
  11. package/dist/cjs/models/settings.model.d.ts +2 -6
  12. package/dist/cjs/models/settings.model.js +3 -0
  13. package/dist/cjs/rotacloud.d.ts +4 -2
  14. package/dist/cjs/rotacloud.js +10 -6
  15. package/dist/cjs/services/index.d.ts +1 -0
  16. package/dist/cjs/services/index.js +1 -0
  17. package/dist/cjs/services/service.d.ts +19 -1
  18. package/dist/cjs/services/service.js +38 -3
  19. package/dist/cjs/services/settings.service.d.ts +14 -0
  20. package/dist/cjs/services/settings.service.js +16 -0
  21. package/dist/cjs/version.js +1 -1
  22. package/dist/mjs/interfaces/index.d.ts +2 -1
  23. package/dist/mjs/interfaces/index.js +2 -1
  24. package/dist/mjs/interfaces/query-params/index.d.ts +1 -0
  25. package/dist/mjs/interfaces/query-params/index.js +1 -0
  26. package/dist/mjs/interfaces/query-params/settings-query-params.interface.d.ts +3 -0
  27. package/dist/mjs/interfaces/query-params/settings-query-params.interface.js +1 -0
  28. package/dist/mjs/interfaces/sdk-config.interface.d.ts +2 -0
  29. package/dist/mjs/interfaces/settings.interface.d.ts +64 -0
  30. package/dist/mjs/interfaces/settings.interface.js +1 -0
  31. package/dist/mjs/models/settings.model.d.ts +2 -6
  32. package/dist/mjs/models/settings.model.js +3 -0
  33. package/dist/mjs/rotacloud.d.ts +4 -2
  34. package/dist/mjs/rotacloud.js +12 -6
  35. package/dist/mjs/services/index.d.ts +1 -0
  36. package/dist/mjs/services/index.js +1 -0
  37. package/dist/mjs/services/service.d.ts +19 -1
  38. package/dist/mjs/services/service.js +37 -2
  39. package/dist/mjs/services/settings.service.d.ts +14 -0
  40. package/dist/mjs/services/settings.service.js +13 -0
  41. package/dist/mjs/version.js +1 -1
  42. package/package.json +2 -1
  43. package/src/interfaces/index.ts +2 -1
  44. package/src/interfaces/query-params/index.ts +1 -0
  45. package/src/interfaces/query-params/settings-query-params.interface.ts +3 -0
  46. package/src/interfaces/sdk-config.interface.ts +3 -0
  47. package/src/interfaces/settings.interface.ts +63 -0
  48. package/src/models/settings.model.ts +5 -3
  49. package/src/rotacloud.ts +14 -5
  50. package/src/services/index.ts +1 -0
  51. package/src/services/service.ts +57 -3
  52. package/src/services/settings.service.ts +23 -0
  53. package/src/version.ts +1 -1
package/README.md CHANGED
@@ -6,7 +6,7 @@ Please ensure you perform the `npm run version:bump` command before commiting an
6
6
 
7
7
  ## Configuration
8
8
 
9
- Configuration is simple, just import the core rotacloud.js SDK and supply your API key as necessary.
9
+ Configuration is simple, just import the core RotaCloud SDK and supply your API key as necessary.
10
10
 
11
11
  ```typescript
12
12
  import { RotaCloud } from 'rotacloud';
@@ -29,3 +29,29 @@ try {
29
29
  console.log(e);
30
30
  }
31
31
  ```
32
+
33
+ ## Retry Policies
34
+
35
+ Our SDK supports both basic and customisable retry polices. Both can be easily configured in the SDKConfig object at time of instantiation. Both exponential and static value based back offs are supported.
36
+
37
+ Only idempotent requests will be retried.
38
+
39
+ ```typescript
40
+ import { RotaCloud } from 'rotacloud';
41
+
42
+ const rc = new RotaCloud({
43
+ apiKey: 'YOUR_API_KEY',
44
+ retry: 'expo' | 'static',
45
+ });
46
+ ```
47
+
48
+ If more granular control is required of the internal retry policy values, an object can be passed through the `retry` field.
49
+
50
+ ```typescript
51
+ import { RotaCloud } from 'rotacloud';
52
+
53
+ const rc = new RotaCloud({
54
+ apiKey: 'YOUR_API_KEY',
55
+ retry: { delay: 2000, exponential: false, maxRetries: 10 },
56
+ });
57
+ ```
@@ -26,5 +26,6 @@ export * from './pay-period.interface.js';
26
26
  export * from './role-rate.interface.js';
27
27
  export * from './role.interface.js';
28
28
  export * from './sdk-config.interface.js';
29
- export * from './user.interface.js';
29
+ export * from './settings.interface.js';
30
30
  export * from './shift.interface.js';
31
+ export * from './user.interface.js';
@@ -38,5 +38,6 @@ __exportStar(require("./pay-period.interface.js"), exports);
38
38
  __exportStar(require("./role-rate.interface.js"), exports);
39
39
  __exportStar(require("./role.interface.js"), exports);
40
40
  __exportStar(require("./sdk-config.interface.js"), exports);
41
- __exportStar(require("./user.interface.js"), exports);
41
+ __exportStar(require("./settings.interface.js"), exports);
42
42
  __exportStar(require("./shift.interface.js"), exports);
43
+ __exportStar(require("./user.interface.js"), exports);
@@ -17,6 +17,7 @@ export * from './locations-query-params.interface.js';
17
17
  export * from './logbook-events-query-params.interface.js';
18
18
  export * from './pay-periods-query-params.interface.js';
19
19
  export * from './roles-query-params.interface.js';
20
+ export * from './settings-query-params.interface.js';
20
21
  export * from './shifts-query-params.interface.js';
21
22
  export * from './swap-requests-query-params.interface.js';
22
23
  export * from './terminals-query-params.interface.js';
@@ -29,6 +29,7 @@ __exportStar(require("./locations-query-params.interface.js"), exports);
29
29
  __exportStar(require("./logbook-events-query-params.interface.js"), exports);
30
30
  __exportStar(require("./pay-periods-query-params.interface.js"), exports);
31
31
  __exportStar(require("./roles-query-params.interface.js"), exports);
32
+ __exportStar(require("./settings-query-params.interface.js"), exports);
32
33
  __exportStar(require("./shifts-query-params.interface.js"), exports);
33
34
  __exportStar(require("./swap-requests-query-params.interface.js"), exports);
34
35
  __exportStar(require("./terminals-query-params.interface.js"), exports);
@@ -0,0 +1,3 @@
1
+ export interface SettingsQueryParams {
2
+ only_values?: boolean;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,8 @@
1
+ import { RetryOptions, RetryStrategy } from '../services/service.js';
1
2
  export interface SDKConfig {
2
3
  baseUri?: string;
3
4
  apiKey: string;
4
5
  accountId?: number;
5
6
  userId?: number;
7
+ retry?: false | `${RetryStrategy}` | RetryOptions;
6
8
  }
@@ -0,0 +1,64 @@
1
+ export interface PayCodes {
2
+ [pay_code_id: string]: string | {
3
+ [leave_type_id: string]: string;
4
+ };
5
+ }
6
+ export interface ApiSettings {
7
+ attendance_record_breaks: string;
8
+ automatically_clock_in_to_consecutive_shifts: boolean;
9
+ availability_employees_can_edit: boolean;
10
+ availability_managers_can_edit: boolean;
11
+ breaks_paid: boolean;
12
+ clock_in_out_reminders_minutes: number;
13
+ clock_in_without_shift_allowed: string;
14
+ currency_symbol: string;
15
+ dashboard_show_unpublished_shifts: boolean;
16
+ early_clock_ins_paid_from: string;
17
+ early_clock_in_minutes: number;
18
+ employee_shift_note_visibility: string;
19
+ employees_can_edit_timesheets: boolean;
20
+ employees_can_only_see_self: boolean;
21
+ employees_can_see_all_locations: boolean;
22
+ employees_can_see_everyones_leave: boolean;
23
+ flag_in_out_discrepancies_minutes: number;
24
+ holiday_accrual_rate: number;
25
+ late_clock_outs_paid_until: string;
26
+ lateness_added_after_minutes: number;
27
+ leave_can_request_over_allowance: boolean;
28
+ leave_prorate_allowances: boolean;
29
+ leave_requests_enabled: boolean;
30
+ leave_requests_notice_days: number;
31
+ leave_year_start_day: number;
32
+ leave_year_start_month: number;
33
+ metadata_enabled: boolean;
34
+ mobile_clocking_enabled: boolean;
35
+ no_show_notifications_minutes: number;
36
+ open_shift_claiming_enabled: boolean;
37
+ public_holiday_affects_allowance: boolean;
38
+ reminders_enabled: boolean;
39
+ rota_grouping: string;
40
+ rota_salaried_cost_method: string;
41
+ rota_show_employee_photos: boolean;
42
+ round_breaks: string;
43
+ round_breaks_direction: string;
44
+ round_currency: string;
45
+ round_currency_direction: string;
46
+ round_hours: string;
47
+ round_hours_direction: string;
48
+ shift_acknowledgement_enabled: boolean;
49
+ shift_swaps_across_locations_enabled: boolean;
50
+ shift_swaps_enabled: boolean;
51
+ shift_swaps_notice_hours: number;
52
+ shift_swaps_require_approval: boolean;
53
+ shift_swaps_shift_range_days: number;
54
+ show_open_shifts_from_other_locations: boolean;
55
+ show_shifts_from_other_locations: boolean;
56
+ time_format: string;
57
+ unavailability_notice_hours: number;
58
+ unavailability_requests_enabled: boolean;
59
+ unpaid_leave_types_included_in_accrual: number[];
60
+ paid_leave_types_included_in_accrual: number[];
61
+ week_starts: string;
62
+ pay_codes: PayCodes;
63
+ webhook_signing_secret: string;
64
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,4 @@
1
- interface PayCodes {
2
- [pay_code_id: string]: string | {
3
- [leave_type_id: string]: string;
4
- };
5
- }
1
+ import { ApiSettings, PayCodes } from '../interfaces';
6
2
  export declare class Settings {
7
3
  attendance_record_breaks: string;
8
4
  automatically_clock_in_to_consecutive_shifts: boolean;
@@ -61,5 +57,5 @@ export declare class Settings {
61
57
  week_starts: string;
62
58
  pay_codes: PayCodes;
63
59
  webhook_signing_secret: string;
60
+ constructor(settings: ApiSettings);
64
61
  }
65
- export {};
@@ -2,5 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Settings = void 0;
4
4
  class Settings {
5
+ constructor(settings) {
6
+ this.attendance_record_breaks = settings.attendance_record_breaks;
7
+ }
5
8
  }
6
9
  exports.Settings = Settings;
@@ -1,8 +1,8 @@
1
- import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveService, LocationsService, RolesService, ShiftsService, UsersService } from './services/index.js';
1
+ import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveService, LocationsService, RolesService, SettingsService, ShiftsService, UsersService } from './services/index.js';
2
2
  import { SDKConfig } from './interfaces/index.js';
3
3
  export declare class RotaCloud {
4
4
  static config: SDKConfig;
5
- defaultAPIURI: string;
5
+ defaultAPIURI: string | undefined;
6
6
  accounts: AccountsService;
7
7
  attendance: AttendanceService;
8
8
  auth: AuthService;
@@ -16,11 +16,13 @@ export declare class RotaCloud {
16
16
  leave: LeaveService;
17
17
  locations: LocationsService;
18
18
  roles: RolesService;
19
+ settings: SettingsService;
19
20
  shifts: ShiftsService;
20
21
  users: UsersService;
21
22
  constructor(config: SDKConfig);
22
23
  get config(): SDKConfig;
23
24
  set config(configVal: SDKConfig);
24
25
  }
26
+ export { RetryStrategy, RetryOptions } from './services/service.js';
25
27
  export * from './interfaces/index.js';
26
28
  export * from './interfaces/query-params/index.js';
@@ -10,11 +10,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.RotaCloud = void 0;
13
+ exports.RetryStrategy = exports.RotaCloud = void 0;
14
14
  const index_js_1 = require("./services/index.js");
15
+ const DEFAULT_CONFIG = {
16
+ baseUri: 'https://api.rotacloud.com/v1',
17
+ retry: index_js_1.RetryStrategy.Exponential,
18
+ };
15
19
  class RotaCloud {
16
20
  constructor(config) {
17
- this.defaultAPIURI = 'https://api.rotacloud.com/v1';
21
+ this.defaultAPIURI = DEFAULT_CONFIG.baseUri;
18
22
  this.accounts = new index_js_1.AccountsService();
19
23
  this.attendance = new index_js_1.AttendanceService();
20
24
  this.auth = new index_js_1.AuthService();
@@ -28,12 +32,10 @@ class RotaCloud {
28
32
  this.leave = new index_js_1.LeaveService();
29
33
  this.locations = new index_js_1.LocationsService();
30
34
  this.roles = new index_js_1.RolesService();
35
+ this.settings = new index_js_1.SettingsService();
31
36
  this.shifts = new index_js_1.ShiftsService();
32
37
  this.users = new index_js_1.UsersService();
33
- if (!config.baseUri) {
34
- config.baseUri = this.defaultAPIURI;
35
- }
36
- this.config = config;
38
+ this.config = Object.assign(Object.assign({}, DEFAULT_CONFIG), config);
37
39
  }
38
40
  get config() {
39
41
  return RotaCloud.config;
@@ -43,5 +45,7 @@ class RotaCloud {
43
45
  }
44
46
  }
45
47
  exports.RotaCloud = RotaCloud;
48
+ var service_js_1 = require("./services/service.js");
49
+ Object.defineProperty(exports, "RetryStrategy", { enumerable: true, get: function () { return service_js_1.RetryStrategy; } });
46
50
  __exportStar(require("./interfaces/index.js"), exports);
47
51
  __exportStar(require("./interfaces/query-params/index.js"), exports);
@@ -12,5 +12,6 @@ export * from './leave-embargoes.service.js';
12
12
  export * from './leave.service.js';
13
13
  export * from './locations.service.js';
14
14
  export * from './roles.service.js';
15
+ export * from './settings.service.js';
15
16
  export * from './shifts.service.js';
16
17
  export * from './users.service.js';
@@ -24,5 +24,6 @@ __exportStar(require("./leave-embargoes.service.js"), exports);
24
24
  __exportStar(require("./leave.service.js"), exports);
25
25
  __exportStar(require("./locations.service.js"), exports);
26
26
  __exportStar(require("./roles.service.js"), exports);
27
+ __exportStar(require("./settings.service.js"), exports);
27
28
  __exportStar(require("./shifts.service.js"), exports);
28
29
  __exportStar(require("./users.service.js"), exports);
@@ -1,5 +1,22 @@
1
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  export declare type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
3
+ export declare enum RetryStrategy {
4
+ Exponential = "expo",
5
+ Static = "static"
6
+ }
7
+ export declare type RetryOptions = {
8
+ /** Use exponential back-off */
9
+ exponential?: false;
10
+ /** The maximum number of retries before erroring */
11
+ maxRetries: number;
12
+ /** Delay in milliseconds between retry attempts - not used in exponential back-off */
13
+ delay: number;
14
+ } | {
15
+ /** Use exponential back-off */
16
+ exponential: true;
17
+ /** The maximum number of retries before erroring */
18
+ maxRetries: number;
19
+ };
3
20
  export interface Options {
4
21
  rawResponse?: boolean;
5
22
  expand?: string[];
@@ -7,6 +24,7 @@ export interface Options {
7
24
  limit?: number;
8
25
  }
9
26
  export declare abstract class Service<ApiResponse = any> {
27
+ protected client: AxiosInstance;
10
28
  isLeaveRequest(endpoint?: string): boolean;
11
29
  private buildQueryStr;
12
30
  private getPagingObject;
@@ -36,12 +36,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Service = void 0;
39
+ exports.Service = exports.RetryStrategy = void 0;
40
40
  const axios_1 = __importDefault(require("axios"));
41
+ const axios_retry_1 = __importDefault(require("axios-retry"));
41
42
  const rotacloud_js_1 = require("../rotacloud.js");
42
43
  const version_js_1 = require("../version.js");
44
+ var RetryStrategy;
45
+ (function (RetryStrategy) {
46
+ RetryStrategy["Exponential"] = "expo";
47
+ RetryStrategy["Static"] = "static";
48
+ })(RetryStrategy = exports.RetryStrategy || (exports.RetryStrategy = {}));
49
+ const DEFAULT_RETRIES = 3;
50
+ const DEFAULT_RETRY_DELAY = 2000;
51
+ const DEFAULT_RETRY_STRATEGY_OPTIONS = {
52
+ [RetryStrategy.Exponential]: {
53
+ exponential: true,
54
+ maxRetries: DEFAULT_RETRIES,
55
+ },
56
+ [RetryStrategy.Static]: {
57
+ exponential: false,
58
+ maxRetries: DEFAULT_RETRIES,
59
+ delay: DEFAULT_RETRY_DELAY,
60
+ },
61
+ };
43
62
  class Service {
44
- // rate limit tracking could be implemented here statically
63
+ constructor() {
64
+ this.client = axios_1.default.create();
65
+ }
45
66
  isLeaveRequest(endpoint) {
46
67
  return endpoint === '/leave_requests';
47
68
  }
@@ -84,7 +105,21 @@ class Service {
84
105
  const reqObject = Object.assign(Object.assign({}, httpOptions), { baseURL: rotacloud_js_1.RotaCloud.config.baseUri, headers, params: Object.assign({ expand: options === null || options === void 0 ? void 0 : options.expand, fields: options === null || options === void 0 ? void 0 : options.fields, limit: options === null || options === void 0 ? void 0 : options.limit }, httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.params), paramsSerializer: (params) => {
85
106
  return params ? this.buildQueryStr(params) : '';
86
107
  } });
87
- const response = yield axios_1.default.request(reqObject);
108
+ if (rotacloud_js_1.RotaCloud.config.retry) {
109
+ const retryConfig = typeof rotacloud_js_1.RotaCloud.config.retry === 'string'
110
+ ? DEFAULT_RETRY_STRATEGY_OPTIONS[rotacloud_js_1.RotaCloud.config.retry]
111
+ : rotacloud_js_1.RotaCloud.config.retry;
112
+ (0, axios_retry_1.default)(this.client, {
113
+ retries: retryConfig.maxRetries,
114
+ retryDelay: (retryCount) => {
115
+ if (retryConfig.exponential) {
116
+ return axios_retry_1.default.exponentialDelay(retryCount);
117
+ }
118
+ return retryConfig.delay;
119
+ },
120
+ });
121
+ }
122
+ const response = yield this.client.request(reqObject);
88
123
  return response;
89
124
  });
90
125
  }
@@ -0,0 +1,14 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Settings } from '../models/settings.model.js';
3
+ import { Service, Options } from './index.js';
4
+ import { ApiSettings } from '../interfaces/index.js';
5
+ import { SettingsQueryParams } from '../rotacloud.js';
6
+ declare class SettingsService extends Service {
7
+ private apiPath;
8
+ get(query: SettingsQueryParams): Promise<Settings>;
9
+ get(query: SettingsQueryParams, options: {
10
+ rawResponse: true;
11
+ } & Options): Promise<AxiosResponse<ApiSettings, any>>;
12
+ get(query: SettingsQueryParams, options: Options): Promise<Settings>;
13
+ }
14
+ export { SettingsService };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SettingsService = void 0;
4
+ const settings_model_js_1 = require("../models/settings.model.js");
5
+ const index_js_1 = require("./index.js");
6
+ const error_response_model_js_1 = require("../models/error-response.model.js");
7
+ class SettingsService extends index_js_1.Service {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.apiPath = '/settings';
11
+ }
12
+ get(query, options) {
13
+ return super.fetch({ url: `${this.apiPath}`, params: query }, options).then((res) => Promise.resolve((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : new settings_model_js_1.Settings(res.data)), (err) => Promise.reject((options === null || options === void 0 ? void 0 : options.rawResponse) ? err : new error_response_model_js_1.ErrorResponse(err)));
14
+ }
15
+ }
16
+ exports.SettingsService = SettingsService;
@@ -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.0.30' };
4
+ exports.Version = { version: '1.0.31' };
@@ -26,5 +26,6 @@ export * from './pay-period.interface.js';
26
26
  export * from './role-rate.interface.js';
27
27
  export * from './role.interface.js';
28
28
  export * from './sdk-config.interface.js';
29
- export * from './user.interface.js';
29
+ export * from './settings.interface.js';
30
30
  export * from './shift.interface.js';
31
+ export * from './user.interface.js';
@@ -26,5 +26,6 @@ export * from './pay-period.interface.js';
26
26
  export * from './role-rate.interface.js';
27
27
  export * from './role.interface.js';
28
28
  export * from './sdk-config.interface.js';
29
- export * from './user.interface.js';
29
+ export * from './settings.interface.js';
30
30
  export * from './shift.interface.js';
31
+ export * from './user.interface.js';
@@ -17,6 +17,7 @@ export * from './locations-query-params.interface.js';
17
17
  export * from './logbook-events-query-params.interface.js';
18
18
  export * from './pay-periods-query-params.interface.js';
19
19
  export * from './roles-query-params.interface.js';
20
+ export * from './settings-query-params.interface.js';
20
21
  export * from './shifts-query-params.interface.js';
21
22
  export * from './swap-requests-query-params.interface.js';
22
23
  export * from './terminals-query-params.interface.js';
@@ -17,6 +17,7 @@ export * from './locations-query-params.interface.js';
17
17
  export * from './logbook-events-query-params.interface.js';
18
18
  export * from './pay-periods-query-params.interface.js';
19
19
  export * from './roles-query-params.interface.js';
20
+ export * from './settings-query-params.interface.js';
20
21
  export * from './shifts-query-params.interface.js';
21
22
  export * from './swap-requests-query-params.interface.js';
22
23
  export * from './terminals-query-params.interface.js';
@@ -0,0 +1,3 @@
1
+ export interface SettingsQueryParams {
2
+ only_values?: boolean;
3
+ }
@@ -1,6 +1,8 @@
1
+ import { RetryOptions, RetryStrategy } from '../services/service.js';
1
2
  export interface SDKConfig {
2
3
  baseUri?: string;
3
4
  apiKey: string;
4
5
  accountId?: number;
5
6
  userId?: number;
7
+ retry?: false | `${RetryStrategy}` | RetryOptions;
6
8
  }
@@ -0,0 +1,64 @@
1
+ export interface PayCodes {
2
+ [pay_code_id: string]: string | {
3
+ [leave_type_id: string]: string;
4
+ };
5
+ }
6
+ export interface ApiSettings {
7
+ attendance_record_breaks: string;
8
+ automatically_clock_in_to_consecutive_shifts: boolean;
9
+ availability_employees_can_edit: boolean;
10
+ availability_managers_can_edit: boolean;
11
+ breaks_paid: boolean;
12
+ clock_in_out_reminders_minutes: number;
13
+ clock_in_without_shift_allowed: string;
14
+ currency_symbol: string;
15
+ dashboard_show_unpublished_shifts: boolean;
16
+ early_clock_ins_paid_from: string;
17
+ early_clock_in_minutes: number;
18
+ employee_shift_note_visibility: string;
19
+ employees_can_edit_timesheets: boolean;
20
+ employees_can_only_see_self: boolean;
21
+ employees_can_see_all_locations: boolean;
22
+ employees_can_see_everyones_leave: boolean;
23
+ flag_in_out_discrepancies_minutes: number;
24
+ holiday_accrual_rate: number;
25
+ late_clock_outs_paid_until: string;
26
+ lateness_added_after_minutes: number;
27
+ leave_can_request_over_allowance: boolean;
28
+ leave_prorate_allowances: boolean;
29
+ leave_requests_enabled: boolean;
30
+ leave_requests_notice_days: number;
31
+ leave_year_start_day: number;
32
+ leave_year_start_month: number;
33
+ metadata_enabled: boolean;
34
+ mobile_clocking_enabled: boolean;
35
+ no_show_notifications_minutes: number;
36
+ open_shift_claiming_enabled: boolean;
37
+ public_holiday_affects_allowance: boolean;
38
+ reminders_enabled: boolean;
39
+ rota_grouping: string;
40
+ rota_salaried_cost_method: string;
41
+ rota_show_employee_photos: boolean;
42
+ round_breaks: string;
43
+ round_breaks_direction: string;
44
+ round_currency: string;
45
+ round_currency_direction: string;
46
+ round_hours: string;
47
+ round_hours_direction: string;
48
+ shift_acknowledgement_enabled: boolean;
49
+ shift_swaps_across_locations_enabled: boolean;
50
+ shift_swaps_enabled: boolean;
51
+ shift_swaps_notice_hours: number;
52
+ shift_swaps_require_approval: boolean;
53
+ shift_swaps_shift_range_days: number;
54
+ show_open_shifts_from_other_locations: boolean;
55
+ show_shifts_from_other_locations: boolean;
56
+ time_format: string;
57
+ unavailability_notice_hours: number;
58
+ unavailability_requests_enabled: boolean;
59
+ unpaid_leave_types_included_in_accrual: number[];
60
+ paid_leave_types_included_in_accrual: number[];
61
+ week_starts: string;
62
+ pay_codes: PayCodes;
63
+ webhook_signing_secret: string;
64
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,4 @@
1
- interface PayCodes {
2
- [pay_code_id: string]: string | {
3
- [leave_type_id: string]: string;
4
- };
5
- }
1
+ import { ApiSettings, PayCodes } from '../interfaces';
6
2
  export declare class Settings {
7
3
  attendance_record_breaks: string;
8
4
  automatically_clock_in_to_consecutive_shifts: boolean;
@@ -61,5 +57,5 @@ export declare class Settings {
61
57
  week_starts: string;
62
58
  pay_codes: PayCodes;
63
59
  webhook_signing_secret: string;
60
+ constructor(settings: ApiSettings);
64
61
  }
65
- export {};
@@ -1,2 +1,5 @@
1
1
  export class Settings {
2
+ constructor(settings) {
3
+ this.attendance_record_breaks = settings.attendance_record_breaks;
4
+ }
2
5
  }
@@ -1,8 +1,8 @@
1
- import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveService, LocationsService, RolesService, ShiftsService, UsersService } from './services/index.js';
1
+ import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveService, LocationsService, RolesService, SettingsService, ShiftsService, UsersService } from './services/index.js';
2
2
  import { SDKConfig } from './interfaces/index.js';
3
3
  export declare class RotaCloud {
4
4
  static config: SDKConfig;
5
- defaultAPIURI: string;
5
+ defaultAPIURI: string | undefined;
6
6
  accounts: AccountsService;
7
7
  attendance: AttendanceService;
8
8
  auth: AuthService;
@@ -16,11 +16,13 @@ export declare class RotaCloud {
16
16
  leave: LeaveService;
17
17
  locations: LocationsService;
18
18
  roles: RolesService;
19
+ settings: SettingsService;
19
20
  shifts: ShiftsService;
20
21
  users: UsersService;
21
22
  constructor(config: SDKConfig);
22
23
  get config(): SDKConfig;
23
24
  set config(configVal: SDKConfig);
24
25
  }
26
+ export { RetryStrategy, RetryOptions } from './services/service.js';
25
27
  export * from './interfaces/index.js';
26
28
  export * from './interfaces/query-params/index.js';
@@ -1,7 +1,11 @@
1
- import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveService, LocationsService, RolesService, ShiftsService, UsersService, } from './services/index.js';
1
+ import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveService, LocationsService, RetryStrategy, RolesService, SettingsService, ShiftsService, UsersService, } from './services/index.js';
2
+ const DEFAULT_CONFIG = {
3
+ baseUri: 'https://api.rotacloud.com/v1',
4
+ retry: RetryStrategy.Exponential,
5
+ };
2
6
  export class RotaCloud {
3
7
  constructor(config) {
4
- this.defaultAPIURI = 'https://api.rotacloud.com/v1';
8
+ this.defaultAPIURI = DEFAULT_CONFIG.baseUri;
5
9
  this.accounts = new AccountsService();
6
10
  this.attendance = new AttendanceService();
7
11
  this.auth = new AuthService();
@@ -15,12 +19,13 @@ export class RotaCloud {
15
19
  this.leave = new LeaveService();
16
20
  this.locations = new LocationsService();
17
21
  this.roles = new RolesService();
22
+ this.settings = new SettingsService();
18
23
  this.shifts = new ShiftsService();
19
24
  this.users = new UsersService();
20
- if (!config.baseUri) {
21
- config.baseUri = this.defaultAPIURI;
22
- }
23
- this.config = config;
25
+ this.config = {
26
+ ...DEFAULT_CONFIG,
27
+ ...config,
28
+ };
24
29
  }
25
30
  get config() {
26
31
  return RotaCloud.config;
@@ -29,5 +34,6 @@ export class RotaCloud {
29
34
  RotaCloud.config = configVal;
30
35
  }
31
36
  }
37
+ export { RetryStrategy } from './services/service.js';
32
38
  export * from './interfaces/index.js';
33
39
  export * from './interfaces/query-params/index.js';
@@ -12,5 +12,6 @@ export * from './leave-embargoes.service.js';
12
12
  export * from './leave.service.js';
13
13
  export * from './locations.service.js';
14
14
  export * from './roles.service.js';
15
+ export * from './settings.service.js';
15
16
  export * from './shifts.service.js';
16
17
  export * from './users.service.js';
@@ -12,5 +12,6 @@ export * from './leave-embargoes.service.js';
12
12
  export * from './leave.service.js';
13
13
  export * from './locations.service.js';
14
14
  export * from './roles.service.js';
15
+ export * from './settings.service.js';
15
16
  export * from './shifts.service.js';
16
17
  export * from './users.service.js';
@@ -1,5 +1,22 @@
1
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  export declare type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
3
+ export declare enum RetryStrategy {
4
+ Exponential = "expo",
5
+ Static = "static"
6
+ }
7
+ export declare type RetryOptions = {
8
+ /** Use exponential back-off */
9
+ exponential?: false;
10
+ /** The maximum number of retries before erroring */
11
+ maxRetries: number;
12
+ /** Delay in milliseconds between retry attempts - not used in exponential back-off */
13
+ delay: number;
14
+ } | {
15
+ /** Use exponential back-off */
16
+ exponential: true;
17
+ /** The maximum number of retries before erroring */
18
+ maxRetries: number;
19
+ };
3
20
  export interface Options {
4
21
  rawResponse?: boolean;
5
22
  expand?: string[];
@@ -7,6 +24,7 @@ export interface Options {
7
24
  limit?: number;
8
25
  }
9
26
  export declare abstract class Service<ApiResponse = any> {
27
+ protected client: AxiosInstance;
10
28
  isLeaveRequest(endpoint?: string): boolean;
11
29
  private buildQueryStr;
12
30
  private getPagingObject;
@@ -1,8 +1,29 @@
1
1
  import axios from 'axios';
2
+ import axiosRetry from 'axios-retry';
2
3
  import { RotaCloud } from '../rotacloud.js';
3
4
  import { Version } from '../version.js';
5
+ export var RetryStrategy;
6
+ (function (RetryStrategy) {
7
+ RetryStrategy["Exponential"] = "expo";
8
+ RetryStrategy["Static"] = "static";
9
+ })(RetryStrategy || (RetryStrategy = {}));
10
+ const DEFAULT_RETRIES = 3;
11
+ const DEFAULT_RETRY_DELAY = 2000;
12
+ const DEFAULT_RETRY_STRATEGY_OPTIONS = {
13
+ [RetryStrategy.Exponential]: {
14
+ exponential: true,
15
+ maxRetries: DEFAULT_RETRIES,
16
+ },
17
+ [RetryStrategy.Static]: {
18
+ exponential: false,
19
+ maxRetries: DEFAULT_RETRIES,
20
+ delay: DEFAULT_RETRY_DELAY,
21
+ },
22
+ };
4
23
  export class Service {
5
- // rate limit tracking could be implemented here statically
24
+ constructor() {
25
+ this.client = axios.create();
26
+ }
6
27
  isLeaveRequest(endpoint) {
7
28
  return endpoint === '/leave_requests';
8
29
  }
@@ -55,7 +76,21 @@ export class Service {
55
76
  return params ? this.buildQueryStr(params) : '';
56
77
  },
57
78
  };
58
- const response = await axios.request(reqObject);
79
+ if (RotaCloud.config.retry) {
80
+ const retryConfig = typeof RotaCloud.config.retry === 'string'
81
+ ? DEFAULT_RETRY_STRATEGY_OPTIONS[RotaCloud.config.retry]
82
+ : RotaCloud.config.retry;
83
+ axiosRetry(this.client, {
84
+ retries: retryConfig.maxRetries,
85
+ retryDelay: (retryCount) => {
86
+ if (retryConfig.exponential) {
87
+ return axiosRetry.exponentialDelay(retryCount);
88
+ }
89
+ return retryConfig.delay;
90
+ },
91
+ });
92
+ }
93
+ const response = await this.client.request(reqObject);
59
94
  return response;
60
95
  }
61
96
  async *listFetch(reqObject, options) {
@@ -0,0 +1,14 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Settings } from '../models/settings.model.js';
3
+ import { Service, Options } from './index.js';
4
+ import { ApiSettings } from '../interfaces/index.js';
5
+ import { SettingsQueryParams } from '../rotacloud.js';
6
+ declare class SettingsService extends Service {
7
+ private apiPath;
8
+ get(query: SettingsQueryParams): Promise<Settings>;
9
+ get(query: SettingsQueryParams, options: {
10
+ rawResponse: true;
11
+ } & Options): Promise<AxiosResponse<ApiSettings, any>>;
12
+ get(query: SettingsQueryParams, options: Options): Promise<Settings>;
13
+ }
14
+ export { SettingsService };
@@ -0,0 +1,13 @@
1
+ import { Settings } from '../models/settings.model.js';
2
+ import { Service } from './index.js';
3
+ import { ErrorResponse } from '../models/error-response.model.js';
4
+ class SettingsService extends Service {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.apiPath = '/settings';
8
+ }
9
+ get(query, options) {
10
+ return super.fetch({ url: `${this.apiPath}`, params: query }, options).then((res) => Promise.resolve(options?.rawResponse ? res : new Settings(res.data)), (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err)));
11
+ }
12
+ }
13
+ export { SettingsService };
@@ -1 +1 @@
1
- export const Version = { version: '1.0.30' };
1
+ export const Version = { version: '1.0.31' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rotacloud",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "The RotaCloud SDK for the RotaCloud API",
5
5
  "engines": {
6
6
  "node": ">=14.17.0"
@@ -47,6 +47,7 @@
47
47
  "dependencies": {
48
48
  "@types/node": "^16.11.6",
49
49
  "axios": "^0.23.0",
50
+ "axios-retry": "^3.3.1",
50
51
  "cross-var": "^1.1.0"
51
52
  }
52
53
  }
@@ -26,5 +26,6 @@ export * from './pay-period.interface.js';
26
26
  export * from './role-rate.interface.js';
27
27
  export * from './role.interface.js';
28
28
  export * from './sdk-config.interface.js';
29
- export * from './user.interface.js';
29
+ export * from './settings.interface.js';
30
30
  export * from './shift.interface.js';
31
+ export * from './user.interface.js';
@@ -17,6 +17,7 @@ export * from './locations-query-params.interface.js';
17
17
  export * from './logbook-events-query-params.interface.js';
18
18
  export * from './pay-periods-query-params.interface.js';
19
19
  export * from './roles-query-params.interface.js';
20
+ export * from './settings-query-params.interface.js';
20
21
  export * from './shifts-query-params.interface.js';
21
22
  export * from './swap-requests-query-params.interface.js';
22
23
  export * from './terminals-query-params.interface.js';
@@ -0,0 +1,3 @@
1
+ export interface SettingsQueryParams {
2
+ only_values?: boolean;
3
+ }
@@ -1,6 +1,9 @@
1
+ import { RetryOptions, RetryStrategy } from '../services/service.js';
2
+
1
3
  export interface SDKConfig {
2
4
  baseUri?: string;
3
5
  apiKey: string;
4
6
  accountId?: number;
5
7
  userId?: number;
8
+ retry?: false | `${RetryStrategy}` | RetryOptions;
6
9
  }
@@ -0,0 +1,63 @@
1
+ export interface PayCodes {
2
+ [pay_code_id: string]: string | { [leave_type_id: string]: string };
3
+ }
4
+
5
+ export interface ApiSettings {
6
+ attendance_record_breaks: string;
7
+ automatically_clock_in_to_consecutive_shifts: boolean;
8
+ availability_employees_can_edit: boolean;
9
+ availability_managers_can_edit: boolean;
10
+ breaks_paid: boolean;
11
+ clock_in_out_reminders_minutes: number;
12
+ clock_in_without_shift_allowed: string;
13
+ currency_symbol: string;
14
+ dashboard_show_unpublished_shifts: boolean;
15
+ early_clock_ins_paid_from: string;
16
+ early_clock_in_minutes: number;
17
+ employee_shift_note_visibility: string;
18
+ employees_can_edit_timesheets: boolean;
19
+ employees_can_only_see_self: boolean;
20
+ employees_can_see_all_locations: boolean;
21
+ employees_can_see_everyones_leave: boolean;
22
+ flag_in_out_discrepancies_minutes: number;
23
+ holiday_accrual_rate: number;
24
+ late_clock_outs_paid_until: string;
25
+ lateness_added_after_minutes: number;
26
+ leave_can_request_over_allowance: boolean;
27
+ leave_prorate_allowances: boolean;
28
+ leave_requests_enabled: boolean;
29
+ leave_requests_notice_days: number;
30
+ leave_year_start_day: number;
31
+ leave_year_start_month: number;
32
+ metadata_enabled: boolean;
33
+ mobile_clocking_enabled: boolean;
34
+ no_show_notifications_minutes: number;
35
+ open_shift_claiming_enabled: boolean;
36
+ public_holiday_affects_allowance: boolean;
37
+ reminders_enabled: boolean;
38
+ rota_grouping: string;
39
+ rota_salaried_cost_method: string;
40
+ rota_show_employee_photos: boolean;
41
+ round_breaks: string;
42
+ round_breaks_direction: string;
43
+ round_currency: string;
44
+ round_currency_direction: string;
45
+ round_hours: string;
46
+ round_hours_direction: string;
47
+ shift_acknowledgement_enabled: boolean;
48
+ shift_swaps_across_locations_enabled: boolean;
49
+ shift_swaps_enabled: boolean;
50
+ shift_swaps_notice_hours: number;
51
+ shift_swaps_require_approval: boolean;
52
+ shift_swaps_shift_range_days: number;
53
+ show_open_shifts_from_other_locations: boolean;
54
+ show_shifts_from_other_locations: boolean;
55
+ time_format: string;
56
+ unavailability_notice_hours: number;
57
+ unavailability_requests_enabled: boolean;
58
+ unpaid_leave_types_included_in_accrual: number[];
59
+ paid_leave_types_included_in_accrual: number[];
60
+ week_starts: string;
61
+ pay_codes: PayCodes;
62
+ webhook_signing_secret: string;
63
+ }
@@ -1,6 +1,4 @@
1
- interface PayCodes {
2
- [pay_code_id: string]: string | { [leave_type_id: string]: string };
3
- }
1
+ import { ApiSettings, PayCodes } from '../interfaces';
4
2
 
5
3
  export class Settings {
6
4
  public attendance_record_breaks: string;
@@ -60,4 +58,8 @@ export class Settings {
60
58
  public week_starts: string;
61
59
  public pay_codes: PayCodes;
62
60
  public webhook_signing_secret: string;
61
+
62
+ constructor(settings: ApiSettings) {
63
+ this.attendance_record_breaks = settings.attendance_record_breaks;
64
+ }
63
65
  }
package/src/rotacloud.ts CHANGED
@@ -11,16 +11,23 @@ import {
11
11
  LeaveRequestService,
12
12
  LeaveService,
13
13
  LocationsService,
14
+ RetryStrategy,
14
15
  RolesService,
16
+ SettingsService,
15
17
  ShiftsService,
16
18
  UsersService,
17
19
  } from './services/index.js';
18
20
  import { SDKConfig } from './interfaces/index.js';
19
21
 
22
+ const DEFAULT_CONFIG: Partial<SDKConfig> = {
23
+ baseUri: 'https://api.rotacloud.com/v1',
24
+ retry: RetryStrategy.Exponential,
25
+ };
26
+
20
27
  export class RotaCloud {
21
28
  public static config: SDKConfig;
22
29
 
23
- public defaultAPIURI = 'https://api.rotacloud.com/v1';
30
+ public defaultAPIURI = DEFAULT_CONFIG.baseUri;
24
31
  public accounts = new AccountsService();
25
32
  public attendance = new AttendanceService();
26
33
  public auth = new AuthService();
@@ -34,14 +41,15 @@ export class RotaCloud {
34
41
  public leave = new LeaveService();
35
42
  public locations = new LocationsService();
36
43
  public roles = new RolesService();
44
+ public settings = new SettingsService();
37
45
  public shifts = new ShiftsService();
38
46
  public users = new UsersService();
39
47
 
40
48
  constructor(config: SDKConfig) {
41
- if (!config.baseUri) {
42
- config.baseUri = this.defaultAPIURI;
43
- }
44
- this.config = config;
49
+ this.config = {
50
+ ...DEFAULT_CONFIG,
51
+ ...config,
52
+ };
45
53
  }
46
54
 
47
55
  get config() {
@@ -53,5 +61,6 @@ export class RotaCloud {
53
61
  }
54
62
  }
55
63
 
64
+ export { RetryStrategy, RetryOptions } from './services/service.js';
56
65
  export * from './interfaces/index.js';
57
66
  export * from './interfaces/query-params/index.js';
@@ -12,5 +12,6 @@ export * from './leave-embargoes.service.js';
12
12
  export * from './leave.service.js';
13
13
  export * from './locations.service.js';
14
14
  export * from './roles.service.js';
15
+ export * from './settings.service.js';
15
16
  export * from './shifts.service.js';
16
17
  export * from './users.service.js';
@@ -1,9 +1,46 @@
1
- import axios, { AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
1
+ import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
2
+ import axiosRetry from 'axios-retry';
2
3
  import { RotaCloud } from '../rotacloud.js';
3
4
  import { Version } from '../version.js';
4
5
 
5
6
  export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
6
7
 
8
+ export enum RetryStrategy {
9
+ Exponential = 'expo',
10
+ Static = 'static',
11
+ }
12
+
13
+ export type RetryOptions =
14
+ | {
15
+ /** Use exponential back-off */
16
+ exponential?: false;
17
+ /** The maximum number of retries before erroring */
18
+ maxRetries: number;
19
+ /** Delay in milliseconds between retry attempts - not used in exponential back-off */
20
+ delay: number;
21
+ }
22
+ | {
23
+ /** Use exponential back-off */
24
+ exponential: true;
25
+ /** The maximum number of retries before erroring */
26
+ maxRetries: number;
27
+ };
28
+
29
+ const DEFAULT_RETRIES = 3;
30
+ const DEFAULT_RETRY_DELAY = 2000;
31
+
32
+ const DEFAULT_RETRY_STRATEGY_OPTIONS: Record<RetryStrategy, RetryOptions> = {
33
+ [RetryStrategy.Exponential]: {
34
+ exponential: true,
35
+ maxRetries: DEFAULT_RETRIES,
36
+ },
37
+ [RetryStrategy.Static]: {
38
+ exponential: false,
39
+ maxRetries: DEFAULT_RETRIES,
40
+ delay: DEFAULT_RETRY_DELAY,
41
+ },
42
+ };
43
+
7
44
  export interface Options {
8
45
  rawResponse?: boolean;
9
46
  expand?: string[];
@@ -22,7 +59,7 @@ type ParameterPrimitive = string | boolean | number | null;
22
59
  type ParameterValue = ParameterPrimitive | ParameterPrimitive[] | undefined;
23
60
 
24
61
  export abstract class Service<ApiResponse = any> {
25
- // rate limit tracking could be implemented here statically
62
+ protected client: AxiosInstance = axios.create();
26
63
 
27
64
  public isLeaveRequest(endpoint?: string): boolean {
28
65
  return endpoint === '/leave_requests';
@@ -80,7 +117,24 @@ export abstract class Service<ApiResponse = any> {
80
117
  },
81
118
  };
82
119
 
83
- const response = await axios.request<T>(reqObject);
120
+ if (RotaCloud.config.retry) {
121
+ const retryConfig =
122
+ typeof RotaCloud.config.retry === 'string'
123
+ ? DEFAULT_RETRY_STRATEGY_OPTIONS[RotaCloud.config.retry]
124
+ : RotaCloud.config.retry;
125
+
126
+ axiosRetry(this.client, {
127
+ retries: retryConfig.maxRetries,
128
+ retryDelay: (retryCount) => {
129
+ if (retryConfig.exponential) {
130
+ return axiosRetry.exponentialDelay(retryCount);
131
+ }
132
+ return retryConfig.delay;
133
+ },
134
+ });
135
+ }
136
+
137
+ const response = await this.client.request<T>(reqObject);
84
138
  return response;
85
139
  }
86
140
 
@@ -0,0 +1,23 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Settings } from '../models/settings.model.js';
3
+ import { Service, Options } from './index.js';
4
+
5
+ import { ApiSettings } from '../interfaces/index.js';
6
+ import { ErrorResponse } from '../models/error-response.model.js';
7
+ import { SettingsQueryParams } from '../rotacloud.js';
8
+
9
+ class SettingsService extends Service {
10
+ private apiPath = '/settings';
11
+
12
+ get(query: SettingsQueryParams): Promise<Settings>;
13
+ get(query: SettingsQueryParams, options: { rawResponse: true } & Options): Promise<AxiosResponse<ApiSettings, any>>;
14
+ get(query: SettingsQueryParams, options: Options): Promise<Settings>;
15
+ get(query: SettingsQueryParams, options?: Options) {
16
+ return super.fetch<ApiSettings>({ url: `${this.apiPath}`, params: query }, options).then(
17
+ (res) => Promise.resolve(options?.rawResponse ? res : new Settings(res.data)),
18
+ (err) => Promise.reject(options?.rawResponse ? err : new ErrorResponse(err))
19
+ );
20
+ }
21
+ }
22
+
23
+ export { SettingsService };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const Version = { version: '1.0.30' };
1
+ export const Version = { version: '1.0.31' };