rotacloud 1.4.5 → 1.4.8

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 (30) hide show
  1. package/dist/cjs/interfaces/document.interface.d.ts +36 -0
  2. package/dist/cjs/interfaces/document.interface.js +2 -0
  3. package/dist/cjs/interfaces/index.d.ts +1 -0
  4. package/dist/cjs/interfaces/index.js +1 -0
  5. package/dist/cjs/interfaces/query-params/documents-query-params.interface.d.ts +1 -1
  6. package/dist/cjs/interfaces/role.interface.d.ts +1 -1
  7. package/dist/cjs/rotacloud.d.ts +2 -0
  8. package/dist/cjs/rotacloud.js +3 -1
  9. package/dist/cjs/services/documents.service.d.ts +73 -0
  10. package/dist/cjs/services/documents.service.js +125 -0
  11. package/dist/cjs/version.js +1 -1
  12. package/dist/mjs/interfaces/document.interface.d.ts +36 -0
  13. package/dist/mjs/interfaces/document.interface.js +1 -0
  14. package/dist/mjs/interfaces/index.d.ts +1 -0
  15. package/dist/mjs/interfaces/index.js +1 -0
  16. package/dist/mjs/interfaces/query-params/documents-query-params.interface.d.ts +1 -1
  17. package/dist/mjs/interfaces/role.interface.d.ts +1 -1
  18. package/dist/mjs/rotacloud.d.ts +2 -0
  19. package/dist/mjs/rotacloud.js +3 -1
  20. package/dist/mjs/services/documents.service.d.ts +73 -0
  21. package/dist/mjs/services/documents.service.js +67 -0
  22. package/dist/mjs/version.js +1 -1
  23. package/package.json +1 -1
  24. package/src/interfaces/document.interface.ts +36 -0
  25. package/src/interfaces/index.ts +1 -0
  26. package/src/interfaces/query-params/documents-query-params.interface.ts +1 -1
  27. package/src/interfaces/role.interface.ts +1 -1
  28. package/src/rotacloud.ts +5 -2
  29. package/src/services/documents.service.ts +142 -0
  30. package/src/version.ts +1 -1
@@ -0,0 +1,36 @@
1
+ export interface Document {
2
+ id: number;
3
+ account_id: number;
4
+ name: string;
5
+ user: number;
6
+ users: number[];
7
+ folder_id: number | null;
8
+ expires: number | null;
9
+ public: boolean;
10
+ created_at: number;
11
+ created_by: number | null;
12
+ deleted: boolean;
13
+ deleted_at: number | null;
14
+ deleted_by: number | null;
15
+ size_kb: number;
16
+ extension: string;
17
+ bucket: string;
18
+ key: string;
19
+ requires_acknowledgement: boolean;
20
+ shared: boolean;
21
+ acknowledgements: {
22
+ id: number;
23
+ accountId: number;
24
+ user: number;
25
+ /** Date in ISO 8601 format */
26
+ acknowledged_at: string;
27
+ }[];
28
+ requires_signing: boolean;
29
+ signature: {
30
+ signature: string;
31
+ /** Date in ISO 8601 format */
32
+ signed_at: string;
33
+ /** IPv4 address */
34
+ ip: string;
35
+ } | null;
36
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -36,3 +36,4 @@ export * from './toil-allowance.interface.js';
36
36
  export * from './user.interface.js';
37
37
  export * from './users-clocked-in.interface.js';
38
38
  export * from './users-clocked-out.interface.js';
39
+ export * from './document.interface.js';
@@ -52,3 +52,4 @@ __exportStar(require("./toil-allowance.interface.js"), exports);
52
52
  __exportStar(require("./user.interface.js"), exports);
53
53
  __exportStar(require("./users-clocked-in.interface.js"), exports);
54
54
  __exportStar(require("./users-clocked-out.interface.js"), exports);
55
+ __exportStar(require("./document.interface.js"), exports);
@@ -1,4 +1,4 @@
1
1
  export interface DocumentsQueryParams {
2
2
  users?: number[];
3
- search?: string;
3
+ company_only?: boolean;
4
4
  }
@@ -2,7 +2,7 @@ export interface Role {
2
2
  id: number;
3
3
  deleted: boolean;
4
4
  name: string;
5
- colour: string;
5
+ colour: string | null;
6
6
  default_break: number;
7
7
  users: number[];
8
8
  pay_code: string;
@@ -1,6 +1,7 @@
1
1
  import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DayNotesService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveTypesService, LeaveService, LocationsService, RolesService, SettingsService, ShiftsService, TerminalsService, TerminalsActiveService, TimeZoneService, ToilAccrualsService, ToilAllowanceService, UsersService, UsersClockInService } from './services/index.js';
2
2
  import { RetryOptions, RetryStrategy, SDKConfig } from './interfaces/index.js';
3
3
  import { PinsService } from './services/pins.service.js';
4
+ import { DocumentsService } from './services/documents.service.js';
4
5
  export declare class RotaCloud {
5
6
  private client;
6
7
  private sdkConfig;
@@ -13,6 +14,7 @@ export declare class RotaCloud {
13
14
  dailyRevenue: DailyRevenueService;
14
15
  dayNotes: DayNotesService;
15
16
  daysOff: DaysOffService;
17
+ documents: DocumentsService;
16
18
  group: GroupsService;
17
19
  leaveEmbargoes: LeaveEmbargoesService;
18
20
  leaveRequests: LeaveRequestService;
@@ -34,6 +34,7 @@ const index_js_2 = require("./interfaces/index.js");
34
34
  Object.defineProperty(exports, "RetryStrategy", { enumerable: true, get: function () { return index_js_2.RetryStrategy; } });
35
35
  const pins_service_js_1 = require("./services/pins.service.js");
36
36
  const index_js_3 = require("./models/index.js");
37
+ const documents_service_js_1 = require("./services/documents.service.js");
37
38
  const DEFAULT_RETRIES = 3;
38
39
  const DEFAULT_RETRY_DELAY = 2000;
39
40
  const DEFAULT_RETRY_STRATEGY_OPTIONS = {
@@ -70,7 +71,7 @@ class RotaCloud {
70
71
  const options = {
71
72
  get config() {
72
73
  return client.config;
73
- }
74
+ },
74
75
  };
75
76
  this.accounts = new index_js_1.AccountsService(this.client, options);
76
77
  this.attendance = new index_js_1.AttendanceService(this.client, options);
@@ -80,6 +81,7 @@ class RotaCloud {
80
81
  this.dailyRevenue = new index_js_1.DailyRevenueService(this.client, options);
81
82
  this.dayNotes = new index_js_1.DayNotesService(this.client, options);
82
83
  this.daysOff = new index_js_1.DaysOffService(this.client, options);
84
+ this.documents = new documents_service_js_1.DocumentsService(this.client, options);
83
85
  this.group = new index_js_1.GroupsService(this.client, options);
84
86
  this.leaveEmbargoes = new index_js_1.LeaveEmbargoesService(this.client, options);
85
87
  this.leaveRequests = new index_js_1.LeaveRequestService(this.client, options);
@@ -0,0 +1,73 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Document } from '../interfaces/index.js';
3
+ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
+ import { DocumentsQueryParams } from '../interfaces/query-params/index.js';
5
+ type RequiredProps = 'name' | 'bucket' | 'key';
6
+ export declare class DocumentsService extends Service<Document> {
7
+ private apiPath;
8
+ create(data: RequirementsOf<Document, RequiredProps>): Promise<Document>;
9
+ create(data: RequirementsOf<Document, RequiredProps>, options: {
10
+ rawResponse: true;
11
+ } & Options): Promise<AxiosResponse<Document>>;
12
+ create(data: RequirementsOf<Document, RequiredProps>, options: Options): Promise<Document>;
13
+ get(id: number): Promise<Document>;
14
+ get<F extends keyof Document>(id: number, options: {
15
+ fields: F[];
16
+ rawResponse: true;
17
+ } & OptionsExtended<Document>): Promise<AxiosResponse<Pick<Document, F>>>;
18
+ get<F extends keyof Document>(id: number, options: {
19
+ fields: F[];
20
+ } & OptionsExtended<Document>): Promise<Pick<Document, F>>;
21
+ get(id: number, options: {
22
+ rawResponse: true;
23
+ } & Options): Promise<AxiosResponse<Document>>;
24
+ get(id: number, options?: OptionsExtended<Document>): Promise<Document>;
25
+ list(query?: DocumentsQueryParams): AsyncGenerator<Document>;
26
+ list<F extends keyof Document>(query: DocumentsQueryParams, options: {
27
+ fields: F[];
28
+ } & OptionsExtended<Document>): AsyncGenerator<Pick<Document, F>>;
29
+ list(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): AsyncGenerator<Document>;
30
+ listAll(query?: DocumentsQueryParams): Promise<Document[]>;
31
+ listAll<F extends keyof Document>(query: DocumentsQueryParams, options: {
32
+ fields: F[];
33
+ } & OptionsExtended<Document>): Promise<Pick<Document, F>[]>;
34
+ listAll(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): Promise<Document[]>;
35
+ listByPage(query?: DocumentsQueryParams): AsyncGenerator<AxiosResponse<Document[]>>;
36
+ listByPage<F extends keyof Document>(query: DocumentsQueryParams, options: {
37
+ fields: F[];
38
+ } & OptionsExtended<Document>): AsyncGenerator<AxiosResponse<Pick<Document, F>[]>>;
39
+ listByPage(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): AsyncGenerator<AxiosResponse<Document[]>>;
40
+ update(document: RequirementsOf<Document, 'id'>): Promise<Document>;
41
+ update(document: RequirementsOf<Document, 'id'>, options: {
42
+ rawResponse: true;
43
+ } & Options): Promise<AxiosResponse<Document>>;
44
+ update(document: RequirementsOf<Document, 'id'>, options: Options): Promise<Document>;
45
+ update(documents: RequirementsOf<Document, 'id'>[]): Promise<{
46
+ success: Document[];
47
+ failed: {
48
+ id: number;
49
+ error: string;
50
+ }[];
51
+ }>;
52
+ update(document: RequirementsOf<Document, 'id'>, options: Options): Promise<Document>;
53
+ update(documents: RequirementsOf<Document, 'id'>[], options: {
54
+ rawResponse: true;
55
+ } & Options): Promise<AxiosResponse<{
56
+ code: number;
57
+ data?: Document;
58
+ error?: string;
59
+ }[]>>;
60
+ update(documents: RequirementsOf<Document, 'id'>[], options: Options): Promise<{
61
+ success: Document[];
62
+ failed: {
63
+ id: number;
64
+ error: string;
65
+ }[];
66
+ }>;
67
+ delete(ids: number | number[]): Promise<number>;
68
+ delete(ids: number | number[], options: {
69
+ rawResponse: true;
70
+ } & Options): Promise<AxiosResponse<void>>;
71
+ delete(ids: number | number[], options: Options): Promise<number>;
72
+ }
73
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
19
+ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
20
+ var i, p;
21
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
22
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
23
+ };
24
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
25
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
26
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
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]); } }
30
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
31
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
32
+ function fulfill(value) { resume("next", value); }
33
+ function reject(value) { resume("throw", value); }
34
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.DocumentsService = void 0;
38
+ const index_js_1 = require("./index.js");
39
+ class DocumentsService extends index_js_1.Service {
40
+ constructor() {
41
+ super(...arguments);
42
+ this.apiPath = '/documents';
43
+ }
44
+ create(data, options) {
45
+ return super
46
+ .fetch({ url: this.apiPath, data, method: 'POST' }, options)
47
+ .then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.data));
48
+ }
49
+ get(id, options) {
50
+ return super
51
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
52
+ .then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.data));
53
+ }
54
+ list(query, options) {
55
+ const _super = Object.create(null, {
56
+ iterator: { get: () => super.iterator }
57
+ });
58
+ return __asyncGenerator(this, arguments, function* list_1() {
59
+ yield __await(yield* __asyncDelegator(__asyncValues(_super.iterator.call(this, { url: this.apiPath, params: query }, options))));
60
+ });
61
+ }
62
+ listAll(query, options) {
63
+ var _a, e_1, _b, _c;
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const shifts = [];
66
+ try {
67
+ for (var _d = true, _e = __asyncValues(this.list(query, options)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
68
+ _c = _f.value;
69
+ _d = false;
70
+ const shift = _c;
71
+ shifts.push(shift);
72
+ }
73
+ }
74
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
+ finally {
76
+ try {
77
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
78
+ }
79
+ finally { if (e_1) throw e_1.error; }
80
+ }
81
+ return shifts;
82
+ });
83
+ }
84
+ listByPage(query, options) {
85
+ return super.iterator({ url: this.apiPath, params: query }, options).byPage();
86
+ }
87
+ update(documents, options) {
88
+ if (!Array.isArray(documents)) {
89
+ return super
90
+ .fetch({
91
+ url: `${this.apiPath}/${documents.id}`,
92
+ data: documents,
93
+ method: 'POST',
94
+ }, options)
95
+ .then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.data));
96
+ }
97
+ return super
98
+ .fetch({
99
+ url: this.apiPath,
100
+ data: documents,
101
+ method: 'POST',
102
+ }, options)
103
+ .then((res) => {
104
+ if (options === null || options === void 0 ? void 0 : options.rawResponse)
105
+ return res;
106
+ const success = [];
107
+ const failed = [];
108
+ for (let documentIdx = 0; documentIdx < res.data.length; documentIdx += 1) {
109
+ const { data, error } = res.data[documentIdx];
110
+ if (data)
111
+ success.push(data);
112
+ if (error)
113
+ failed.push({ id: documents[documentIdx].id, error });
114
+ }
115
+ return { success, failed };
116
+ });
117
+ }
118
+ delete(ids, options) {
119
+ const params = Array.isArray(ids)
120
+ ? { url: this.apiPath, data: { ids }, method: 'DELETE' }
121
+ : { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
122
+ return super.fetch(params, options).then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
123
+ }
124
+ }
125
+ exports.DocumentsService = DocumentsService;
@@ -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.4.5' };
4
+ exports.Version = { version: '1.4.8' };
@@ -0,0 +1,36 @@
1
+ export interface Document {
2
+ id: number;
3
+ account_id: number;
4
+ name: string;
5
+ user: number;
6
+ users: number[];
7
+ folder_id: number | null;
8
+ expires: number | null;
9
+ public: boolean;
10
+ created_at: number;
11
+ created_by: number | null;
12
+ deleted: boolean;
13
+ deleted_at: number | null;
14
+ deleted_by: number | null;
15
+ size_kb: number;
16
+ extension: string;
17
+ bucket: string;
18
+ key: string;
19
+ requires_acknowledgement: boolean;
20
+ shared: boolean;
21
+ acknowledgements: {
22
+ id: number;
23
+ accountId: number;
24
+ user: number;
25
+ /** Date in ISO 8601 format */
26
+ acknowledged_at: string;
27
+ }[];
28
+ requires_signing: boolean;
29
+ signature: {
30
+ signature: string;
31
+ /** Date in ISO 8601 format */
32
+ signed_at: string;
33
+ /** IPv4 address */
34
+ ip: string;
35
+ } | null;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -36,3 +36,4 @@ export * from './toil-allowance.interface.js';
36
36
  export * from './user.interface.js';
37
37
  export * from './users-clocked-in.interface.js';
38
38
  export * from './users-clocked-out.interface.js';
39
+ export * from './document.interface.js';
@@ -36,3 +36,4 @@ export * from './toil-allowance.interface.js';
36
36
  export * from './user.interface.js';
37
37
  export * from './users-clocked-in.interface.js';
38
38
  export * from './users-clocked-out.interface.js';
39
+ export * from './document.interface.js';
@@ -1,4 +1,4 @@
1
1
  export interface DocumentsQueryParams {
2
2
  users?: number[];
3
- search?: string;
3
+ company_only?: boolean;
4
4
  }
@@ -2,7 +2,7 @@ export interface Role {
2
2
  id: number;
3
3
  deleted: boolean;
4
4
  name: string;
5
- colour: string;
5
+ colour: string | null;
6
6
  default_break: number;
7
7
  users: number[];
8
8
  pay_code: string;
@@ -1,6 +1,7 @@
1
1
  import { AccountsService, AttendanceService, AuthService, AvailabilityService, DailyBudgetsService, DailyRevenueService, DayNotesService, DaysOffService, GroupsService, LeaveEmbargoesService, LeaveRequestService, LeaveTypesService, LeaveService, LocationsService, RolesService, SettingsService, ShiftsService, TerminalsService, TerminalsActiveService, TimeZoneService, ToilAccrualsService, ToilAllowanceService, UsersService, UsersClockInService } from './services/index.js';
2
2
  import { RetryOptions, RetryStrategy, SDKConfig } from './interfaces/index.js';
3
3
  import { PinsService } from './services/pins.service.js';
4
+ import { DocumentsService } from './services/documents.service.js';
4
5
  export declare class RotaCloud {
5
6
  private client;
6
7
  private sdkConfig;
@@ -13,6 +14,7 @@ export declare class RotaCloud {
13
14
  dailyRevenue: DailyRevenueService;
14
15
  dayNotes: DayNotesService;
15
16
  daysOff: DaysOffService;
17
+ documents: DocumentsService;
16
18
  group: GroupsService;
17
19
  leaveEmbargoes: LeaveEmbargoesService;
18
20
  leaveRequests: LeaveRequestService;
@@ -4,6 +4,7 @@ import { AccountsService, AttendanceService, AuthService, AvailabilityService, D
4
4
  import { RetryStrategy } from './interfaces/index.js';
5
5
  import { PinsService } from './services/pins.service.js';
6
6
  import { SDKError } from './models/index.js';
7
+ import { DocumentsService } from './services/documents.service.js';
7
8
  const DEFAULT_RETRIES = 3;
8
9
  const DEFAULT_RETRY_DELAY = 2000;
9
10
  const DEFAULT_RETRY_STRATEGY_OPTIONS = {
@@ -39,7 +40,7 @@ export class RotaCloud {
39
40
  const options = {
40
41
  get config() {
41
42
  return client.config;
42
- }
43
+ },
43
44
  };
44
45
  this.accounts = new AccountsService(this.client, options);
45
46
  this.attendance = new AttendanceService(this.client, options);
@@ -49,6 +50,7 @@ export class RotaCloud {
49
50
  this.dailyRevenue = new DailyRevenueService(this.client, options);
50
51
  this.dayNotes = new DayNotesService(this.client, options);
51
52
  this.daysOff = new DaysOffService(this.client, options);
53
+ this.documents = new DocumentsService(this.client, options);
52
54
  this.group = new GroupsService(this.client, options);
53
55
  this.leaveEmbargoes = new LeaveEmbargoesService(this.client, options);
54
56
  this.leaveRequests = new LeaveRequestService(this.client, options);
@@ -0,0 +1,73 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Document } from '../interfaces/index.js';
3
+ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
+ import { DocumentsQueryParams } from '../interfaces/query-params/index.js';
5
+ type RequiredProps = 'name' | 'bucket' | 'key';
6
+ export declare class DocumentsService extends Service<Document> {
7
+ private apiPath;
8
+ create(data: RequirementsOf<Document, RequiredProps>): Promise<Document>;
9
+ create(data: RequirementsOf<Document, RequiredProps>, options: {
10
+ rawResponse: true;
11
+ } & Options): Promise<AxiosResponse<Document>>;
12
+ create(data: RequirementsOf<Document, RequiredProps>, options: Options): Promise<Document>;
13
+ get(id: number): Promise<Document>;
14
+ get<F extends keyof Document>(id: number, options: {
15
+ fields: F[];
16
+ rawResponse: true;
17
+ } & OptionsExtended<Document>): Promise<AxiosResponse<Pick<Document, F>>>;
18
+ get<F extends keyof Document>(id: number, options: {
19
+ fields: F[];
20
+ } & OptionsExtended<Document>): Promise<Pick<Document, F>>;
21
+ get(id: number, options: {
22
+ rawResponse: true;
23
+ } & Options): Promise<AxiosResponse<Document>>;
24
+ get(id: number, options?: OptionsExtended<Document>): Promise<Document>;
25
+ list(query?: DocumentsQueryParams): AsyncGenerator<Document>;
26
+ list<F extends keyof Document>(query: DocumentsQueryParams, options: {
27
+ fields: F[];
28
+ } & OptionsExtended<Document>): AsyncGenerator<Pick<Document, F>>;
29
+ list(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): AsyncGenerator<Document>;
30
+ listAll(query?: DocumentsQueryParams): Promise<Document[]>;
31
+ listAll<F extends keyof Document>(query: DocumentsQueryParams, options: {
32
+ fields: F[];
33
+ } & OptionsExtended<Document>): Promise<Pick<Document, F>[]>;
34
+ listAll(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): Promise<Document[]>;
35
+ listByPage(query?: DocumentsQueryParams): AsyncGenerator<AxiosResponse<Document[]>>;
36
+ listByPage<F extends keyof Document>(query: DocumentsQueryParams, options: {
37
+ fields: F[];
38
+ } & OptionsExtended<Document>): AsyncGenerator<AxiosResponse<Pick<Document, F>[]>>;
39
+ listByPage(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): AsyncGenerator<AxiosResponse<Document[]>>;
40
+ update(document: RequirementsOf<Document, 'id'>): Promise<Document>;
41
+ update(document: RequirementsOf<Document, 'id'>, options: {
42
+ rawResponse: true;
43
+ } & Options): Promise<AxiosResponse<Document>>;
44
+ update(document: RequirementsOf<Document, 'id'>, options: Options): Promise<Document>;
45
+ update(documents: RequirementsOf<Document, 'id'>[]): Promise<{
46
+ success: Document[];
47
+ failed: {
48
+ id: number;
49
+ error: string;
50
+ }[];
51
+ }>;
52
+ update(document: RequirementsOf<Document, 'id'>, options: Options): Promise<Document>;
53
+ update(documents: RequirementsOf<Document, 'id'>[], options: {
54
+ rawResponse: true;
55
+ } & Options): Promise<AxiosResponse<{
56
+ code: number;
57
+ data?: Document;
58
+ error?: string;
59
+ }[]>>;
60
+ update(documents: RequirementsOf<Document, 'id'>[], options: Options): Promise<{
61
+ success: Document[];
62
+ failed: {
63
+ id: number;
64
+ error: string;
65
+ }[];
66
+ }>;
67
+ delete(ids: number | number[]): Promise<number>;
68
+ delete(ids: number | number[], options: {
69
+ rawResponse: true;
70
+ } & Options): Promise<AxiosResponse<void>>;
71
+ delete(ids: number | number[], options: Options): Promise<number>;
72
+ }
73
+ export {};
@@ -0,0 +1,67 @@
1
+ import { Service } from './index.js';
2
+ export class DocumentsService extends Service {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.apiPath = '/documents';
6
+ }
7
+ create(data, options) {
8
+ return super
9
+ .fetch({ url: this.apiPath, data, method: 'POST' }, options)
10
+ .then((res) => (options?.rawResponse ? res : res.data));
11
+ }
12
+ get(id, options) {
13
+ return super
14
+ .fetch({ url: `${this.apiPath}/${id}` }, options)
15
+ .then((res) => (options?.rawResponse ? res : res.data));
16
+ }
17
+ async *list(query, options) {
18
+ yield* super.iterator({ url: this.apiPath, params: query }, options);
19
+ }
20
+ async listAll(query, options) {
21
+ const shifts = [];
22
+ for await (const shift of this.list(query, options)) {
23
+ shifts.push(shift);
24
+ }
25
+ return shifts;
26
+ }
27
+ listByPage(query, options) {
28
+ return super.iterator({ url: this.apiPath, params: query }, options).byPage();
29
+ }
30
+ update(documents, options) {
31
+ if (!Array.isArray(documents)) {
32
+ return super
33
+ .fetch({
34
+ url: `${this.apiPath}/${documents.id}`,
35
+ data: documents,
36
+ method: 'POST',
37
+ }, options)
38
+ .then((res) => (options?.rawResponse ? res : res.data));
39
+ }
40
+ return super
41
+ .fetch({
42
+ url: this.apiPath,
43
+ data: documents,
44
+ method: 'POST',
45
+ }, options)
46
+ .then((res) => {
47
+ if (options?.rawResponse)
48
+ return res;
49
+ const success = [];
50
+ const failed = [];
51
+ for (let documentIdx = 0; documentIdx < res.data.length; documentIdx += 1) {
52
+ const { data, error } = res.data[documentIdx];
53
+ if (data)
54
+ success.push(data);
55
+ if (error)
56
+ failed.push({ id: documents[documentIdx].id, error });
57
+ }
58
+ return { success, failed };
59
+ });
60
+ }
61
+ delete(ids, options) {
62
+ const params = Array.isArray(ids)
63
+ ? { url: this.apiPath, data: { ids }, method: 'DELETE' }
64
+ : { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
65
+ return super.fetch(params, options).then((res) => (options?.rawResponse ? res : res.status));
66
+ }
67
+ }
@@ -1 +1 @@
1
- export const Version = { version: '1.4.5' };
1
+ export const Version = { version: '1.4.8' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rotacloud",
3
- "version": "1.4.5",
3
+ "version": "1.4.8",
4
4
  "description": "The RotaCloud SDK for the RotaCloud API",
5
5
  "engines": {
6
6
  "node": ">=16.10.0"
@@ -0,0 +1,36 @@
1
+ export interface Document {
2
+ id: number;
3
+ account_id: number;
4
+ name: string;
5
+ user: number;
6
+ users: number[];
7
+ folder_id: number | null;
8
+ expires: number | null;
9
+ public: boolean;
10
+ created_at: number;
11
+ created_by: number | null;
12
+ deleted: boolean;
13
+ deleted_at: number | null;
14
+ deleted_by: number | null;
15
+ size_kb: number;
16
+ extension: string;
17
+ bucket: string;
18
+ key: string;
19
+ requires_acknowledgement: boolean;
20
+ shared: boolean;
21
+ acknowledgements: {
22
+ id: number;
23
+ accountId: number;
24
+ user: number;
25
+ /** Date in ISO 8601 format */
26
+ acknowledged_at: string;
27
+ }[];
28
+ requires_signing: boolean;
29
+ signature: {
30
+ signature: string;
31
+ /** Date in ISO 8601 format */
32
+ signed_at: string;
33
+ /** IPv4 address */
34
+ ip: string;
35
+ } | null;
36
+ }
@@ -36,3 +36,4 @@ export * from './toil-allowance.interface.js';
36
36
  export * from './user.interface.js';
37
37
  export * from './users-clocked-in.interface.js';
38
38
  export * from './users-clocked-out.interface.js';
39
+ export * from './document.interface.js';
@@ -1,4 +1,4 @@
1
1
  export interface DocumentsQueryParams {
2
2
  users?: number[];
3
- search?: string;
3
+ company_only?: boolean;
4
4
  }
@@ -2,7 +2,7 @@ export interface Role {
2
2
  id: number;
3
3
  deleted: boolean;
4
4
  name: string;
5
- colour: string;
5
+ colour: string | null;
6
6
  default_break: number;
7
7
  users: number[];
8
8
  pay_code: string;
package/src/rotacloud.ts CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  import { RetryOptions, RetryStrategy, SDKBase, SDKConfig } from './interfaces/index.js';
30
30
  import { PinsService } from './services/pins.service.js';
31
31
  import { SDKError } from './models/index.js';
32
+ import { DocumentsService } from './services/documents.service.js';
32
33
 
33
34
  const DEFAULT_RETRIES = 3;
34
35
  const DEFAULT_RETRY_DELAY = 2000;
@@ -73,6 +74,7 @@ export class RotaCloud {
73
74
  dailyRevenue: DailyRevenueService;
74
75
  dayNotes: DayNotesService;
75
76
  daysOff: DaysOffService;
77
+ documents: DocumentsService;
76
78
  group: GroupsService;
77
79
  leaveEmbargoes: LeaveEmbargoesService;
78
80
  leaveRequests: LeaveRequestService;
@@ -97,8 +99,8 @@ export class RotaCloud {
97
99
  const options = {
98
100
  get config(): SDKConfig {
99
101
  return client.config;
100
- }
101
- }
102
+ },
103
+ };
102
104
 
103
105
  this.accounts = new AccountsService(this.client, options);
104
106
  this.attendance = new AttendanceService(this.client, options);
@@ -108,6 +110,7 @@ export class RotaCloud {
108
110
  this.dailyRevenue = new DailyRevenueService(this.client, options);
109
111
  this.dayNotes = new DayNotesService(this.client, options);
110
112
  this.daysOff = new DaysOffService(this.client, options);
113
+ this.documents = new DocumentsService(this.client, options);
111
114
  this.group = new GroupsService(this.client, options);
112
115
  this.leaveEmbargoes = new LeaveEmbargoesService(this.client, options);
113
116
  this.leaveRequests = new LeaveRequestService(this.client, options);
@@ -0,0 +1,142 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { Document } from '../interfaces/index.js';
3
+ import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
4
+ import { DocumentsQueryParams } from '../interfaces/query-params/index.js';
5
+
6
+ type RequiredProps = 'name' | 'bucket' | 'key';
7
+
8
+ export class DocumentsService extends Service<Document> {
9
+ private apiPath = '/documents';
10
+
11
+ create(data: RequirementsOf<Document, RequiredProps>): Promise<Document>;
12
+ create(
13
+ data: RequirementsOf<Document, RequiredProps>,
14
+ options: { rawResponse: true } & Options,
15
+ ): Promise<AxiosResponse<Document>>;
16
+ create(data: RequirementsOf<Document, RequiredProps>, options: Options): Promise<Document>;
17
+ create(data: RequirementsOf<Document, RequiredProps>, options?: Options) {
18
+ return super
19
+ .fetch<Document>({ url: this.apiPath, data, method: 'POST' }, options)
20
+ .then((res) => (options?.rawResponse ? res : res.data));
21
+ }
22
+
23
+ get(id: number): Promise<Document>;
24
+ get<F extends keyof Document>(
25
+ id: number,
26
+ options: { fields: F[]; rawResponse: true } & OptionsExtended<Document>,
27
+ ): Promise<AxiosResponse<Pick<Document, F>>>;
28
+ get<F extends keyof Document>(
29
+ id: number,
30
+ options: { fields: F[] } & OptionsExtended<Document>,
31
+ ): Promise<Pick<Document, F>>;
32
+ get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Document>>;
33
+ get(id: number, options?: OptionsExtended<Document>): Promise<Document>;
34
+ get(id: number, options?: OptionsExtended<Document>) {
35
+ return super
36
+ .fetch<Document>({ url: `${this.apiPath}/${id}` }, options)
37
+ .then((res) => (options?.rawResponse ? res : res.data));
38
+ }
39
+
40
+ list(query?: DocumentsQueryParams): AsyncGenerator<Document>;
41
+ list<F extends keyof Document>(
42
+ query: DocumentsQueryParams,
43
+ options: { fields: F[] } & OptionsExtended<Document>,
44
+ ): AsyncGenerator<Pick<Document, F>>;
45
+ list(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): AsyncGenerator<Document>;
46
+ async *list(query?: DocumentsQueryParams, options?: OptionsExtended<Document>) {
47
+ yield* super.iterator({ url: this.apiPath, params: query }, options);
48
+ }
49
+
50
+ listAll(query?: DocumentsQueryParams): Promise<Document[]>;
51
+ listAll<F extends keyof Document>(
52
+ query: DocumentsQueryParams,
53
+ options: { fields: F[] } & OptionsExtended<Document>,
54
+ ): Promise<Pick<Document, F>[]>;
55
+ listAll(query?: DocumentsQueryParams, options?: OptionsExtended<Document>): Promise<Document[]>;
56
+ async listAll(query?: DocumentsQueryParams, options?: OptionsExtended<Document>) {
57
+ const shifts = [] as Document[];
58
+ for await (const shift of this.list(query, options)) {
59
+ shifts.push(shift);
60
+ }
61
+ return shifts;
62
+ }
63
+
64
+ listByPage(query?: DocumentsQueryParams): AsyncGenerator<AxiosResponse<Document[]>>;
65
+ listByPage<F extends keyof Document>(
66
+ query: DocumentsQueryParams,
67
+ options: { fields: F[] } & OptionsExtended<Document>,
68
+ ): AsyncGenerator<AxiosResponse<Pick<Document, F>[]>>;
69
+ listByPage(
70
+ query?: DocumentsQueryParams,
71
+ options?: OptionsExtended<Document>,
72
+ ): AsyncGenerator<AxiosResponse<Document[]>>;
73
+ listByPage(query?: DocumentsQueryParams, options?: OptionsExtended<Document>) {
74
+ return super.iterator<Document>({ url: this.apiPath, params: query }, options).byPage();
75
+ }
76
+
77
+ update(document: RequirementsOf<Document, 'id'>): Promise<Document>;
78
+ update(
79
+ document: RequirementsOf<Document, 'id'>,
80
+ options: { rawResponse: true } & Options,
81
+ ): Promise<AxiosResponse<Document>>;
82
+ update(document: RequirementsOf<Document, 'id'>, options: Options): Promise<Document>;
83
+ update(
84
+ documents: RequirementsOf<Document, 'id'>[],
85
+ ): Promise<{ success: Document[]; failed: { id: number; error: string }[] }>;
86
+ update(document: RequirementsOf<Document, 'id'>, options: Options): Promise<Document>;
87
+ update(
88
+ documents: RequirementsOf<Document, 'id'>[],
89
+ options: { rawResponse: true } & Options,
90
+ ): Promise<AxiosResponse<{ code: number; data?: Document; error?: string }[]>>;
91
+ update(
92
+ documents: RequirementsOf<Document, 'id'>[],
93
+ options: Options,
94
+ ): Promise<{ success: Document[]; failed: { id: number; error: string }[] }>;
95
+ update(documents: RequirementsOf<Document, 'id'> | RequirementsOf<Document, 'id'>[], options?: Options) {
96
+ if (!Array.isArray(documents)) {
97
+ return super
98
+ .fetch<Document>(
99
+ {
100
+ url: `${this.apiPath}/${documents.id}`,
101
+ data: documents,
102
+ method: 'POST',
103
+ },
104
+ options,
105
+ )
106
+ .then((res) => (options?.rawResponse ? res : res.data));
107
+ }
108
+
109
+ return super
110
+ .fetch<{ code: number; data?: Document; error?: string }[]>(
111
+ {
112
+ url: this.apiPath,
113
+ data: documents,
114
+ method: 'POST',
115
+ },
116
+ options,
117
+ )
118
+ .then((res) => {
119
+ if (options?.rawResponse) return res;
120
+
121
+ const success: Document[] = [];
122
+ const failed: { id: number; error: string }[] = [];
123
+ for (let documentIdx = 0; documentIdx < res.data.length; documentIdx += 1) {
124
+ const { data, error } = res.data[documentIdx];
125
+ if (data) success.push(data);
126
+ if (error) failed.push({ id: documents[documentIdx].id, error });
127
+ }
128
+ return { success, failed };
129
+ });
130
+ }
131
+
132
+ delete(ids: number | number[]): Promise<number>;
133
+ delete(ids: number | number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
134
+ delete(ids: number | number[], options: Options): Promise<number>;
135
+ delete(ids: number | number[], options?: Options) {
136
+ const params: AxiosRequestConfig = Array.isArray(ids)
137
+ ? { url: this.apiPath, data: { ids }, method: 'DELETE' }
138
+ : { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
139
+
140
+ return super.fetch<void>(params, options).then((res) => (options?.rawResponse ? res : res.status));
141
+ }
142
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const Version = { version: '1.4.5' };
1
+ export const Version = { version: '1.4.8' };