@managemint-solutions/sdk 0.35.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -15
- package/dist/cache/index.d.ts +28 -22
- package/dist/cache/index.js +36 -29
- package/dist/client.d.ts +6 -0
- package/dist/client.js +11 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +25 -1
- package/dist/leave/dto.d.ts +75 -0
- package/dist/leave/dto.js +375 -0
- package/dist/leave/index.d.ts +5 -0
- package/dist/leave/index.js +29 -0
- package/dist/leave/leave-entitlements.d.ts +42 -0
- package/dist/leave/leave-entitlements.js +170 -0
- package/dist/leave/leave-requests.d.ts +69 -0
- package/dist/leave/leave-requests.js +181 -0
- package/dist/leave/leave-types.d.ts +21 -0
- package/dist/leave/leave-types.js +95 -0
- package/dist/leave/working-days.d.ts +29 -0
- package/dist/leave/working-days.js +80 -0
- package/dist/permissions/dto.d.ts +12 -0
- package/dist/permissions/dto.js +60 -24
- package/dist/public-holidays/dto.d.ts +4 -0
- package/dist/public-holidays/dto.js +30 -0
- package/dist/public-holidays/index.d.ts +21 -0
- package/dist/public-holidays/index.js +63 -0
- package/dist/users/index.d.ts +2 -0
- package/dist/users/index.js +11 -0
- package/dist/validators.d.ts +8 -0
- package/dist/validators.js +32 -0
- package/package.json +2 -2
|
@@ -0,0 +1,63 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.PublicHolidaysResource = void 0;
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
__exportStar(require("./dto"), exports);
|
|
20
|
+
const PUBLIC_HOLIDAY_SELECT = 'mms_id, created_at, name, date, religion, notes';
|
|
21
|
+
/**
|
|
22
|
+
* The public-holiday calendar. Global, like configs: every signed-in caller reads the same
|
|
23
|
+
* rows (the READ policy is `true` - there is no tenant on them), so this hangs off the user
|
|
24
|
+
* client with no auth context, and nothing writes them but Scott in Supabase Studio.
|
|
25
|
+
*/
|
|
26
|
+
class PublicHolidaysResource {
|
|
27
|
+
supabase;
|
|
28
|
+
constructor(supabase) {
|
|
29
|
+
this.supabase = supabase;
|
|
30
|
+
}
|
|
31
|
+
/** The calendar in date order, or one calendar year of it. */
|
|
32
|
+
async list(query) {
|
|
33
|
+
let holidaysQuery = this.supabase
|
|
34
|
+
.from('public_holidays')
|
|
35
|
+
.select(PUBLIC_HOLIDAY_SELECT)
|
|
36
|
+
.order('date')
|
|
37
|
+
.order('name');
|
|
38
|
+
if (query.year) {
|
|
39
|
+
holidaysQuery = holidaysQuery.gte('date', `${query.year}-01-01`).lte('date', `${query.year}-12-31`);
|
|
40
|
+
}
|
|
41
|
+
const { data, error } = await holidaysQuery;
|
|
42
|
+
if (error)
|
|
43
|
+
throw (0, errors_1.mapPostgrestError)(error);
|
|
44
|
+
return (data ?? []);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The dates between `start` and `end` (inclusive) that are a day off for everyone - the input
|
|
48
|
+
* to leave's working-day count. A faith-specific holiday (`religion` set) is on the calendar
|
|
49
|
+
* but does not shorten a request, since nothing yet says which employees observe it.
|
|
50
|
+
*/
|
|
51
|
+
async datesBetween(start, end) {
|
|
52
|
+
const { data, error } = await this.supabase
|
|
53
|
+
.from('public_holidays')
|
|
54
|
+
.select('date')
|
|
55
|
+
.is('religion', null)
|
|
56
|
+
.gte('date', start)
|
|
57
|
+
.lte('date', end);
|
|
58
|
+
if (error)
|
|
59
|
+
throw (0, errors_1.mapPostgrestError)(error);
|
|
60
|
+
return new Set((data ?? []).map((row) => row.date));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.PublicHolidaysResource = PublicHolidaysResource;
|
package/dist/users/index.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare class UsersResource {
|
|
|
26
26
|
* client — it needs no service role.
|
|
27
27
|
*/
|
|
28
28
|
identityById(userId?: string | null): Promise<UserIdentity | null>;
|
|
29
|
+
/** The users who report to `managerId` - the direct reports a leave approver may act on. */
|
|
30
|
+
idsManagedBy(managerId: string): Promise<string[]>;
|
|
29
31
|
/** Seats in use. Counts rows rather than fetching them. */
|
|
30
32
|
activeCount(): Promise<number>;
|
|
31
33
|
isActive(userId: string): Promise<boolean>;
|
package/dist/users/index.js
CHANGED
|
@@ -92,6 +92,17 @@ class UsersResource {
|
|
|
92
92
|
throw (0, errors_1.mapPostgrestError)(error);
|
|
93
93
|
return data;
|
|
94
94
|
}
|
|
95
|
+
/** The users who report to `managerId` - the direct reports a leave approver may act on. */
|
|
96
|
+
async idsManagedBy(managerId) {
|
|
97
|
+
const { data, error } = await this.supabase
|
|
98
|
+
.from('users')
|
|
99
|
+
.select('mms_id')
|
|
100
|
+
.eq('organization_id', this.auth.organization_id)
|
|
101
|
+
.eq('manager_id', managerId);
|
|
102
|
+
if (error)
|
|
103
|
+
throw (0, errors_1.mapPostgrestError)(error);
|
|
104
|
+
return (data ?? []).map((row) => row.mms_id);
|
|
105
|
+
}
|
|
95
106
|
/** Seats in use. Counts rows rather than fetching them. */
|
|
96
107
|
async activeCount() {
|
|
97
108
|
const { count, error } = await this.supabase
|
package/dist/validators.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { ValidationOptions } from 'class-validator';
|
|
2
|
+
/** A real `YYYY-MM-DD` - the only date shape a `date` column's DTO accepts. */
|
|
3
|
+
export declare const isCalendarDate: (value: unknown) => value is string;
|
|
4
|
+
/**
|
|
5
|
+
* Calendar dates, `YYYY-MM-DD` and nothing more, for the leave and public-holiday columns
|
|
6
|
+
* that are `date`: a timestamp would leave the day to whoever's time zone did the
|
|
7
|
+
* conversion. Stricter on purpose than the `@IsDateString` the timestamp columns use.
|
|
8
|
+
*/
|
|
9
|
+
export declare const IsCalendarDate: (options?: ValidationOptions) => PropertyDecorator;
|
|
2
10
|
export declare function IsNullable(validationOptions?: ValidationOptions): PropertyDecorator;
|
|
3
11
|
/**
|
|
4
12
|
* An empty string from a cleared form field means "none". It becomes null before validation,
|
package/dist/validators.js
CHANGED
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.IsCalendarDate = exports.isCalendarDate = void 0;
|
|
3
10
|
exports.IsNullable = IsNullable;
|
|
4
11
|
exports.EmptyToNull = EmptyToNull;
|
|
5
12
|
const class_validator_1 = require("class-validator");
|
|
6
13
|
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
const CALENDAR_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
15
|
+
/** A real `YYYY-MM-DD` - the only date shape a `date` column's DTO accepts. */
|
|
16
|
+
const isCalendarDate = (value) => {
|
|
17
|
+
if (typeof value !== 'string' || !CALENDAR_DATE.test(value))
|
|
18
|
+
return false;
|
|
19
|
+
const [year, month, day] = value.split('-').map(Number);
|
|
20
|
+
const parsed = new Date(Date.UTC(year, month - 1, day));
|
|
21
|
+
return (parsed.getUTCFullYear() === year && parsed.getUTCMonth() === month - 1 && parsed.getUTCDate() === day);
|
|
22
|
+
};
|
|
23
|
+
exports.isCalendarDate = isCalendarDate;
|
|
24
|
+
let CalendarDateConstraint = class CalendarDateConstraint {
|
|
25
|
+
validate(value) {
|
|
26
|
+
return (0, exports.isCalendarDate)(value);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
CalendarDateConstraint = __decorate([
|
|
30
|
+
(0, class_validator_1.ValidatorConstraint)({ name: 'isCalendarDate' })
|
|
31
|
+
], CalendarDateConstraint);
|
|
32
|
+
/**
|
|
33
|
+
* Calendar dates, `YYYY-MM-DD` and nothing more, for the leave and public-holiday columns
|
|
34
|
+
* that are `date`: a timestamp would leave the day to whoever's time zone did the
|
|
35
|
+
* conversion. Stricter on purpose than the `@IsDateString` the timestamp columns use.
|
|
36
|
+
*/
|
|
37
|
+
const IsCalendarDate = (options) => (0, class_validator_1.Validate)(CalendarDateConstraint, options);
|
|
38
|
+
exports.IsCalendarDate = IsCalendarDate;
|
|
7
39
|
function IsNullable(validationOptions) {
|
|
8
40
|
return (0, class_validator_1.ValidateIf)((_object, value) => value !== null, validationOptions);
|
|
9
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@managemint-solutions/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Typed Supabase data-access SDK for ManageMint Solutions",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Scott Bebington <scottbebington@gmail.com>",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"testEnvironment": "node"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@managemint-solutions/entities": "^1.
|
|
54
|
+
"@managemint-solutions/entities": "^1.21.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@nestjs/common": "^11.0.0",
|