@rentcheck/biz 1.0.177 → 1.0.179

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/constants/index.d.ts +1 -0
  2. package/dist/constants/index.js +2 -1
  3. package/dist/constants/sync-info.d.ts +1 -0
  4. package/dist/constants/sync-info.js +4 -0
  5. package/dist/errors/admin.d.ts +10 -0
  6. package/dist/errors/admin.js +22 -0
  7. package/dist/errors/automations.d.ts +13 -0
  8. package/dist/errors/automations.js +28 -0
  9. package/dist/errors/http.d.ts +19 -0
  10. package/dist/errors/http.js +40 -0
  11. package/dist/errors/imports.d.ts +13 -0
  12. package/dist/errors/imports.js +28 -0
  13. package/dist/errors/index.d.ts +19 -0
  14. package/dist/errors/index.js +48 -0
  15. package/dist/errors/inspection-invites.d.ts +4 -0
  16. package/dist/errors/inspection-invites.js +10 -0
  17. package/dist/errors/integrations.d.ts +10 -0
  18. package/dist/errors/integrations.js +22 -0
  19. package/dist/errors/permission-groups.d.ts +4 -0
  20. package/dist/errors/permission-groups.js +10 -0
  21. package/dist/errors/propexo.d.ts +20 -0
  22. package/dist/errors/propexo.js +41 -0
  23. package/dist/errors/subscriptions.d.ts +4 -0
  24. package/dist/errors/subscriptions.js +10 -0
  25. package/dist/errors/take-over-requests.d.ts +7 -0
  26. package/dist/errors/take-over-requests.js +16 -0
  27. package/dist/errors/validations.d.ts +19 -0
  28. package/dist/errors/validations.js +40 -0
  29. package/dist/errors/zapier.d.ts +7 -0
  30. package/dist/errors/zapier.js +16 -0
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.js +2 -1
  33. package/dist/permissions/inspections.d.ts +6 -1
  34. package/dist/permissions/inspections.js +39 -1
  35. package/dist/rules/inspections/index.d.ts +2 -1
  36. package/dist/rules/inspections/index.js +26 -3
  37. package/dist/rules/properties/index.d.ts +7 -0
  38. package/dist/rules/properties/index.js +11 -1
  39. package/dist/rules/work-orders/index.d.ts +11 -14
  40. package/dist/rules/work-orders/index.js +53 -45
  41. package/dist/utils/properties/index.js +6 -2
  42. package/dist/utils/properties/validations.d.ts +8 -1
  43. package/dist/utils/properties/validations.js +23 -1
  44. package/package.json +1 -1
  45. package/src/constants/index.ts +1 -0
  46. package/src/constants/sync-info.ts +1 -0
  47. package/src/errors/admin.ts +19 -0
  48. package/src/errors/automations.ts +25 -0
  49. package/src/errors/http.ts +37 -0
  50. package/src/errors/imports.ts +29 -0
  51. package/src/errors/index.ts +24 -0
  52. package/src/errors/inspection-invites.ts +7 -0
  53. package/src/errors/integrations.ts +19 -0
  54. package/src/errors/permission-groups.ts +7 -0
  55. package/src/errors/propexo.ts +37 -0
  56. package/src/errors/subscriptions.ts +7 -0
  57. package/src/errors/take-over-requests.ts +15 -0
  58. package/src/errors/validations.ts +40 -0
  59. package/src/errors/zapier.ts +13 -0
  60. package/src/index.ts +1 -0
  61. package/src/permissions/inspections.ts +52 -0
  62. package/src/rules/inspections/index.ts +38 -2
  63. package/src/rules/properties/index.ts +10 -0
  64. package/src/rules/work-orders/index.ts +94 -44
  65. package/src/utils/properties/index.ts +7 -2
  66. package/src/utils/properties/validations.ts +34 -0
  67. package/tsconfig.tsbuildinfo +1 -1
@@ -5,3 +5,4 @@ export * as Plans from './plans';
5
5
  export * as Rooms from './rooms';
6
6
  export * as Skills from './skills';
7
7
  export * as UserSettings from './user-settings';
8
+ export * as SyncInfo from './sync-info';
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.UserSettings = exports.Skills = exports.Rooms = exports.Plans = exports.NotificationPreferences = exports.Emails = exports.Addons = void 0;
26
+ exports.SyncInfo = exports.UserSettings = exports.Skills = exports.Rooms = exports.Plans = exports.NotificationPreferences = exports.Emails = exports.Addons = void 0;
27
27
  exports.Addons = __importStar(require("./addons"));
28
28
  exports.Emails = __importStar(require("./emails"));
29
29
  exports.NotificationPreferences = __importStar(require("./notification-preferences"));
@@ -31,3 +31,4 @@ exports.Plans = __importStar(require("./plans"));
31
31
  exports.Rooms = __importStar(require("./rooms"));
32
32
  exports.Skills = __importStar(require("./skills"));
33
33
  exports.UserSettings = __importStar(require("./user-settings"));
34
+ exports.SyncInfo = __importStar(require("./sync-info"));
@@ -0,0 +1 @@
1
+ export declare const propertySyncExpirationDays = 7;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.propertySyncExpirationDays = void 0;
4
+ exports.propertySyncExpirationDays = 7;
@@ -0,0 +1,10 @@
1
+ import { BadRequest } from './http';
2
+ export declare class DocumentWithNoTeam extends BadRequest {
3
+ constructor(collection: 'inspection' | 'property');
4
+ }
5
+ export declare class InspectionWithoutRenter extends BadRequest {
6
+ constructor();
7
+ }
8
+ export declare class InspectionRestore extends BadRequest {
9
+ constructor(reason: string);
10
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InspectionRestore = exports.InspectionWithoutRenter = exports.DocumentWithNoTeam = void 0;
4
+ const http_1 = require("./http");
5
+ class DocumentWithNoTeam extends http_1.BadRequest {
6
+ constructor(collection) {
7
+ super(`The ${collection} is not part of any teams`);
8
+ }
9
+ }
10
+ exports.DocumentWithNoTeam = DocumentWithNoTeam;
11
+ class InspectionWithoutRenter extends http_1.BadRequest {
12
+ constructor() {
13
+ super('Inspection does not have a renter');
14
+ }
15
+ }
16
+ exports.InspectionWithoutRenter = InspectionWithoutRenter;
17
+ class InspectionRestore extends http_1.BadRequest {
18
+ constructor(reason) {
19
+ super(`Inspection cannot be restored - ${reason}`);
20
+ }
21
+ }
22
+ exports.InspectionRestore = InspectionRestore;
@@ -0,0 +1,13 @@
1
+ import { BadRequest, NotFound } from './http';
2
+ export declare class NoTeammateForTeam extends BadRequest {
3
+ constructor();
4
+ }
5
+ export declare class InspectionTemplateNotPublished extends BadRequest {
6
+ constructor();
7
+ }
8
+ export declare class InspectionTemplateDeleted extends NotFound {
9
+ constructor();
10
+ }
11
+ export declare class InspectionTemplateNoFastTrack extends BadRequest {
12
+ constructor();
13
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InspectionTemplateNoFastTrack = exports.InspectionTemplateDeleted = exports.InspectionTemplateNotPublished = exports.NoTeammateForTeam = void 0;
4
+ const http_1 = require("./http");
5
+ class NoTeammateForTeam extends http_1.BadRequest {
6
+ constructor() {
7
+ super('a teammate must be provided for all teams');
8
+ }
9
+ }
10
+ exports.NoTeammateForTeam = NoTeammateForTeam;
11
+ class InspectionTemplateNotPublished extends http_1.BadRequest {
12
+ constructor() {
13
+ super('inspection template not published');
14
+ }
15
+ }
16
+ exports.InspectionTemplateNotPublished = InspectionTemplateNotPublished;
17
+ class InspectionTemplateDeleted extends http_1.NotFound {
18
+ constructor() {
19
+ super('Selected inspection template has been deleted');
20
+ }
21
+ }
22
+ exports.InspectionTemplateDeleted = InspectionTemplateDeleted;
23
+ class InspectionTemplateNoFastTrack extends http_1.BadRequest {
24
+ constructor() {
25
+ super('fast track not enabled for this inspection template');
26
+ }
27
+ }
28
+ exports.InspectionTemplateNoFastTrack = InspectionTemplateNoFastTrack;
@@ -0,0 +1,19 @@
1
+ import { RentCheckException } from '.';
2
+ export declare class BadRequest extends RentCheckException {
3
+ constructor(message: string);
4
+ }
5
+ export declare class Unauthorized extends RentCheckException {
6
+ constructor(message?: string);
7
+ }
8
+ export declare class Forbidden extends RentCheckException {
9
+ constructor(message?: string);
10
+ }
11
+ export declare class NotFound extends RentCheckException {
12
+ constructor(documentName: string, id?: string);
13
+ }
14
+ export declare class MethodNotAllowed extends RentCheckException {
15
+ constructor();
16
+ }
17
+ export declare class Conflict extends RentCheckException {
18
+ constructor(message?: string, resource?: string);
19
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Conflict = exports.MethodNotAllowed = exports.NotFound = exports.Forbidden = exports.Unauthorized = exports.BadRequest = void 0;
4
+ const _1 = require(".");
5
+ class BadRequest extends _1.RentCheckException {
6
+ constructor(message) {
7
+ super(message, 400);
8
+ }
9
+ }
10
+ exports.BadRequest = BadRequest;
11
+ class Unauthorized extends _1.RentCheckException {
12
+ constructor(message) {
13
+ super(message !== null && message !== void 0 ? message : 'unauthorized', 401);
14
+ }
15
+ }
16
+ exports.Unauthorized = Unauthorized;
17
+ class Forbidden extends _1.RentCheckException {
18
+ constructor(message) {
19
+ super(message !== null && message !== void 0 ? message : 'forbidden', 403);
20
+ }
21
+ }
22
+ exports.Forbidden = Forbidden;
23
+ class NotFound extends _1.RentCheckException {
24
+ constructor(documentName, id) {
25
+ super(`${documentName} not found${id ? ` (${id})` : ''}`, 404);
26
+ }
27
+ }
28
+ exports.NotFound = NotFound;
29
+ class MethodNotAllowed extends _1.RentCheckException {
30
+ constructor() {
31
+ super('method not allowed', 405);
32
+ }
33
+ }
34
+ exports.MethodNotAllowed = MethodNotAllowed;
35
+ class Conflict extends _1.RentCheckException {
36
+ constructor(message, resource) {
37
+ super(message !== null && message !== void 0 ? message : `conflict${resource ? ` on ${resource}` : ''}`, 409);
38
+ }
39
+ }
40
+ exports.Conflict = Conflict;
@@ -0,0 +1,13 @@
1
+ import { BadRequest } from './http';
2
+ export declare class InvalidImportModel extends BadRequest {
3
+ constructor(model?: string);
4
+ }
5
+ export declare class OperationNotSupportedForModel extends BadRequest {
6
+ constructor(operation: string, model: string);
7
+ }
8
+ export declare class InvalidMoveDates extends BadRequest {
9
+ constructor(startDate: string, endDate: string, fullName: string);
10
+ }
11
+ export declare class InvalidLeaseDates extends BadRequest {
12
+ constructor(startDate: string, endDate: string, fullName: string);
13
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidLeaseDates = exports.InvalidMoveDates = exports.OperationNotSupportedForModel = exports.InvalidImportModel = void 0;
4
+ const http_1 = require("./http");
5
+ class InvalidImportModel extends http_1.BadRequest {
6
+ constructor(model) {
7
+ super(`invalid import model ${model}`);
8
+ }
9
+ }
10
+ exports.InvalidImportModel = InvalidImportModel;
11
+ class OperationNotSupportedForModel extends http_1.BadRequest {
12
+ constructor(operation, model) {
13
+ super(`operation ${operation} is not supported for model ${model}`);
14
+ }
15
+ }
16
+ exports.OperationNotSupportedForModel = OperationNotSupportedForModel;
17
+ class InvalidMoveDates extends http_1.BadRequest {
18
+ constructor(startDate, endDate, fullName) {
19
+ super(`Invalid move dates for ${fullName}: move-in (${startDate}) after move-out (${endDate})`);
20
+ }
21
+ }
22
+ exports.InvalidMoveDates = InvalidMoveDates;
23
+ class InvalidLeaseDates extends http_1.BadRequest {
24
+ constructor(startDate, endDate, fullName) {
25
+ super(`Invalid lease dates for ${fullName}: lease start (${startDate}) after lease end (${endDate})`);
26
+ }
27
+ }
28
+ exports.InvalidLeaseDates = InvalidLeaseDates;
@@ -0,0 +1,19 @@
1
+ export declare class RentCheckException extends Error {
2
+ /**
3
+ * Status code to return to the client. For example 404 for not found.
4
+ */
5
+ statusCode: number;
6
+ constructor(message: string, statusCode: number);
7
+ }
8
+ export * from './http';
9
+ export * as Admin from './admin';
10
+ export * as Automations from './automations';
11
+ export * as Imports from './imports';
12
+ export * as InspectionInvites from './inspection-invites';
13
+ export * as Integrations from './integrations';
14
+ export * as PermissionGroups from './permission-groups';
15
+ export * as Propexo from './propexo';
16
+ export * as Subscriptions from './subscriptions';
17
+ export * as TakeOverRequests from './take-over-requests';
18
+ export * as Validations from './validations';
19
+ export * as Zapier from './zapier';
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Zapier = exports.Validations = exports.TakeOverRequests = exports.Subscriptions = exports.Propexo = exports.PermissionGroups = exports.Integrations = exports.InspectionInvites = exports.Imports = exports.Automations = exports.Admin = exports.RentCheckException = void 0;
30
+ class RentCheckException extends Error {
31
+ constructor(message, statusCode) {
32
+ super(message);
33
+ this.statusCode = statusCode;
34
+ }
35
+ }
36
+ exports.RentCheckException = RentCheckException;
37
+ __exportStar(require("./http"), exports);
38
+ exports.Admin = __importStar(require("./admin"));
39
+ exports.Automations = __importStar(require("./automations"));
40
+ exports.Imports = __importStar(require("./imports"));
41
+ exports.InspectionInvites = __importStar(require("./inspection-invites"));
42
+ exports.Integrations = __importStar(require("./integrations"));
43
+ exports.PermissionGroups = __importStar(require("./permission-groups"));
44
+ exports.Propexo = __importStar(require("./propexo"));
45
+ exports.Subscriptions = __importStar(require("./subscriptions"));
46
+ exports.TakeOverRequests = __importStar(require("./take-over-requests"));
47
+ exports.Validations = __importStar(require("./validations"));
48
+ exports.Zapier = __importStar(require("./zapier"));
@@ -0,0 +1,4 @@
1
+ import { Conflict } from './http';
2
+ export declare class AlreadyClaimed extends Conflict {
3
+ constructor();
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlreadyClaimed = void 0;
4
+ const http_1 = require("./http");
5
+ class AlreadyClaimed extends http_1.Conflict {
6
+ constructor() {
7
+ super(`This invite code has already been claimed by another user.`);
8
+ }
9
+ }
10
+ exports.AlreadyClaimed = AlreadyClaimed;
@@ -0,0 +1,10 @@
1
+ import { BadRequest } from './http';
2
+ export declare class IntegrationAlreadyExists extends BadRequest {
3
+ constructor();
4
+ }
5
+ export declare class IntegrationAlreadyExistsForSubscription extends BadRequest {
6
+ constructor();
7
+ }
8
+ export declare class InvalidCredentials extends BadRequest {
9
+ constructor();
10
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidCredentials = exports.IntegrationAlreadyExistsForSubscription = exports.IntegrationAlreadyExists = void 0;
4
+ const http_1 = require("./http");
5
+ class IntegrationAlreadyExists extends http_1.BadRequest {
6
+ constructor() {
7
+ super(`integration already exist for client_id and client_secret`);
8
+ }
9
+ }
10
+ exports.IntegrationAlreadyExists = IntegrationAlreadyExists;
11
+ class IntegrationAlreadyExistsForSubscription extends http_1.BadRequest {
12
+ constructor() {
13
+ super(`integration already exist for subscription`);
14
+ }
15
+ }
16
+ exports.IntegrationAlreadyExistsForSubscription = IntegrationAlreadyExistsForSubscription;
17
+ class InvalidCredentials extends http_1.BadRequest {
18
+ constructor() {
19
+ super('invalid credentials');
20
+ }
21
+ }
22
+ exports.InvalidCredentials = InvalidCredentials;
@@ -0,0 +1,4 @@
1
+ import { Forbidden } from './http';
2
+ export declare class DeleteRemainingGroups extends Forbidden {
3
+ constructor();
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeleteRemainingGroups = void 0;
4
+ const http_1 = require("./http");
5
+ class DeleteRemainingGroups extends http_1.Forbidden {
6
+ constructor() {
7
+ super(`At least one permission group must remain on the subscription`);
8
+ }
9
+ }
10
+ exports.DeleteRemainingGroups = DeleteRemainingGroups;
@@ -0,0 +1,20 @@
1
+ import { RentmanagerIntegration } from '@rentcheck/types';
2
+ import { RentCheckException } from '.';
3
+ export declare class PropexoSyncError extends RentCheckException {
4
+ name: string;
5
+ }
6
+ export declare class IntegrationNotFound extends PropexoSyncError {
7
+ constructor(id: RentmanagerIntegration['id']);
8
+ }
9
+ export declare class LocationNotEnabled extends PropexoSyncError {
10
+ constructor(id: RentmanagerIntegration['enabled_locations'][number]['id']);
11
+ }
12
+ export declare class LocationNotMapped extends PropexoSyncError {
13
+ constructor(id: RentmanagerIntegration['enabled_locations'][number]['id']);
14
+ }
15
+ export declare class IntegrationWithNoSyncDetails extends PropexoSyncError {
16
+ constructor();
17
+ }
18
+ export declare class IntegrationWithNoTeamMappings extends PropexoSyncError {
19
+ constructor();
20
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegrationWithNoTeamMappings = exports.IntegrationWithNoSyncDetails = exports.LocationNotMapped = exports.LocationNotEnabled = exports.IntegrationNotFound = exports.PropexoSyncError = void 0;
4
+ const _1 = require(".");
5
+ class PropexoSyncError extends _1.RentCheckException {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.name = 'PropexoSyncError';
9
+ }
10
+ }
11
+ exports.PropexoSyncError = PropexoSyncError;
12
+ class IntegrationNotFound extends PropexoSyncError {
13
+ constructor(id) {
14
+ super(`invalid rentmanager integration "${id}"`, 404);
15
+ }
16
+ }
17
+ exports.IntegrationNotFound = IntegrationNotFound;
18
+ class LocationNotEnabled extends PropexoSyncError {
19
+ constructor(id) {
20
+ super(`location not enabled "${id}"`, 400);
21
+ }
22
+ }
23
+ exports.LocationNotEnabled = LocationNotEnabled;
24
+ class LocationNotMapped extends PropexoSyncError {
25
+ constructor(id) {
26
+ super(`location not mapped "${id}"`, 400);
27
+ }
28
+ }
29
+ exports.LocationNotMapped = LocationNotMapped;
30
+ class IntegrationWithNoSyncDetails extends PropexoSyncError {
31
+ constructor() {
32
+ super('integration with no sync details', 400);
33
+ }
34
+ }
35
+ exports.IntegrationWithNoSyncDetails = IntegrationWithNoSyncDetails;
36
+ class IntegrationWithNoTeamMappings extends PropexoSyncError {
37
+ constructor() {
38
+ super('Integration with no team mappings', 400);
39
+ }
40
+ }
41
+ exports.IntegrationWithNoTeamMappings = IntegrationWithNoTeamMappings;
@@ -0,0 +1,4 @@
1
+ import { Conflict } from '.';
2
+ export declare class TooMany extends Conflict {
3
+ constructor();
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TooMany = void 0;
4
+ const _1 = require(".");
5
+ class TooMany extends _1.Conflict {
6
+ constructor() {
7
+ super('too many subscriptions');
8
+ }
9
+ }
10
+ exports.TooMany = TooMany;
@@ -0,0 +1,7 @@
1
+ import { BadRequest } from './http';
2
+ export declare class InvalidRequest extends BadRequest {
3
+ constructor(requestId: string, inspectionId: string);
4
+ }
5
+ export declare class InvalidInspectionStatus extends BadRequest {
6
+ constructor(status: string);
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidInspectionStatus = exports.InvalidRequest = void 0;
4
+ const http_1 = require("./http");
5
+ class InvalidRequest extends http_1.BadRequest {
6
+ constructor(requestId, inspectionId) {
7
+ super(`request ${requestId} isn't valid for inspection ${inspectionId}`);
8
+ }
9
+ }
10
+ exports.InvalidRequest = InvalidRequest;
11
+ class InvalidInspectionStatus extends http_1.BadRequest {
12
+ constructor(status) {
13
+ super(`inspection must have status "Continue Inspection", got ${status} instead`);
14
+ }
15
+ }
16
+ exports.InvalidInspectionStatus = InvalidInspectionStatus;
@@ -0,0 +1,19 @@
1
+ import { BadRequest, Unauthorized } from './http';
2
+ export declare class BlankField extends BadRequest {
3
+ constructor(field: string);
4
+ }
5
+ export declare class MissingField extends BadRequest {
6
+ constructor(field: string);
7
+ }
8
+ export declare class InvalidValue extends BadRequest {
9
+ constructor(field: string, value?: string);
10
+ }
11
+ export declare class MissingPermissions extends Unauthorized {
12
+ constructor(action: 'create' | 'update' | 'delete' | 'get', resource: string);
13
+ }
14
+ export declare class UnsupportedValue extends BadRequest {
15
+ constructor(value?: string);
16
+ }
17
+ export declare class NotArray extends BadRequest {
18
+ constructor(field?: string);
19
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotArray = exports.UnsupportedValue = exports.MissingPermissions = exports.InvalidValue = exports.MissingField = exports.BlankField = void 0;
4
+ const http_1 = require("./http");
5
+ class BlankField extends http_1.BadRequest {
6
+ constructor(field) {
7
+ super(`${field} can not be empty`);
8
+ }
9
+ }
10
+ exports.BlankField = BlankField;
11
+ class MissingField extends http_1.BadRequest {
12
+ constructor(field) {
13
+ super(`${field} is missing`);
14
+ }
15
+ }
16
+ exports.MissingField = MissingField;
17
+ class InvalidValue extends http_1.BadRequest {
18
+ constructor(field, value) {
19
+ super(`${field} has an invalid value${value ? `: ${value}` : ''}`);
20
+ }
21
+ }
22
+ exports.InvalidValue = InvalidValue;
23
+ class MissingPermissions extends http_1.Unauthorized {
24
+ constructor(action, resource) {
25
+ super(`User does not have permissions to ${action} ${resource}`);
26
+ }
27
+ }
28
+ exports.MissingPermissions = MissingPermissions;
29
+ class UnsupportedValue extends http_1.BadRequest {
30
+ constructor(value) {
31
+ super(`unsupported ${value ? ` ${value}` : 'value'}`);
32
+ }
33
+ }
34
+ exports.UnsupportedValue = UnsupportedValue;
35
+ class NotArray extends http_1.BadRequest {
36
+ constructor(field) {
37
+ super(`${field} must be an array`);
38
+ }
39
+ }
40
+ exports.NotArray = NotArray;
@@ -0,0 +1,7 @@
1
+ import { BadRequest } from './http';
2
+ export declare class InvalidOperation extends BadRequest {
3
+ constructor(badOperation: string);
4
+ }
5
+ export declare class InvalidSubscriptionEvent extends BadRequest {
6
+ constructor(event: string);
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidSubscriptionEvent = exports.InvalidOperation = void 0;
4
+ const http_1 = require("./http");
5
+ class InvalidOperation extends http_1.BadRequest {
6
+ constructor(badOperation) {
7
+ super(`invalid "${badOperation}" operation`);
8
+ }
9
+ }
10
+ exports.InvalidOperation = InvalidOperation;
11
+ class InvalidSubscriptionEvent extends http_1.BadRequest {
12
+ constructor(event) {
13
+ super(`invalid subscription event "${event}"`);
14
+ }
15
+ }
16
+ exports.InvalidSubscriptionEvent = InvalidSubscriptionEvent;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * as Constants from './constants';
2
+ export * as Errors from './errors';
2
3
  export * as Permissions from './permissions';
3
4
  export * as Rules from './rules';
4
5
  export * as Utils from './utils';
package/dist/index.js CHANGED
@@ -23,8 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Utils = exports.Rules = exports.Permissions = exports.Constants = void 0;
26
+ exports.Utils = exports.Rules = exports.Permissions = exports.Errors = exports.Constants = void 0;
27
27
  exports.Constants = __importStar(require("./constants"));
28
+ exports.Errors = __importStar(require("./errors"));
28
29
  exports.Permissions = __importStar(require("./permissions"));
29
30
  exports.Rules = __importStar(require("./rules"));
30
31
  exports.Utils = __importStar(require("./utils"));
@@ -1,4 +1,4 @@
1
- import { AccountSettings, ApiSubscription, Inspection, PermissionGroup, Profile } from '@rentcheck/types';
1
+ import { AccountSettings, ApiSubscription, Inspection, InspectionEdit, PermissionGroup, Profile } from '@rentcheck/types';
2
2
  export declare const canRecordVideo: (subscription?: ApiSubscription | null) => boolean;
3
3
  export declare const canTake360Photos: (subscription?: ApiSubscription | null) => boolean;
4
4
  export declare const canRenterReportMaintenance: (accountSettings?: AccountSettings | null, subscription?: ApiSubscription | null) => boolean;
@@ -18,4 +18,9 @@ type RulesResult = {
18
18
  error?: string;
19
19
  };
20
20
  export declare const canSubmit: ({ user, inspection, }: CanSubmitParams) => RulesResult;
21
+ export declare const canSign: ({ user, inspection }: CanSubmitParams) => RulesResult;
22
+ type CanEditParams = {
23
+ changeset: InspectionEdit;
24
+ };
25
+ export declare const canEdit: ({ changeset }: CanEditParams) => RulesResult;
21
26
  export {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.canSubmit = exports.canAccess = exports.areFlagDefaultPhotosEnabled = exports.canRenterReportMaintenance = exports.canTake360Photos = exports.canRecordVideo = void 0;
26
+ exports.canEdit = exports.canSign = exports.canSubmit = exports.canAccess = exports.areFlagDefaultPhotosEnabled = exports.canRenterReportMaintenance = exports.canTake360Photos = exports.canRecordVideo = void 0;
27
27
  const Utils = __importStar(require("../utils"));
28
28
  const canRecordVideo = (subscription) => {
29
29
  if (!subscription) {
@@ -74,6 +74,8 @@ const canAccess = ({ user, inspection, permissionGroups, }) => {
74
74
  userPermissionGroupsHaveAccessToInspectionTemplate) {
75
75
  return true;
76
76
  }
77
+ if (user.internal_admin)
78
+ return true;
77
79
  return false;
78
80
  };
79
81
  exports.canAccess = canAccess;
@@ -96,3 +98,39 @@ const canSubmit = ({ user, inspection, }) => {
96
98
  return { value: true };
97
99
  };
98
100
  exports.canSubmit = canSubmit;
101
+ const canSign = ({ user, inspection }) => {
102
+ const validInspectionStatuses = ['Continue Inspection'];
103
+ if (!validInspectionStatuses.includes(inspection.inspection_status)) {
104
+ const error = `Invalid inspection status: ${inspection.inspection_status}`;
105
+ return { value: false, error };
106
+ }
107
+ if (inspection.renterID && inspection.renterID !== user.id) {
108
+ const error = `User does not have permission to submit inspection`;
109
+ return { value: false, error };
110
+ }
111
+ return { value: true };
112
+ };
113
+ exports.canSign = canSign;
114
+ const canEdit = ({ changeset }) => {
115
+ var _a, _b, _c, _d, _e, _f;
116
+ if ('questions' in changeset) {
117
+ const emptyResponse = ((_a = changeset.questions.find((q) => q.updated.length === 0)) === null || _a === void 0 ? void 0 : _a.updated) === '' ||
118
+ changeset.questions.find((q) => !q.updated.trim().length);
119
+ if (emptyResponse) {
120
+ return {
121
+ value: false,
122
+ error: 'Responses to text questions are required to edit this feature.',
123
+ };
124
+ }
125
+ }
126
+ const changesetAsInspectionEdited = changeset;
127
+ if (!changesetAsInspectionEdited.note &&
128
+ !changesetAsInspectionEdited.images &&
129
+ !((_c = (_b = changesetAsInspectionEdited.images) === null || _b === void 0 ? void 0 : _b.addded) === null || _c === void 0 ? void 0 : _c.length) &&
130
+ !((_e = (_d = changesetAsInspectionEdited.images) === null || _d === void 0 ? void 0 : _d.removed) === null || _e === void 0 ? void 0 : _e.length) &&
131
+ !((_f = changesetAsInspectionEdited.questions) === null || _f === void 0 ? void 0 : _f.length)) {
132
+ return { value: false, error: 'No changes to save' };
133
+ }
134
+ return { value: true };
135
+ };
136
+ exports.canEdit = canEdit;