@managemint-solutions/sdk 0.52.0 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +92 -13
  2. package/dist/additional-details/index.d.ts +2 -2
  3. package/dist/additional-details/index.js +6 -10
  4. package/dist/audit/dto.d.ts +3 -8
  5. package/dist/audit/dto.js +7 -48
  6. package/dist/audit/index.d.ts +71 -10
  7. package/dist/audit/index.js +234 -55
  8. package/dist/auth-client/index.d.ts +2 -0
  9. package/dist/auth-client/index.js +12 -0
  10. package/dist/auth.d.ts +21 -0
  11. package/dist/auth.js +47 -3
  12. package/dist/clients/dto.d.ts +5 -1
  13. package/dist/clients/dto.js +12 -1
  14. package/dist/clients/index.d.ts +8 -4
  15. package/dist/clients/index.js +11 -8
  16. package/dist/emulation-handshakes/index.d.ts +13 -0
  17. package/dist/emulation-handshakes/index.js +36 -0
  18. package/dist/errors.js +2 -2
  19. package/dist/index.d.ts +14 -10
  20. package/dist/index.js +23 -4
  21. package/dist/leads/dto.d.ts +5 -1
  22. package/dist/leads/dto.js +12 -1
  23. package/dist/leads/index.d.ts +8 -5
  24. package/dist/leads/index.js +23 -21
  25. package/dist/leave/leave-adjustments.js +1 -0
  26. package/dist/leave/leave-entitlements.d.ts +3 -1
  27. package/dist/leave/leave-entitlements.js +3 -0
  28. package/dist/leave/leave-requests.d.ts +3 -1
  29. package/dist/leave/leave-requests.js +3 -0
  30. package/dist/nest/index.d.ts +26 -1
  31. package/dist/nest/index.js +58 -1
  32. package/dist/notifications/index.d.ts +1 -3
  33. package/dist/organization-payment-methods/index.d.ts +5 -6
  34. package/dist/organization-payment-methods/index.js +4 -17
  35. package/dist/organizations/dto.d.ts +9 -1
  36. package/dist/organizations/dto.js +40 -1
  37. package/dist/organizations/index.d.ts +13 -3
  38. package/dist/organizations/index.js +59 -3
  39. package/dist/permissions/index.d.ts +6 -4
  40. package/dist/permissions/index.js +19 -12
  41. package/dist/projects/dto.d.ts +5 -1
  42. package/dist/projects/dto.js +12 -1
  43. package/dist/projects/index.d.ts +8 -4
  44. package/dist/projects/index.js +11 -8
  45. package/dist/service-client/index.d.ts +39 -1
  46. package/dist/service-client/index.js +89 -2
  47. package/dist/staff/dto.d.ts +14 -0
  48. package/dist/staff/dto.js +63 -0
  49. package/dist/staff/index.d.ts +50 -0
  50. package/dist/staff/index.js +139 -0
  51. package/dist/staff-client.d.ts +37 -0
  52. package/dist/staff-client.js +52 -0
  53. package/dist/tasks/dto.d.ts +5 -1
  54. package/dist/tasks/dto.js +12 -1
  55. package/dist/tasks/index.d.ts +15 -10
  56. package/dist/tasks/index.js +34 -31
  57. package/dist/tenancy.d.ts +13 -0
  58. package/dist/tenancy.js +25 -0
  59. package/dist/timesheets/timesheet-entries.js +1 -0
  60. package/dist/timesheets/timesheets.d.ts +3 -1
  61. package/dist/timesheets/timesheets.js +3 -0
  62. package/dist/user-api-credentials/dto.d.ts +12 -0
  63. package/dist/user-api-credentials/dto.js +56 -0
  64. package/dist/user-api-credentials/index.d.ts +47 -0
  65. package/dist/user-api-credentials/index.js +101 -0
  66. package/dist/users/dto.d.ts +5 -1
  67. package/dist/users/dto.js +13 -2
  68. package/dist/users/index.d.ts +7 -3
  69. package/dist/users/index.js +16 -29
  70. package/dist/validators.d.ts +2 -0
  71. package/dist/validators.js +6 -1
  72. package/package.json +2 -2
@@ -18,6 +18,7 @@ exports.ClientsResource = void 0;
18
18
  const enum_1 = require("@managemint-solutions/entities/audit-trail/enum");
19
19
  const audit_1 = require("../audit");
20
20
  const errors_1 = require("../errors");
21
+ const tenancy_1 = require("../tenancy");
21
22
  const transforms_1 = require("../transforms");
22
23
  __exportStar(require("./dto"), exports);
23
24
  // The public contract is the shared ClientSummary / ClientEntity from
@@ -74,6 +75,8 @@ class ClientsResource {
74
75
  supabase;
75
76
  auth;
76
77
  table;
78
+ /** This record's history - its own rows and the rows that hang off it. */
79
+ audit;
77
80
  constructor(supabase, auth, audit) {
78
81
  this.supabase = supabase;
79
82
  this.auth = auth;
@@ -81,6 +84,7 @@ class ClientsResource {
81
84
  table: 'clients',
82
85
  entityType: enum_1.AuditTrailEntityType.CLIENTS,
83
86
  });
87
+ this.audit = new audit_1.EntityAuditTrail(supabase, auth, enum_1.AuditTrailEntityType.CLIENTS);
84
88
  }
85
89
  async list(query) {
86
90
  const page = query.page;
@@ -89,14 +93,16 @@ class ClientsResource {
89
93
  const trimmedSearch = query.search?.trim();
90
94
  // `order`/`range` return `this`, so the builder stays a filter builder and the conditional
91
95
  // filters below can be reassigned onto it without a cast.
92
- let clientsQuery = this.supabase
96
+ let clientsQuery = (0, tenancy_1.scopeToOrganization)(this.supabase
93
97
  .from('clients')
94
- .select(CLIENT_LIST_SELECT, { count: 'estimated' })
95
- .eq('organization_id', this.auth.organization_id)
98
+ .select((0, tenancy_1.withOrganization)(CLIENT_LIST_SELECT, this.auth), { count: 'estimated' }), this.auth)
96
99
  .eq('archived', query.archive)
97
100
  .eq('deleted', false)
98
101
  .order('created_at', { ascending: false })
99
102
  .range(offset, offset + pageSize - 1);
103
+ if (query.organization_id) {
104
+ clientsQuery = clientsQuery.eq('organization_id', query.organization_id);
105
+ }
100
106
  if (trimmedSearch) {
101
107
  clientsQuery = clientsQuery.or((0, transforms_1.orIlike)(['name', 'email'], trimmedSearch));
102
108
  }
@@ -115,10 +121,7 @@ class ClientsResource {
115
121
  return (0, transforms_1.toMmsList)(data, page, pageSize, count);
116
122
  }
117
123
  async getById(clientId) {
118
- const { data, error } = await this.supabase
119
- .from('clients')
120
- .select(CLIENT_DETAIL_SELECT)
121
- .eq('organization_id', this.auth.organization_id)
124
+ const { data, error } = await (0, tenancy_1.scopeToOrganization)(this.supabase.from('clients').select(CLIENT_DETAIL_SELECT), this.auth)
122
125
  .eq('mms_id', clientId)
123
126
  .single();
124
127
  if (error)
@@ -140,7 +143,7 @@ class ClientsResource {
140
143
  async create(input) {
141
144
  const row = await this.table.insert({
142
145
  ...input,
143
- organization_id: this.auth.organization_id,
146
+ organization_id: (0, tenancy_1.requireOrganization)(this.auth),
144
147
  created_by: this.auth.mms_id,
145
148
  created_at: new Date().toISOString(),
146
149
  });
@@ -0,0 +1,13 @@
1
+ import type { TypedSupabaseClient } from '../client';
2
+ /**
3
+ * `emulation_handshakes`, service client only: proof that a user's next sign-in is the admin
4
+ * api's own mint, which the custom access token hook spends to mark that token emulated.
5
+ */
6
+ export declare class EmulationHandshakesResource {
7
+ private readonly supabase;
8
+ constructor(supabase: TypedSupabaseClient);
9
+ /** Opens a handshake for `userId`'s next sign-in, good for thirty seconds. Returns its id. */
10
+ open(userId: string, credentialId: string): Promise<number>;
11
+ /** Deletes the handshake, spent or not, once the mint is over. */
12
+ close(id: number): Promise<void>;
13
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmulationHandshakesResource = void 0;
4
+ const errors_1 = require("../errors");
5
+ /**
6
+ * `emulation_handshakes`, service client only: proof that a user's next sign-in is the admin
7
+ * api's own mint, which the custom access token hook spends to mark that token emulated.
8
+ */
9
+ class EmulationHandshakesResource {
10
+ supabase;
11
+ constructor(supabase) {
12
+ this.supabase = supabase;
13
+ }
14
+ /** Opens a handshake for `userId`'s next sign-in, good for thirty seconds. Returns its id. */
15
+ async open(userId, credentialId) {
16
+ const { data, error } = await this.supabase
17
+ .from('emulation_handshakes')
18
+ .insert({
19
+ user_id: userId,
20
+ credential_id: credentialId,
21
+ expires_at: new Date(Date.now() + 30_000).toISOString(),
22
+ })
23
+ .select('id')
24
+ .single();
25
+ if (error)
26
+ throw (0, errors_1.mapPostgrestError)(error);
27
+ return data.id;
28
+ }
29
+ /** Deletes the handshake, spent or not, once the mint is over. */
30
+ async close(id) {
31
+ const { error } = await this.supabase.from('emulation_handshakes').delete().eq('id', id);
32
+ if (error)
33
+ throw (0, errors_1.mapPostgrestError)(error);
34
+ }
35
+ }
36
+ exports.EmulationHandshakesResource = EmulationHandshakesResource;
package/dist/errors.js CHANGED
@@ -90,7 +90,7 @@ exports.mapPostgrestError = mapPostgrestError;
90
90
  * network/unknown failures have none, hence the 500 fallback.
91
91
  */
92
92
  const mapStorageError = (error, message = error.message) => new SupabaseClientError({
93
- status: error.status ?? 500,
93
+ status: error.status || 500,
94
94
  error: 'Storage Error',
95
95
  message,
96
96
  }, { cause: error });
@@ -101,7 +101,7 @@ exports.mapStorageError = mapStorageError;
101
101
  * status GoTrue answered with; network/unknown failures carry none, hence the 500 fallback.
102
102
  */
103
103
  const mapAuthError = (error) => new SupabaseClientError({
104
- status: error.status ?? 500,
104
+ status: error.status || 500,
105
105
  error: 'Authentication Error',
106
106
  message: error.message,
107
107
  }, { cause: error });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { SupabaseClient, createSupabaseClient } from './client';
2
2
  export type { SupabaseClientConfig, TypedSupabaseClient } from './client';
3
- export type { AuthContext, VerifiedAuth, VerifiedOrganization, VerifyAccessTokenConfig, } from './auth';
3
+ export { SupabaseStaffClient, createSupabaseStaffClient } from './staff-client';
4
+ export type { AuthContext, StaffContext, VerifiedAuth, VerifiedOrganization, VerifiedStaff, VerifyAccessTokenConfig, } from './auth';
4
5
  export { SupabaseAuthClient, createSupabaseAuthClient } from './auth-client';
5
6
  export type { SupabaseAuthClientConfig } from './auth-client';
6
7
  export { ExchangeRefreshTokenDto, ExchangeTokenHashDto, ResetPasswordDto, SendPasswordResetEmailDto, SignInDto, } from './auth-client';
@@ -9,8 +10,8 @@ export type { SupabaseOrganizationScope, SupabaseServiceClientConfig } from './s
9
10
  export { SupabaseClientError } from './errors';
10
11
  export type { SupabaseClientErrorInit } from './errors';
11
12
  export { EmptyToNull, IsNullable } from './validators';
12
- export type { AuditActor, AuditChanges, AuditEntry, AuditErrorHandler, AuditGuard, AuditRow, AuditedTable, AuditedTableOptions, } from './audit';
13
- export { GetAuditTrailDto } from './audit';
13
+ export type { AuditActor, AuditChanges, AuditEntry, AuditErrorHandler, AuditGuard, AuditNameTable, AuditRow, AuditedTable, AuditedTableOptions, EntityAuditTrail, OrganizationTableFactory, } from './audit';
14
+ export { GetAuditTrailDto, withAuditBatch } from './audit';
14
15
  export { CancelSubscriptionDto, GetPaymentsQueryDto, InitialPaymentDto, PaymentIdDto, PurchaseModuleDto, ReinstateSubscriptionDto, } from './billing';
15
16
  export { GetInvoicesQueryDto, InvoiceIdDto } from './billing/invoices';
16
17
  export type { CreateFeatureRequestRow, CreatedFeatureRequest } from './feature-requests';
@@ -21,23 +22,26 @@ export { AddStatusDto, GetStatusesDto, ReorderStatusesDto, StatusIdDto, UpdateSt
21
22
  export { AddLabelDto, GetLabelsDto, LabelIdDto, UpdateLabelDto } from './labels';
22
23
  export { AddAdditionalDetailsDto, AdditionalDetailsIdDto, GetAdditionalDetailsDto, IsAdditionalDetailsValueByType, UpdateAdditionalDetailsDto, } from './additional-details';
23
24
  export { AddNoteDto, GetNotesDto, NoteIdDto } from './notes';
24
- export type { CreateNotificationInput, CreatedNotification, NotificationContentRow, OrganizationTableFactory, QueuedNotification, } from './notifications';
25
+ export type { CreateNotificationInput, CreatedNotification, NotificationContentRow, QueuedNotification, } from './notifications';
25
26
  export { GetNotificationsDto, NotificationIdDto } from './notifications';
26
27
  export type { OrganizationInvite } from './organization-invites';
27
28
  export type { OrganizationPaymentMethod, PaymentMethodLookupColumn, } from './organization-payment-methods';
28
29
  export type { CreateOrganizationRow, OrganizationRow } from './organizations';
29
- export { CreateOrganizationDto, UpdateOrganizationDto } from './organizations';
30
+ export { CreateOrganizationDto, GetOrganizationsDto, OrganizationIdDto, UpdateOrganizationDto, } from './organizations';
30
31
  export { PermissionsResource } from './permissions';
31
32
  export type { PermissionFlags } from './permissions';
32
33
  export { UpdatePermissionsDto } from './permissions';
34
+ export { CreateStaffDto, StaffIdDto, UpdateStaffPermissionsDto } from './staff';
35
+ export type { CreateUserApiCredentialRow, UserApiCredentialRow } from './user-api-credentials';
36
+ export { CreateUserApiCredentialDto, MintEmulationTokenDto, UserApiCredentialIdDto, } from './user-api-credentials';
33
37
  export type { UserEmploymentRow, UserRow } from './users';
34
- export { AddUserDto, GetUsersQueryDto, UpdateMyProfileDto, UpdateUserDto, UserIdDto, } from './users';
38
+ export { AddUserDto, GetUsersQueryDto, StaffGetUsersDto, UpdateMyProfileDto, UpdateUserDto, UserIdDto, } from './users';
35
39
  export type { ClaimOutcome, WebhookEventRow, WebhookEventsTable } from './webhook-events';
36
40
  export { GetSupportingFilesDto, SupportingFileIdDto, SupportingFileNamesDto } from './supporting-files';
37
- export { ClientIdDto, CreateClientDto, GetClientsDto, UpdateClientDto } from './clients';
38
- export { ConvertLeadDto, CreateLeadDto, GetLeadsDto, LeadIdDto, UpdateLeadDto } from './leads';
39
- export { CreateProjectDto, GetProjectsDto, ProjectIdDto, UpdateProjectDto } from './projects';
40
- export { AddTaskLinkDto, CreateTaskDto, GetTasksDto, TaskIdDto, TaskLinkIdDto, UpdateTaskDto } from './tasks';
41
+ export { ClientIdDto, CreateClientDto, GetClientsDto, StaffGetClientsDto, UpdateClientDto } from './clients';
42
+ export { ConvertLeadDto, CreateLeadDto, GetLeadsDto, LeadIdDto, StaffGetLeadsDto, UpdateLeadDto } from './leads';
43
+ export { CreateProjectDto, GetProjectsDto, ProjectIdDto, StaffGetProjectsDto, UpdateProjectDto } from './projects';
44
+ export { AddTaskLinkDto, CreateTaskDto, GetTasksDto, StaffGetTasksDto, TaskIdDto, TaskLinkIdDto, UpdateTaskDto, } from './tasks';
41
45
  export type { CreateLeaveEntitlementInput, CreateLeaveRequestRow, ReviewLeaveRequestRow, UpdateLeaveRequestRow, } from './leave';
42
46
  export type { BalanceEntitlement, BalanceRequest, LeaveCycle } from './leave';
43
47
  export { BulkCreateLeaveEntitlementsDto, CreateLeaveAdjustmentDto, CreateLeaveEntitlementDto, CreateLeaveRequestDto, CreateLeaveTypeDto, GetLeaveCalendarDto, GetLeaveEntitlementsDto, GetLeaveRequestsDto, GetLeaveTypesDto, LeaveEntitlementIdDto, LeaveRequestIdDto, LeaveTypeIdDto, ReviewLeaveRequestDto, UpdateLeaveEntitlementDto, UpdateLeaveRequestDto, UpdateLeaveTypeDto, } from './leave';
package/dist/index.js CHANGED
@@ -3,16 +3,19 @@
3
3
  // the audit diff, the row helpers, the select-string fragments, the error mappers - and stays
4
4
  // reachable only from inside. The `./nest` entrypoint is listed separately, in src/nest/index.ts.
5
5
  //
6
- // Resources are reached through the three clients (`supabase.tasks`, `scope.invoices`, ...), so
6
+ // Resources are reached through the clients (`supabase.tasks`, `scope.invoices`, ...), so
7
7
  // their classes are not exported: a consumer never constructs one, and every export is a contract
8
8
  // to keep. The row and input types they produce and accept are exported for annotations.
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.UpdatePermissionsDto = exports.PermissionsResource = exports.UpdateOrganizationDto = exports.CreateOrganizationDto = exports.NotificationIdDto = exports.GetNotificationsDto = exports.NoteIdDto = exports.GetNotesDto = exports.AddNoteDto = exports.UpdateAdditionalDetailsDto = exports.IsAdditionalDetailsValueByType = exports.GetAdditionalDetailsDto = exports.AdditionalDetailsIdDto = exports.AddAdditionalDetailsDto = exports.UpdateLabelDto = exports.LabelIdDto = exports.GetLabelsDto = exports.AddLabelDto = exports.UpdateStatusDto = exports.StatusIdDto = exports.ReorderStatusesDto = exports.GetStatusesDto = exports.AddStatusDto = exports.CreateSupportRequestDto = exports.UpdateConfigDto = exports.CreateConfigDto = exports.CreateFeatureRequestDto = exports.InvoiceIdDto = exports.GetInvoicesQueryDto = exports.ReinstateSubscriptionDto = exports.PurchaseModuleDto = exports.PaymentIdDto = exports.InitialPaymentDto = exports.GetPaymentsQueryDto = exports.CancelSubscriptionDto = exports.GetAuditTrailDto = exports.IsNullable = exports.EmptyToNull = exports.SupabaseClientError = exports.createSupabaseServiceClient = exports.SupabaseServiceClient = exports.SignInDto = exports.SendPasswordResetEmailDto = exports.ResetPasswordDto = exports.ExchangeTokenHashDto = exports.ExchangeRefreshTokenDto = exports.createSupabaseAuthClient = exports.SupabaseAuthClient = exports.createSupabaseClient = exports.SupabaseClient = void 0;
11
- exports.isWithinPeriod = exports.initialUntil = exports.cyclePeriodFor = exports.countWorkingDays = exports.completedMonths = exports.addMonths = exports.GetPublicHolidaysDto = exports.UpdateLeaveTypeDto = exports.UpdateLeaveRequestDto = exports.UpdateLeaveEntitlementDto = exports.ReviewLeaveRequestDto = exports.LeaveTypeIdDto = exports.LeaveRequestIdDto = exports.LeaveEntitlementIdDto = exports.GetLeaveTypesDto = exports.GetLeaveRequestsDto = exports.GetLeaveEntitlementsDto = exports.GetLeaveCalendarDto = exports.CreateLeaveTypeDto = exports.CreateLeaveRequestDto = exports.CreateLeaveEntitlementDto = exports.CreateLeaveAdjustmentDto = exports.BulkCreateLeaveEntitlementsDto = exports.UpdateTaskDto = exports.TaskLinkIdDto = exports.TaskIdDto = exports.GetTasksDto = exports.CreateTaskDto = exports.AddTaskLinkDto = exports.UpdateProjectDto = exports.ProjectIdDto = exports.GetProjectsDto = exports.CreateProjectDto = exports.UpdateLeadDto = exports.LeadIdDto = exports.GetLeadsDto = exports.CreateLeadDto = exports.ConvertLeadDto = exports.UpdateClientDto = exports.GetClientsDto = exports.CreateClientDto = exports.ClientIdDto = exports.SupportingFileNamesDto = exports.SupportingFileIdDto = exports.GetSupportingFilesDto = exports.UserIdDto = exports.UpdateUserDto = exports.UpdateMyProfileDto = exports.GetUsersQueryDto = exports.AddUserDto = void 0;
12
- exports.monthlyTotalMinor = exports.weekStartOf = exports.minutesBetween = exports.UpdateTimesheetEntryDto = exports.TimesheetIdDto = exports.TimesheetEntryIdDto = exports.ReviewTimesheetDto = exports.GetTimesheetsDto = exports.GetTimesheetReportDto = exports.CreateTimesheetEntryDto = exports.todayInJohannesburg = exports.shiftDays = exports.proRataDays = void 0;
10
+ exports.CreateOrganizationDto = exports.NotificationIdDto = exports.GetNotificationsDto = exports.NoteIdDto = exports.GetNotesDto = exports.AddNoteDto = exports.UpdateAdditionalDetailsDto = exports.IsAdditionalDetailsValueByType = exports.GetAdditionalDetailsDto = exports.AdditionalDetailsIdDto = exports.AddAdditionalDetailsDto = exports.UpdateLabelDto = exports.LabelIdDto = exports.GetLabelsDto = exports.AddLabelDto = exports.UpdateStatusDto = exports.StatusIdDto = exports.ReorderStatusesDto = exports.GetStatusesDto = exports.AddStatusDto = exports.CreateSupportRequestDto = exports.UpdateConfigDto = exports.CreateConfigDto = exports.CreateFeatureRequestDto = exports.InvoiceIdDto = exports.GetInvoicesQueryDto = exports.ReinstateSubscriptionDto = exports.PurchaseModuleDto = exports.PaymentIdDto = exports.InitialPaymentDto = exports.GetPaymentsQueryDto = exports.CancelSubscriptionDto = exports.withAuditBatch = exports.GetAuditTrailDto = exports.IsNullable = exports.EmptyToNull = exports.SupabaseClientError = exports.createSupabaseServiceClient = exports.SupabaseServiceClient = exports.SignInDto = exports.SendPasswordResetEmailDto = exports.ResetPasswordDto = exports.ExchangeTokenHashDto = exports.ExchangeRefreshTokenDto = exports.createSupabaseAuthClient = exports.SupabaseAuthClient = exports.createSupabaseStaffClient = exports.SupabaseStaffClient = exports.createSupabaseClient = exports.SupabaseClient = void 0;
11
+ exports.GetLeaveEntitlementsDto = exports.GetLeaveCalendarDto = exports.CreateLeaveTypeDto = exports.CreateLeaveRequestDto = exports.CreateLeaveEntitlementDto = exports.CreateLeaveAdjustmentDto = exports.BulkCreateLeaveEntitlementsDto = exports.UpdateTaskDto = exports.TaskLinkIdDto = exports.TaskIdDto = exports.StaffGetTasksDto = exports.GetTasksDto = exports.CreateTaskDto = exports.AddTaskLinkDto = exports.UpdateProjectDto = exports.StaffGetProjectsDto = exports.ProjectIdDto = exports.GetProjectsDto = exports.CreateProjectDto = exports.UpdateLeadDto = exports.StaffGetLeadsDto = exports.LeadIdDto = exports.GetLeadsDto = exports.CreateLeadDto = exports.ConvertLeadDto = exports.UpdateClientDto = exports.StaffGetClientsDto = exports.GetClientsDto = exports.CreateClientDto = exports.ClientIdDto = exports.SupportingFileNamesDto = exports.SupportingFileIdDto = exports.GetSupportingFilesDto = exports.UserIdDto = exports.UpdateUserDto = exports.UpdateMyProfileDto = exports.StaffGetUsersDto = exports.GetUsersQueryDto = exports.AddUserDto = exports.UserApiCredentialIdDto = exports.MintEmulationTokenDto = exports.CreateUserApiCredentialDto = exports.UpdateStaffPermissionsDto = exports.StaffIdDto = exports.CreateStaffDto = exports.UpdatePermissionsDto = exports.PermissionsResource = exports.UpdateOrganizationDto = exports.OrganizationIdDto = exports.GetOrganizationsDto = void 0;
12
+ exports.monthlyTotalMinor = exports.weekStartOf = exports.minutesBetween = exports.UpdateTimesheetEntryDto = exports.TimesheetIdDto = exports.TimesheetEntryIdDto = exports.ReviewTimesheetDto = exports.GetTimesheetsDto = exports.GetTimesheetReportDto = exports.CreateTimesheetEntryDto = exports.todayInJohannesburg = exports.shiftDays = exports.proRataDays = exports.isWithinPeriod = exports.initialUntil = exports.cyclePeriodFor = exports.countWorkingDays = exports.completedMonths = exports.addMonths = exports.GetPublicHolidaysDto = exports.UpdateLeaveTypeDto = exports.UpdateLeaveRequestDto = exports.UpdateLeaveEntitlementDto = exports.ReviewLeaveRequestDto = exports.LeaveTypeIdDto = exports.LeaveRequestIdDto = exports.LeaveEntitlementIdDto = exports.GetLeaveTypesDto = exports.GetLeaveRequestsDto = void 0;
13
13
  var client_1 = require("./client");
14
14
  Object.defineProperty(exports, "SupabaseClient", { enumerable: true, get: function () { return client_1.SupabaseClient; } });
15
15
  Object.defineProperty(exports, "createSupabaseClient", { enumerable: true, get: function () { return client_1.createSupabaseClient; } });
16
+ var staff_client_1 = require("./staff-client");
17
+ Object.defineProperty(exports, "SupabaseStaffClient", { enumerable: true, get: function () { return staff_client_1.SupabaseStaffClient; } });
18
+ Object.defineProperty(exports, "createSupabaseStaffClient", { enumerable: true, get: function () { return staff_client_1.createSupabaseStaffClient; } });
16
19
  var auth_client_1 = require("./auth-client");
17
20
  Object.defineProperty(exports, "SupabaseAuthClient", { enumerable: true, get: function () { return auth_client_1.SupabaseAuthClient; } });
18
21
  Object.defineProperty(exports, "createSupabaseAuthClient", { enumerable: true, get: function () { return auth_client_1.createSupabaseAuthClient; } });
@@ -32,6 +35,7 @@ Object.defineProperty(exports, "EmptyToNull", { enumerable: true, get: function
32
35
  Object.defineProperty(exports, "IsNullable", { enumerable: true, get: function () { return validators_1.IsNullable; } });
33
36
  var audit_1 = require("./audit");
34
37
  Object.defineProperty(exports, "GetAuditTrailDto", { enumerable: true, get: function () { return audit_1.GetAuditTrailDto; } });
38
+ Object.defineProperty(exports, "withAuditBatch", { enumerable: true, get: function () { return audit_1.withAuditBatch; } });
35
39
  var billing_1 = require("./billing");
36
40
  Object.defineProperty(exports, "CancelSubscriptionDto", { enumerable: true, get: function () { return billing_1.CancelSubscriptionDto; } });
37
41
  Object.defineProperty(exports, "GetPaymentsQueryDto", { enumerable: true, get: function () { return billing_1.GetPaymentsQueryDto; } });
@@ -75,6 +79,8 @@ Object.defineProperty(exports, "GetNotificationsDto", { enumerable: true, get: f
75
79
  Object.defineProperty(exports, "NotificationIdDto", { enumerable: true, get: function () { return notifications_1.NotificationIdDto; } });
76
80
  var organizations_1 = require("./organizations");
77
81
  Object.defineProperty(exports, "CreateOrganizationDto", { enumerable: true, get: function () { return organizations_1.CreateOrganizationDto; } });
82
+ Object.defineProperty(exports, "GetOrganizationsDto", { enumerable: true, get: function () { return organizations_1.GetOrganizationsDto; } });
83
+ Object.defineProperty(exports, "OrganizationIdDto", { enumerable: true, get: function () { return organizations_1.OrganizationIdDto; } });
78
84
  Object.defineProperty(exports, "UpdateOrganizationDto", { enumerable: true, get: function () { return organizations_1.UpdateOrganizationDto; } });
79
85
  // The one resource class still exported: the api's permissions guard spec drives a real
80
86
  // PermissionsResource over a stubbed client.
@@ -82,9 +88,18 @@ var permissions_1 = require("./permissions");
82
88
  Object.defineProperty(exports, "PermissionsResource", { enumerable: true, get: function () { return permissions_1.PermissionsResource; } });
83
89
  var permissions_2 = require("./permissions");
84
90
  Object.defineProperty(exports, "UpdatePermissionsDto", { enumerable: true, get: function () { return permissions_2.UpdatePermissionsDto; } });
91
+ var staff_1 = require("./staff");
92
+ Object.defineProperty(exports, "CreateStaffDto", { enumerable: true, get: function () { return staff_1.CreateStaffDto; } });
93
+ Object.defineProperty(exports, "StaffIdDto", { enumerable: true, get: function () { return staff_1.StaffIdDto; } });
94
+ Object.defineProperty(exports, "UpdateStaffPermissionsDto", { enumerable: true, get: function () { return staff_1.UpdateStaffPermissionsDto; } });
95
+ var user_api_credentials_1 = require("./user-api-credentials");
96
+ Object.defineProperty(exports, "CreateUserApiCredentialDto", { enumerable: true, get: function () { return user_api_credentials_1.CreateUserApiCredentialDto; } });
97
+ Object.defineProperty(exports, "MintEmulationTokenDto", { enumerable: true, get: function () { return user_api_credentials_1.MintEmulationTokenDto; } });
98
+ Object.defineProperty(exports, "UserApiCredentialIdDto", { enumerable: true, get: function () { return user_api_credentials_1.UserApiCredentialIdDto; } });
85
99
  var users_1 = require("./users");
86
100
  Object.defineProperty(exports, "AddUserDto", { enumerable: true, get: function () { return users_1.AddUserDto; } });
87
101
  Object.defineProperty(exports, "GetUsersQueryDto", { enumerable: true, get: function () { return users_1.GetUsersQueryDto; } });
102
+ Object.defineProperty(exports, "StaffGetUsersDto", { enumerable: true, get: function () { return users_1.StaffGetUsersDto; } });
88
103
  Object.defineProperty(exports, "UpdateMyProfileDto", { enumerable: true, get: function () { return users_1.UpdateMyProfileDto; } });
89
104
  Object.defineProperty(exports, "UpdateUserDto", { enumerable: true, get: function () { return users_1.UpdateUserDto; } });
90
105
  Object.defineProperty(exports, "UserIdDto", { enumerable: true, get: function () { return users_1.UserIdDto; } });
@@ -96,22 +111,26 @@ var clients_1 = require("./clients");
96
111
  Object.defineProperty(exports, "ClientIdDto", { enumerable: true, get: function () { return clients_1.ClientIdDto; } });
97
112
  Object.defineProperty(exports, "CreateClientDto", { enumerable: true, get: function () { return clients_1.CreateClientDto; } });
98
113
  Object.defineProperty(exports, "GetClientsDto", { enumerable: true, get: function () { return clients_1.GetClientsDto; } });
114
+ Object.defineProperty(exports, "StaffGetClientsDto", { enumerable: true, get: function () { return clients_1.StaffGetClientsDto; } });
99
115
  Object.defineProperty(exports, "UpdateClientDto", { enumerable: true, get: function () { return clients_1.UpdateClientDto; } });
100
116
  var leads_1 = require("./leads");
101
117
  Object.defineProperty(exports, "ConvertLeadDto", { enumerable: true, get: function () { return leads_1.ConvertLeadDto; } });
102
118
  Object.defineProperty(exports, "CreateLeadDto", { enumerable: true, get: function () { return leads_1.CreateLeadDto; } });
103
119
  Object.defineProperty(exports, "GetLeadsDto", { enumerable: true, get: function () { return leads_1.GetLeadsDto; } });
104
120
  Object.defineProperty(exports, "LeadIdDto", { enumerable: true, get: function () { return leads_1.LeadIdDto; } });
121
+ Object.defineProperty(exports, "StaffGetLeadsDto", { enumerable: true, get: function () { return leads_1.StaffGetLeadsDto; } });
105
122
  Object.defineProperty(exports, "UpdateLeadDto", { enumerable: true, get: function () { return leads_1.UpdateLeadDto; } });
106
123
  var projects_1 = require("./projects");
107
124
  Object.defineProperty(exports, "CreateProjectDto", { enumerable: true, get: function () { return projects_1.CreateProjectDto; } });
108
125
  Object.defineProperty(exports, "GetProjectsDto", { enumerable: true, get: function () { return projects_1.GetProjectsDto; } });
109
126
  Object.defineProperty(exports, "ProjectIdDto", { enumerable: true, get: function () { return projects_1.ProjectIdDto; } });
127
+ Object.defineProperty(exports, "StaffGetProjectsDto", { enumerable: true, get: function () { return projects_1.StaffGetProjectsDto; } });
110
128
  Object.defineProperty(exports, "UpdateProjectDto", { enumerable: true, get: function () { return projects_1.UpdateProjectDto; } });
111
129
  var tasks_1 = require("./tasks");
112
130
  Object.defineProperty(exports, "AddTaskLinkDto", { enumerable: true, get: function () { return tasks_1.AddTaskLinkDto; } });
113
131
  Object.defineProperty(exports, "CreateTaskDto", { enumerable: true, get: function () { return tasks_1.CreateTaskDto; } });
114
132
  Object.defineProperty(exports, "GetTasksDto", { enumerable: true, get: function () { return tasks_1.GetTasksDto; } });
133
+ Object.defineProperty(exports, "StaffGetTasksDto", { enumerable: true, get: function () { return tasks_1.StaffGetTasksDto; } });
115
134
  Object.defineProperty(exports, "TaskIdDto", { enumerable: true, get: function () { return tasks_1.TaskIdDto; } });
116
135
  Object.defineProperty(exports, "TaskLinkIdDto", { enumerable: true, get: function () { return tasks_1.TaskLinkIdDto; } });
117
136
  Object.defineProperty(exports, "UpdateTaskDto", { enumerable: true, get: function () { return tasks_1.UpdateTaskDto; } });
@@ -1,5 +1,5 @@
1
1
  import type { UUID } from 'crypto';
2
- import type { ConvertLeadDto as ConvertLeadDtoType, CreateLeadDto as CreateLeadDtoType, GetLeadsDto as GetLeadsDtoType, LeadIdDto as LeadIdDtoType, UpdateLeadDto as UpdateLeadDtoType } from '@managemint-solutions/entities/leads/dto';
2
+ import type { ConvertLeadDto as ConvertLeadDtoType, CreateLeadDto as CreateLeadDtoType, GetLeadsDto as GetLeadsDtoType, StaffGetLeadsDto as StaffGetLeadsDtoType, LeadIdDto as LeadIdDtoType, UpdateLeadDto as UpdateLeadDtoType } from '@managemint-solutions/entities/leads/dto';
3
3
  import { LeadSource } from '@managemint-solutions/entities/leads/enum';
4
4
  export declare class GetLeadsDto implements Omit<GetLeadsDtoType, 'status_id_in'> {
5
5
  readonly search?: string | null;
@@ -13,6 +13,10 @@ export declare class GetLeadsDto implements Omit<GetLeadsDtoType, 'status_id_in'
13
13
  readonly completed?: boolean | null;
14
14
  readonly archive: boolean;
15
15
  }
16
+ /** A staff read across organizations, optionally narrowed to one of them. */
17
+ export declare class StaffGetLeadsDto extends GetLeadsDto implements Omit<StaffGetLeadsDtoType, 'status_id_in'> {
18
+ readonly organization_id?: string | null;
19
+ }
16
20
  export declare class LeadIdDto implements LeadIdDtoType {
17
21
  readonly leadId: string;
18
22
  }
package/dist/leads/dto.js CHANGED
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ConvertLeadDto = exports.UpdateLeadDto = exports.CreateLeadDto = exports.LeadIdDto = exports.GetLeadsDto = void 0;
12
+ exports.ConvertLeadDto = exports.UpdateLeadDto = exports.CreateLeadDto = exports.LeadIdDto = exports.StaffGetLeadsDto = exports.GetLeadsDto = void 0;
13
13
  const class_validator_1 = require("class-validator");
14
14
  const class_transformer_1 = require("class-transformer");
15
15
  const enum_1 = require("@managemint-solutions/entities/leads/enum");
@@ -107,6 +107,17 @@ __decorate([
107
107
  (0, class_validator_1.IsBoolean)({ message: 'Include archived must be a boolean' }),
108
108
  __metadata("design:type", Boolean)
109
109
  ], GetLeadsDto.prototype, "archive", void 0);
110
+ /** A staff read across organizations, optionally narrowed to one of them. */
111
+ class StaffGetLeadsDto extends GetLeadsDto {
112
+ organization_id;
113
+ }
114
+ exports.StaffGetLeadsDto = StaffGetLeadsDto;
115
+ __decorate([
116
+ (0, class_validator_1.IsOptional)(),
117
+ (0, validators_1.IsNullable)(),
118
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid organization ID format' }),
119
+ __metadata("design:type", Object)
120
+ ], StaffGetLeadsDto.prototype, "organization_id", void 0);
110
121
  class LeadIdDto {
111
122
  leadId;
112
123
  }
@@ -1,9 +1,9 @@
1
1
  import type { ClientEntity } from '@managemint-solutions/entities/clients';
2
2
  import type { MmsList } from '@managemint-solutions/entities/common';
3
3
  import type { LeadEntity, LeadSummary } from '@managemint-solutions/entities/leads';
4
- import type { AuthContext } from '../auth';
4
+ import type { ClientContext } from '../auth';
5
5
  import type { AdditionalDetailsResource } from '../additional-details';
6
- import { type AuditResource } from '../audit';
6
+ import { EntityAuditTrail, type AuditResource } from '../audit';
7
7
  import type { ClientsResource } from '../clients';
8
8
  import type { TypedSupabaseClient } from '../client';
9
9
  import type { ConvertLeadDto, CreateLeadDto, GetLeadsDto, UpdateLeadDto } from './dto';
@@ -11,11 +11,14 @@ export * from './dto';
11
11
  export declare class LeadsResource {
12
12
  private readonly supabase;
13
13
  private readonly auth;
14
- private readonly audit;
15
14
  private readonly additionalDetails;
16
15
  private readonly table;
17
- constructor(supabase: TypedSupabaseClient, auth: AuthContext, audit: AuditResource, additionalDetails: AdditionalDetailsResource);
18
- list(query: GetLeadsDto): Promise<MmsList<LeadSummary>>;
16
+ /** This record's history - its own rows and the rows that hang off it. */
17
+ readonly audit: EntityAuditTrail;
18
+ constructor(supabase: TypedSupabaseClient, auth: ClientContext, audit: AuditResource, additionalDetails: AdditionalDetailsResource);
19
+ list(query: GetLeadsDto & {
20
+ organization_id?: string | null;
21
+ }): Promise<MmsList<LeadSummary>>;
19
22
  getById(leadId: string): Promise<LeadEntity>;
20
23
  create(input: CreateLeadDto): Promise<LeadEntity>;
21
24
  update(leadId: string, input: UpdateLeadDto): Promise<LeadEntity>;
@@ -24,6 +24,7 @@ const enum_6 = require("@managemint-solutions/entities/audit-trail/enum");
24
24
  const audit_1 = require("../audit");
25
25
  const errors_1 = require("../errors");
26
26
  const paths_1 = require("../supporting-files/paths");
27
+ const tenancy_1 = require("../tenancy");
27
28
  const transforms_1 = require("../transforms");
28
29
  const won_1 = require("./won");
29
30
  __exportStar(require("./dto"), exports);
@@ -106,18 +107,19 @@ const refuse = (status, message) => new errors_1.SupabaseClientError({ status, e
106
107
  class LeadsResource {
107
108
  supabase;
108
109
  auth;
109
- audit;
110
110
  additionalDetails;
111
111
  table;
112
+ /** This record's history - its own rows and the rows that hang off it. */
113
+ audit;
112
114
  constructor(supabase, auth, audit, additionalDetails) {
113
115
  this.supabase = supabase;
114
116
  this.auth = auth;
115
- this.audit = audit;
116
117
  this.additionalDetails = additionalDetails;
117
118
  this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
118
119
  table: 'leads',
119
120
  entityType: enum_6.AuditTrailEntityType.LEADS,
120
121
  });
122
+ this.audit = new audit_1.EntityAuditTrail(supabase, auth, enum_6.AuditTrailEntityType.LEADS);
121
123
  }
122
124
  async list(query) {
123
125
  const page = query.page;
@@ -126,14 +128,16 @@ class LeadsResource {
126
128
  const trimmedSearch = query.search?.trim();
127
129
  // `order`/`range` return `this`, so the builder stays a filter builder and the conditional
128
130
  // filters below can be reassigned onto it without a cast.
129
- let leadsQuery = this.supabase
131
+ let leadsQuery = (0, tenancy_1.scopeToOrganization)(this.supabase
130
132
  .from('leads')
131
- .select(LEAD_LIST_SELECT, { count: 'estimated' })
132
- .eq('organization_id', this.auth.organization_id)
133
+ .select((0, tenancy_1.withOrganization)(LEAD_LIST_SELECT, this.auth), { count: 'estimated' }), this.auth)
133
134
  .eq('archived', query.archive)
134
135
  .eq('deleted', false)
135
136
  .order('created_at', { ascending: false })
136
137
  .range(offset, offset + pageSize - 1);
138
+ if (query.organization_id) {
139
+ leadsQuery = leadsQuery.eq('organization_id', query.organization_id);
140
+ }
137
141
  if (trimmedSearch) {
138
142
  leadsQuery = leadsQuery.or((0, transforms_1.orIlike)(['name', 'contact_person', 'email'], trimmedSearch));
139
143
  }
@@ -161,10 +165,7 @@ class LeadsResource {
161
165
  return (0, transforms_1.toMmsList)(data, page, pageSize, count);
162
166
  }
163
167
  async getById(leadId) {
164
- const { data, error } = await this.supabase
165
- .from('leads')
166
- .select(LEAD_DETAIL_SELECT)
167
- .eq('organization_id', this.auth.organization_id)
168
+ const { data, error } = await (0, tenancy_1.scopeToOrganization)(this.supabase.from('leads').select(LEAD_DETAIL_SELECT), this.auth)
168
169
  .eq('mms_id', leadId)
169
170
  .single();
170
171
  if (error)
@@ -195,7 +196,7 @@ class LeadsResource {
195
196
  // Omitted means the creator owns the lead; an explicit null leaves it unassigned.
196
197
  assigned_to_id: input.assigned_to_id === undefined ? this.auth.mms_id : input.assigned_to_id,
197
198
  lost_reason: lostReason,
198
- organization_id: this.auth.organization_id,
199
+ organization_id: (0, tenancy_1.requireOrganization)(this.auth),
199
200
  created_by: this.auth.mms_id,
200
201
  created_at: new Date().toISOString(),
201
202
  });
@@ -207,7 +208,7 @@ class LeadsResource {
207
208
  const { data, error } = await this.supabase
208
209
  .from('leads')
209
210
  .select('status_id, converted_client_id')
210
- .eq('organization_id', this.auth.organization_id)
211
+ .eq('organization_id', (0, tenancy_1.requireOrganization)(this.auth))
211
212
  .eq('mms_id', leadId)
212
213
  .single();
213
214
  if (error)
@@ -227,12 +228,12 @@ class LeadsResource {
227
228
  return this.getById(leadId);
228
229
  }
229
230
  async archive(leadId) {
230
- await (0, won_1.refuseWonLead)(this.supabase, this.auth.organization_id, leadId);
231
+ await (0, won_1.refuseWonLead)(this.supabase, (0, tenancy_1.requireOrganization)(this.auth), leadId);
231
232
  await this.table.transition(leadId, enum_6.AuditTrailAction.ARCHIVE, (0, transforms_1.archivedPatch)(this.auth.mms_id));
232
233
  return this.getById(leadId);
233
234
  }
234
235
  async unarchive(leadId) {
235
- await (0, won_1.refuseWonLead)(this.supabase, this.auth.organization_id, leadId);
236
+ await (0, won_1.refuseWonLead)(this.supabase, (0, tenancy_1.requireOrganization)(this.auth), leadId);
236
237
  await this.table.transition(leadId, enum_6.AuditTrailAction.UNARCHIVE, (0, transforms_1.unarchivedPatch)(this.auth.mms_id));
237
238
  return this.getById(leadId);
238
239
  }
@@ -242,7 +243,7 @@ class LeadsResource {
242
243
  }
243
244
  /** Soft delete - the row stays, flagged `deleted`, and `restore()` brings it back. A Won lead cannot be deleted. */
244
245
  async remove(leadId) {
245
- await (0, won_1.refuseWonLead)(this.supabase, this.auth.organization_id, leadId);
246
+ await (0, won_1.refuseWonLead)(this.supabase, (0, tenancy_1.requireOrganization)(this.auth), leadId);
246
247
  await this.table.transition(leadId, enum_6.AuditTrailAction.DELETE, (0, transforms_1.deletedPatch)(this.auth.mms_id));
247
248
  }
248
249
  /**
@@ -265,11 +266,12 @@ class LeadsResource {
265
266
  * client is created, and read back, without the caller holding any clients permission.
266
267
  */
267
268
  async convert(leadId, input, clients) {
269
+ const organizationId = (0, tenancy_1.requireOrganization)(this.auth);
268
270
  // (a) The lead, in this organization, not deleted and not converted already.
269
271
  const { data, error } = await this.supabase
270
272
  .from('leads')
271
273
  .select(LEAD_CONVERT_SELECT)
272
- .eq('organization_id', this.auth.organization_id)
274
+ .eq('organization_id', organizationId)
273
275
  .eq('mms_id', leadId)
274
276
  .maybeSingle();
275
277
  if (error)
@@ -323,7 +325,7 @@ class LeadsResource {
323
325
  const { error: moveError } = await this.supabase
324
326
  .from(table)
325
327
  .update({ entity_type: toType, entity_id: clientId })
326
- .eq('organization_id', this.auth.organization_id)
328
+ .eq('organization_id', organizationId)
327
329
  .eq('entity_type', fromType)
328
330
  .eq('entity_id', leadId);
329
331
  if (moveError)
@@ -335,7 +337,7 @@ class LeadsResource {
335
337
  const { data: files, error: filesError } = await this.supabase
336
338
  .from('supporting_files')
337
339
  .select('mms_id, name, extension')
338
- .eq('organization_id', this.auth.organization_id)
340
+ .eq('organization_id', organizationId)
339
341
  .eq('entity_type', enum_5.SupportingFilesEntityTypes.LEAD)
340
342
  .eq('entity_id', leadId);
341
343
  if (filesError)
@@ -343,7 +345,7 @@ class LeadsResource {
343
345
  for (const file of files) {
344
346
  const { error: storageError } = await this.supabase.storage
345
347
  .from(SUPPORTING_FILES_BUCKET)
346
- .move((0, paths_1.storagePath)(this.auth.organization_id, enum_5.SupportingFilesEntityTypes.LEAD, leadId, file.name, file.extension), (0, paths_1.storagePath)(this.auth.organization_id, enum_5.SupportingFilesEntityTypes.CLIENT, clientId, file.name, file.extension));
348
+ .move((0, paths_1.storagePath)(organizationId, enum_5.SupportingFilesEntityTypes.LEAD, leadId, file.name, file.extension), (0, paths_1.storagePath)(organizationId, enum_5.SupportingFilesEntityTypes.CLIENT, clientId, file.name, file.extension));
347
349
  if (storageError) {
348
350
  if (storageError.status === 404 || storageError.statusCode === '404')
349
351
  continue;
@@ -352,7 +354,7 @@ class LeadsResource {
352
354
  const { error: rowError } = await this.supabase
353
355
  .from('supporting_files')
354
356
  .update({ entity_type: enum_5.SupportingFilesEntityTypes.CLIENT, entity_id: clientId })
355
- .eq('organization_id', this.auth.organization_id)
357
+ .eq('organization_id', organizationId)
356
358
  .eq('mms_id', file.mms_id);
357
359
  if (rowError)
358
360
  throw (0, errors_1.mapPostgrestError)(rowError);
@@ -362,7 +364,7 @@ class LeadsResource {
362
364
  const { data: won, error: wonError } = await this.supabase
363
365
  .from('statuses')
364
366
  .select('mms_id')
365
- .eq('organization_id', this.auth.organization_id)
367
+ .eq('organization_id', organizationId)
366
368
  .eq('is_won', true)
367
369
  .maybeSingle();
368
370
  if (wonError)
@@ -389,7 +391,7 @@ class LeadsResource {
389
391
  const { data, error } = await this.supabase
390
392
  .from('statuses')
391
393
  .select('is_fail, is_won')
392
- .eq('organization_id', this.auth.organization_id)
394
+ .eq('organization_id', (0, tenancy_1.requireOrganization)(this.auth))
393
395
  .eq('entity_type', enum_4.StatusEntityTypes.LEAD)
394
396
  .eq('mms_id', statusId)
395
397
  .maybeSingle();
@@ -27,6 +27,7 @@ class LeaveAdjustmentsResource {
27
27
  this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
28
28
  table: 'leave_adjustments',
29
29
  entityType: enum_1.AuditTrailEntityType.LEAVE_ADJUSTMENTS,
30
+ related: { entityType: enum_1.AuditTrailEntityType.LEAVE_ENTITLEMENTS, column: 'leave_entitlement_id' },
30
31
  });
31
32
  }
32
33
  /** The adjustments of the given entitlements, oldest first. */
@@ -1,7 +1,7 @@
1
1
  import type { MmsList } from '@managemint-solutions/entities/common';
2
2
  import type { LeaveEntitlementEntity, LeavePeriod } from '@managemint-solutions/entities/leave';
3
3
  import { LeaveGrantMethod } from '@managemint-solutions/entities/leave/enum';
4
- import { type AuditActor, type AuditResource } from '../audit';
4
+ import { EntityAuditTrail, type AuditActor, type AuditResource } from '../audit';
5
5
  import type { TypedSupabaseClient } from '../client';
6
6
  import type { GetLeaveEntitlementsDto, UpdateLeaveEntitlementDto } from './dto';
7
7
  /** The create input after the api has resolved the defaults and copied the type's policy on. */
@@ -21,6 +21,8 @@ export declare class LeaveEntitlementsResource {
21
21
  private readonly supabase;
22
22
  private readonly auth;
23
23
  private readonly table;
24
+ /** This record's history - its own rows and the rows that hang off it. */
25
+ readonly audit: EntityAuditTrail;
24
26
  constructor(supabase: TypedSupabaseClient, auth: AuditActor, audit: AuditResource);
25
27
  list(query: GetLeaveEntitlementsDto): Promise<MmsList<LeaveEntitlementEntity>>;
26
28
  getById(leaveEntitlementId: string): Promise<LeaveEntitlementEntity>;
@@ -38,6 +38,8 @@ class LeaveEntitlementsResource {
38
38
  supabase;
39
39
  auth;
40
40
  table;
41
+ /** This record's history - its own rows and the rows that hang off it. */
42
+ audit;
41
43
  constructor(supabase, auth, audit) {
42
44
  this.supabase = supabase;
43
45
  this.auth = auth;
@@ -45,6 +47,7 @@ class LeaveEntitlementsResource {
45
47
  table: 'leave_entitlements',
46
48
  entityType: enum_1.AuditTrailEntityType.LEAVE_ENTITLEMENTS,
47
49
  });
50
+ this.audit = new audit_1.EntityAuditTrail(supabase, auth, enum_1.AuditTrailEntityType.LEAVE_ENTITLEMENTS);
48
51
  }
49
52
  async list(query) {
50
53
  const page = query.page;
@@ -1,7 +1,7 @@
1
1
  import type { MmsList } from '@managemint-solutions/entities/common';
2
2
  import type { LeaveCalendarEntry, LeaveRequestEntity } from '@managemint-solutions/entities/leave';
3
3
  import { LeaveRequestStatus, LeaveReviewDecision } from '@managemint-solutions/entities/leave/enum';
4
- import { type AuditActor, type AuditResource } from '../audit';
4
+ import { EntityAuditTrail, type AuditActor, type AuditResource } from '../audit';
5
5
  import type { TypedSupabaseClient } from '../client';
6
6
  import type { GetLeaveCalendarDto, GetLeaveRequestsDto } from './dto';
7
7
  /** A request as the api inserts it: the caller's own, with the days already counted. */
@@ -39,6 +39,8 @@ export declare class LeaveRequestsResource {
39
39
  private readonly supabase;
40
40
  private readonly auth;
41
41
  private readonly table;
42
+ /** This record's history - its own rows and the rows that hang off it. */
43
+ readonly audit: EntityAuditTrail;
42
44
  constructor(supabase: TypedSupabaseClient, auth: AuditActor, audit: AuditResource);
43
45
  list(query: GetLeaveRequestsDto, options?: ListOptions): Promise<MmsList<LeaveRequestEntity>>;
44
46
  getById(leaveRequestId: string): Promise<LeaveRequestEntity>;
@@ -49,6 +49,8 @@ class LeaveRequestsResource {
49
49
  supabase;
50
50
  auth;
51
51
  table;
52
+ /** This record's history - its own rows and the rows that hang off it. */
53
+ audit;
52
54
  constructor(supabase, auth, audit) {
53
55
  this.supabase = supabase;
54
56
  this.auth = auth;
@@ -56,6 +58,7 @@ class LeaveRequestsResource {
56
58
  table: 'leave_requests',
57
59
  entityType: enum_1.AuditTrailEntityType.LEAVE_REQUESTS,
58
60
  });
61
+ this.audit = new audit_1.EntityAuditTrail(supabase, auth, enum_1.AuditTrailEntityType.LEAVE_REQUESTS);
59
62
  }
60
63
  async list(query, options = {}) {
61
64
  const page = query.page;