@managemint-solutions/sdk 0.8.0 → 0.16.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 +73 -1
- package/dist/additional-details/index.d.ts +3 -1
- package/dist/additional-details/index.js +15 -28
- package/dist/additional-details/index.js.map +1 -1
- package/dist/audit/dto.d.ts +13 -0
- package/dist/audit/dto.js +90 -0
- package/dist/audit/dto.js.map +1 -0
- package/dist/audit/index.d.ts +104 -0
- package/dist/audit/index.js +308 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/billing/dto.d.ts +33 -0
- package/dist/billing/dto.js +71 -0
- package/dist/billing/dto.js.map +1 -0
- package/dist/billing/index.d.ts +35 -0
- package/dist/billing/index.js +115 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.js +23 -7
- package/dist/client.js.map +1 -1
- package/dist/clients/index.d.ts +3 -1
- package/dist/clients/index.js +25 -62
- package/dist/clients/index.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/nest/index.d.ts +22 -0
- package/dist/nest/index.js +28 -1
- package/dist/nest/index.js.map +1 -1
- package/dist/notes/index.d.ts +3 -1
- package/dist/notes/index.js +16 -27
- package/dist/notes/index.js.map +1 -1
- package/dist/notifications/dto.d.ts +10 -0
- package/dist/notifications/dto.js +63 -0
- package/dist/notifications/dto.js.map +1 -0
- package/dist/notifications/index.d.ts +139 -0
- package/dist/notifications/index.js +354 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/organizations/dto.d.ts +62 -0
- package/dist/organizations/dto.js +445 -0
- package/dist/organizations/dto.js.map +1 -0
- package/dist/organizations/index.d.ts +72 -0
- package/dist/organizations/index.js +221 -0
- package/dist/organizations/index.js.map +1 -0
- package/dist/permissions/dto.d.ts +27 -0
- package/dist/permissions/dto.js +215 -0
- package/dist/permissions/dto.js.map +1 -0
- package/dist/permissions/index.d.ts +36 -0
- package/dist/permissions/index.js +110 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/projects/index.d.ts +3 -1
- package/dist/projects/index.js +25 -62
- package/dist/projects/index.js.map +1 -1
- package/dist/service-client/index.d.ts +72 -0
- package/dist/service-client/index.js +119 -0
- package/dist/service-client/index.js.map +1 -0
- package/dist/statuses/index.d.ts +3 -1
- package/dist/statuses/index.js +17 -28
- package/dist/statuses/index.js.map +1 -1
- package/dist/supporting-files/index.d.ts +3 -1
- package/dist/supporting-files/index.js +14 -20
- package/dist/supporting-files/index.js.map +1 -1
- package/dist/tasks/index.d.ts +3 -1
- package/dist/tasks/index.js +21 -50
- package/dist/tasks/index.js.map +1 -1
- package/dist/users/dto.d.ts +48 -0
- package/dist/users/dto.js +267 -0
- package/dist/users/dto.js.map +1 -0
- package/dist/users/index.d.ts +38 -0
- package/dist/users/index.js +144 -0
- package/dist/users/index.js.map +1 -0
- package/dist/webhook-events/index.d.ts +65 -0
- package/dist/webhook-events/index.js +109 -0
- package/dist/webhook-events/index.js.map +1 -0
- package/package.json +2 -2
package/dist/projects/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.ProjectsResource = void 0;
|
|
18
|
+
const enum_1 = require("@managemint-solutions/entities/audit-trail/enum");
|
|
19
|
+
const audit_1 = require("../audit");
|
|
18
20
|
const errors_1 = require("../errors");
|
|
19
21
|
const transforms_1 = require("../transforms");
|
|
20
22
|
__exportStar(require("./dto"), exports);
|
|
@@ -104,9 +106,14 @@ const PROJECT_DETAIL_SELECT = `
|
|
|
104
106
|
class ProjectsResource {
|
|
105
107
|
supabase;
|
|
106
108
|
auth;
|
|
107
|
-
|
|
109
|
+
table;
|
|
110
|
+
constructor(supabase, auth, audit) {
|
|
108
111
|
this.supabase = supabase;
|
|
109
112
|
this.auth = auth;
|
|
113
|
+
this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
|
|
114
|
+
table: 'projects',
|
|
115
|
+
entityType: enum_1.AuditTrailEntityType.PROJECTS,
|
|
116
|
+
});
|
|
110
117
|
}
|
|
111
118
|
async list(query) {
|
|
112
119
|
const page = query.page;
|
|
@@ -198,101 +205,57 @@ class ProjectsResource {
|
|
|
198
205
|
return data;
|
|
199
206
|
}
|
|
200
207
|
async create(input) {
|
|
201
|
-
const
|
|
202
|
-
.from('projects')
|
|
203
|
-
.insert({
|
|
208
|
+
const row = await this.table.insert({
|
|
204
209
|
...input,
|
|
205
210
|
start_date: (0, transforms_1.toDateInput)(input.start_date),
|
|
206
211
|
end_date: (0, transforms_1.toDateInput)(input.end_date),
|
|
207
212
|
organization_id: this.auth.organization_id,
|
|
208
213
|
created_by: this.auth.mms_id,
|
|
209
214
|
created_at: new Date().toISOString(),
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
.single();
|
|
213
|
-
if (error)
|
|
214
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
215
|
-
return this.getById(data.mms_id);
|
|
215
|
+
});
|
|
216
|
+
return this.getById(row.mms_id);
|
|
216
217
|
}
|
|
217
218
|
async update(projectId, input) {
|
|
218
|
-
|
|
219
|
-
.from('projects')
|
|
220
|
-
.update({
|
|
219
|
+
await this.table.update(projectId, {
|
|
221
220
|
...input,
|
|
222
221
|
start_date: (0, transforms_1.toDateInput)(input.start_date),
|
|
223
222
|
end_date: (0, transforms_1.toDateInput)(input.end_date),
|
|
224
223
|
last_updated_by: this.auth.mms_id,
|
|
225
224
|
updated_at: new Date().toISOString(),
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
.eq('mms_id', projectId)
|
|
229
|
-
.select('mms_id')
|
|
230
|
-
.single();
|
|
231
|
-
if (error)
|
|
232
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
233
|
-
return this.getById(data.mms_id);
|
|
225
|
+
});
|
|
226
|
+
return this.getById(projectId);
|
|
234
227
|
}
|
|
235
228
|
async archive(projectId) {
|
|
236
|
-
|
|
237
|
-
.from('projects')
|
|
238
|
-
.update({
|
|
229
|
+
await this.table.transition(projectId, enum_1.AuditTrailAction.ARCHIVE, {
|
|
239
230
|
archived: true,
|
|
240
231
|
archived_at: new Date().toISOString(),
|
|
241
232
|
archived_by: this.auth.mms_id,
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
.eq('mms_id', projectId)
|
|
245
|
-
.select('mms_id')
|
|
246
|
-
.single();
|
|
247
|
-
if (error)
|
|
248
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
249
|
-
return this.getById(data.mms_id);
|
|
233
|
+
});
|
|
234
|
+
return this.getById(projectId);
|
|
250
235
|
}
|
|
251
236
|
async unarchive(projectId) {
|
|
252
|
-
|
|
253
|
-
.from('projects')
|
|
254
|
-
.update({
|
|
237
|
+
await this.table.transition(projectId, enum_1.AuditTrailAction.UNARCHIVE, {
|
|
255
238
|
archived: false,
|
|
256
239
|
unarchived_at: new Date().toISOString(),
|
|
257
240
|
unarchived_by: this.auth.mms_id,
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
.eq('mms_id', projectId)
|
|
261
|
-
.select('mms_id')
|
|
262
|
-
.single();
|
|
263
|
-
if (error)
|
|
264
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
265
|
-
return this.getById(data.mms_id);
|
|
241
|
+
});
|
|
242
|
+
return this.getById(projectId);
|
|
266
243
|
}
|
|
267
244
|
async restore(projectId) {
|
|
268
|
-
|
|
269
|
-
.from('projects')
|
|
270
|
-
.update({
|
|
245
|
+
await this.table.transition(projectId, enum_1.AuditTrailAction.RESTORE, {
|
|
271
246
|
deleted: false,
|
|
272
247
|
restored_at: new Date().toISOString(),
|
|
273
248
|
restored_by: this.auth.mms_id,
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
.eq('mms_id', projectId)
|
|
277
|
-
.select('mms_id')
|
|
278
|
-
.single();
|
|
279
|
-
if (error)
|
|
280
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
281
|
-
return this.getById(data.mms_id);
|
|
249
|
+
});
|
|
250
|
+
return this.getById(projectId);
|
|
282
251
|
}
|
|
283
252
|
/** Soft delete — the row stays, flagged `deleted`, and `restore()` brings it back. */
|
|
284
253
|
async remove(projectId) {
|
|
285
|
-
|
|
286
|
-
.from('projects')
|
|
287
|
-
.update({
|
|
254
|
+
await this.table.transition(projectId, enum_1.AuditTrailAction.DELETE, {
|
|
288
255
|
deleted: true,
|
|
289
256
|
deleted_at: new Date().toISOString(),
|
|
290
257
|
deleted_by: this.auth.mms_id,
|
|
291
|
-
})
|
|
292
|
-
.eq('organization_id', this.auth.organization_id)
|
|
293
|
-
.eq('mms_id', projectId);
|
|
294
|
-
if (error)
|
|
295
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
258
|
+
});
|
|
296
259
|
}
|
|
297
260
|
}
|
|
298
261
|
exports.ProjectsResource = ProjectsResource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/projects/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/projects/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,0EAGyD;AAEzD,oCAA+E;AAE/E,sCAA8C;AAC9C,8CAA4C;AAG5C,wCAAsB;AAEtB,wEAAwE;AACxE,gGAAgG;AAChG,4EAA4E;AAC5E,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;OAcZ,CAAC;AAEjB,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgEd,CAAC;AAEjB,MAAa,gBAAgB;IAIR;IACA;IAJF,KAAK,CAAe;IAErC,YACmB,QAA6B,EAC7B,IAAiB,EAClC,KAAoB;QAFH,aAAQ,GAAR,QAAQ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} from '../audit';
|
|
2
|
+
import type { TypedSupabaseClient } from '../client';
|
|
3
|
+
import { BillingResource } from '../billing';
|
|
4
|
+
import { NotificationsOutboxResource } from '../notifications';
|
|
5
|
+
import { OrganizationsResource, OrganizationSignupResource } from '../organizations';
|
|
6
|
+
import { PermissionsResource } from '../permissions';
|
|
7
|
+
import { UsersResource } from '../users';
|
|
8
|
+
import { WebhookEventsResource } from '../webhook-events';
|
|
9
|
+
export type SupabaseServiceClientConfig = {
|
|
10
|
+
url: string;
|
|
11
|
+
/** Service-role key — every query bypasses RLS. */
|
|
12
|
+
serviceRoleKey: string;
|
|
13
|
+
/** Where a failed audit insert is reported. Defaults to `console.error`. */
|
|
14
|
+
onAuditError?: AuditErrorHandler;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The organization-scoped half of the service client. Everything here is attributed to one
|
|
18
|
+
* `AuditActor`, so writes land in `audit_logs` the same way a caller's own would — with
|
|
19
|
+
* `mms_id: null` when the actor is the system (a webhook, a queue worker, provisioning).
|
|
20
|
+
*/
|
|
21
|
+
export declare class SupabaseOrganizationScope {
|
|
22
|
+
private readonly supabase;
|
|
23
|
+
readonly actor: AuditActor;
|
|
24
|
+
readonly audit: AuditResource;
|
|
25
|
+
readonly billing: BillingResource;
|
|
26
|
+
readonly organizations: OrganizationsResource;
|
|
27
|
+
readonly permissions: PermissionsResource;
|
|
28
|
+
readonly users: UsersResource;
|
|
29
|
+
constructor(supabase: TypedSupabaseClient, actor: AuditActor, onAuditError?: AuditErrorHandler);
|
|
30
|
+
/**
|
|
31
|
+
* An audited table bound to this organization and actor — the shape the api hand-rolls today
|
|
32
|
+
* as a local `auditedTables(client, organizationId)` factory in billing, provisioning,
|
|
33
|
+
* subscriptions and both webhook handler services.
|
|
34
|
+
*/
|
|
35
|
+
table(options: AuditedTableOptions): AuditedTable;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The client for work that has no caller and no RLS context to run under: inbound webhooks
|
|
39
|
+
* (Paystack, Resend, the Supabase `send_email` hook), the notification queue worker, unauthenticated
|
|
40
|
+
* signup, and the writes RLS reserves for the service role outright — the ledger, the outbox, the
|
|
41
|
+
* webhook event logs, `organizations` INSERT, `permissions` INSERT/DELETE.
|
|
42
|
+
*
|
|
43
|
+
* It decodes no JWT, because there is none. Cross-org lookups (find the organization behind a
|
|
44
|
+
* Paystack customer code) hang off the client itself; anything attributable goes through
|
|
45
|
+
* `forOrganization`, which supplies the audit actor the resources need.
|
|
46
|
+
*/
|
|
47
|
+
export declare class SupabaseServiceClient {
|
|
48
|
+
private readonly config;
|
|
49
|
+
readonly supabase: TypedSupabaseClient;
|
|
50
|
+
readonly notifications: NotificationsOutboxResource;
|
|
51
|
+
readonly signup: OrganizationSignupResource;
|
|
52
|
+
readonly paystackEvents: WebhookEventsResource;
|
|
53
|
+
readonly resendEvents: WebhookEventsResource;
|
|
54
|
+
constructor(config: SupabaseServiceClientConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Scope to one organization once it is known. `actorMmsId` stays `null` for system work —
|
|
57
|
+
* `audit_logs.created_by` is nullable precisely so an unattributed write is still recorded.
|
|
58
|
+
*/
|
|
59
|
+
forOrganization(organizationId: string, actorMmsId?: string | null): SupabaseOrganizationScope;
|
|
60
|
+
/**
|
|
61
|
+
* Finds the organization behind an external identifier — a Paystack customer or subscription
|
|
62
|
+
* code. Deliberately unscoped: a webhook knows only the provider's own id, and which tenant
|
|
63
|
+
* it belongs to is exactly what this answers.
|
|
64
|
+
*/
|
|
65
|
+
findOrganizationBy(column: string, value: string): Promise<Record<string, unknown> | null>;
|
|
66
|
+
/**
|
|
67
|
+
* A ledger row by id alone. Also unscoped by necessity: a `charge.success` carries the
|
|
68
|
+
* transaction id in its metadata, and the row is what says which tenant it belongs to.
|
|
69
|
+
*/
|
|
70
|
+
findTransaction(transactionId: string): Promise<Record<string, unknown> | null>;
|
|
71
|
+
}
|
|
72
|
+
export declare const createSupabaseServiceClient: (config: SupabaseServiceClientConfig) => SupabaseServiceClient;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSupabaseServiceClient = exports.SupabaseServiceClient = exports.SupabaseOrganizationScope = void 0;
|
|
4
|
+
const supabase_js_1 = require("@supabase/supabase-js");
|
|
5
|
+
const audit_1 = require("../audit");
|
|
6
|
+
const enum_1 = require("@managemint-solutions/entities/audit-trail/enum");
|
|
7
|
+
const billing_1 = require("../billing");
|
|
8
|
+
const notifications_1 = require("../notifications");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const organizations_1 = require("../organizations");
|
|
11
|
+
const permissions_1 = require("../permissions");
|
|
12
|
+
const users_1 = require("../users");
|
|
13
|
+
const webhook_events_1 = require("../webhook-events");
|
|
14
|
+
/**
|
|
15
|
+
* The organization-scoped half of the service client. Everything here is attributed to one
|
|
16
|
+
* `AuditActor`, so writes land in `audit_logs` the same way a caller's own would — with
|
|
17
|
+
* `mms_id: null` when the actor is the system (a webhook, a queue worker, provisioning).
|
|
18
|
+
*/
|
|
19
|
+
class SupabaseOrganizationScope {
|
|
20
|
+
supabase;
|
|
21
|
+
actor;
|
|
22
|
+
audit;
|
|
23
|
+
billing;
|
|
24
|
+
organizations;
|
|
25
|
+
permissions;
|
|
26
|
+
users;
|
|
27
|
+
constructor(supabase, actor, onAuditError) {
|
|
28
|
+
this.supabase = supabase;
|
|
29
|
+
this.actor = actor;
|
|
30
|
+
this.audit = new audit_1.AuditResource(supabase, actor, onAuditError);
|
|
31
|
+
this.billing = new billing_1.BillingResource(supabase, actor, this.audit);
|
|
32
|
+
this.organizations = new organizations_1.OrganizationsResource(supabase, actor, this.audit);
|
|
33
|
+
this.permissions = new permissions_1.PermissionsResource(supabase, actor, this.audit);
|
|
34
|
+
this.users = new users_1.UsersResource(supabase, actor, this.audit);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* An audited table bound to this organization and actor — the shape the api hand-rolls today
|
|
38
|
+
* as a local `auditedTables(client, organizationId)` factory in billing, provisioning,
|
|
39
|
+
* subscriptions and both webhook handler services.
|
|
40
|
+
*/
|
|
41
|
+
table(options) {
|
|
42
|
+
return (0, audit_1.auditedTable)(this.supabase, this.actor, this.audit, options);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.SupabaseOrganizationScope = SupabaseOrganizationScope;
|
|
46
|
+
/**
|
|
47
|
+
* The client for work that has no caller and no RLS context to run under: inbound webhooks
|
|
48
|
+
* (Paystack, Resend, the Supabase `send_email` hook), the notification queue worker, unauthenticated
|
|
49
|
+
* signup, and the writes RLS reserves for the service role outright — the ledger, the outbox, the
|
|
50
|
+
* webhook event logs, `organizations` INSERT, `permissions` INSERT/DELETE.
|
|
51
|
+
*
|
|
52
|
+
* It decodes no JWT, because there is none. Cross-org lookups (find the organization behind a
|
|
53
|
+
* Paystack customer code) hang off the client itself; anything attributable goes through
|
|
54
|
+
* `forOrganization`, which supplies the audit actor the resources need.
|
|
55
|
+
*/
|
|
56
|
+
class SupabaseServiceClient {
|
|
57
|
+
config;
|
|
58
|
+
supabase; // escape hatch for not-yet-migrated queries
|
|
59
|
+
notifications;
|
|
60
|
+
signup;
|
|
61
|
+
paystackEvents;
|
|
62
|
+
resendEvents;
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.config = config;
|
|
65
|
+
this.supabase = (0, supabase_js_1.createClient)(config.url, config.serviceRoleKey, {
|
|
66
|
+
auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false },
|
|
67
|
+
});
|
|
68
|
+
this.paystackEvents = new webhook_events_1.WebhookEventsResource(this.supabase, 'paystack_webhook_events');
|
|
69
|
+
this.resendEvents = new webhook_events_1.WebhookEventsResource(this.supabase, 'resend_webhook_events');
|
|
70
|
+
this.signup = new organizations_1.OrganizationSignupResource(this.supabase, (organizationId) => this.forOrganization(organizationId).audit);
|
|
71
|
+
// The outbox spans organizations — the row it is about carries its own — so it takes a
|
|
72
|
+
// factory and scopes per write rather than being built inside one organization's scope.
|
|
73
|
+
this.notifications = new notifications_1.NotificationsOutboxResource(this.supabase, (organizationId) => this.forOrganization(organizationId).table({
|
|
74
|
+
table: 'notifications',
|
|
75
|
+
entityType: enum_1.AuditTrailEntityType.NOTIFICATION,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Scope to one organization once it is known. `actorMmsId` stays `null` for system work —
|
|
80
|
+
* `audit_logs.created_by` is nullable precisely so an unattributed write is still recorded.
|
|
81
|
+
*/
|
|
82
|
+
forOrganization(organizationId, actorMmsId = null) {
|
|
83
|
+
return new SupabaseOrganizationScope(this.supabase, { mms_id: actorMmsId, organization_id: organizationId }, this.config.onAuditError);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Finds the organization behind an external identifier — a Paystack customer or subscription
|
|
87
|
+
* code. Deliberately unscoped: a webhook knows only the provider's own id, and which tenant
|
|
88
|
+
* it belongs to is exactly what this answers.
|
|
89
|
+
*/
|
|
90
|
+
async findOrganizationBy(column, value) {
|
|
91
|
+
const { data, error } = await this.supabase
|
|
92
|
+
.from('organizations')
|
|
93
|
+
.select('*')
|
|
94
|
+
.eq(column, value)
|
|
95
|
+
.limit(1)
|
|
96
|
+
.maybeSingle();
|
|
97
|
+
if (error)
|
|
98
|
+
throw (0, errors_1.mapPostgrestError)(error);
|
|
99
|
+
return (data ?? null);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A ledger row by id alone. Also unscoped by necessity: a `charge.success` carries the
|
|
103
|
+
* transaction id in its metadata, and the row is what says which tenant it belongs to.
|
|
104
|
+
*/
|
|
105
|
+
async findTransaction(transactionId) {
|
|
106
|
+
const { data, error } = await this.supabase
|
|
107
|
+
.from('billing_transactions')
|
|
108
|
+
.select('*')
|
|
109
|
+
.eq('mms_id', transactionId)
|
|
110
|
+
.maybeSingle();
|
|
111
|
+
if (error)
|
|
112
|
+
throw (0, errors_1.mapPostgrestError)(error);
|
|
113
|
+
return (data ?? null);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.SupabaseServiceClient = SupabaseServiceClient;
|
|
117
|
+
const createSupabaseServiceClient = (config) => new SupabaseServiceClient(config);
|
|
118
|
+
exports.createSupabaseServiceClient = createSupabaseServiceClient;
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service-client/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AACrD,oCAOkB;AAClB,0EAAuF;AAEvF,wCAA6C;AAC7C,oDAA+D;AAC/D,sCAA8C;AAC9C,oDAAqF;AACrF,gDAAqD;AACrD,oCAAyC;AACzC,sDAA0D;AAU1D;;;;GAIG;AACH,MAAa,yBAAyB;IAQjB;IACR;IARF,KAAK,CAAgB;IACrB,OAAO,CAAkB;IACzB,aAAa,CAAwB;IACrC,WAAW,CAAsB;IACjC,KAAK,CAAgB;IAE9B,YACmB,QAA6B,EACrC,KAAiB,EAC1B,YAAgC;QAFf,aAAQ,GAAR,QAAQ,CAAqB;QACrC,UAAK,GAAL,KAAK,CAAY;QAG1B,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,GAAG,IAAI,yBAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAChE,IAAI,CAAC,aAAa,GAAG,IAAI,qCAAqB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5E,IAAI,CAAC,WAAW,GAAG,IAAI,iCAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,I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C;AAFjD,QAAA,2BAA2B,+BAEsB"}
|
package/dist/statuses/index.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import type { StatusEntity } from '@managemint-solutions/entities/status';
|
|
|
2
2
|
import type { AddStatusDto, UpdateStatusDto } from '@managemint-solutions/entities/status/dto';
|
|
3
3
|
import { StatusEntityTypes } from '@managemint-solutions/entities/status/enum';
|
|
4
4
|
import type { AuthContext } from '../auth';
|
|
5
|
+
import { type AuditResource } from '../audit';
|
|
5
6
|
import type { TypedSupabaseClient } from '../client';
|
|
6
7
|
export * from './dto';
|
|
7
8
|
export declare class StatusesResource {
|
|
8
9
|
private readonly supabase;
|
|
9
10
|
private readonly auth;
|
|
10
|
-
|
|
11
|
+
private readonly table;
|
|
12
|
+
constructor(supabase: TypedSupabaseClient, auth: AuthContext, audit: AuditResource);
|
|
11
13
|
list(entity: StatusEntityTypes): Promise<StatusEntity[]>;
|
|
12
14
|
create(input: AddStatusDto): Promise<StatusEntity>;
|
|
13
15
|
update(statusId: string, input: UpdateStatusDto): Promise<StatusEntity>;
|
package/dist/statuses/index.js
CHANGED
|
@@ -15,18 +15,27 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.StatusesResource = void 0;
|
|
18
|
+
const enum_1 = require("@managemint-solutions/entities/audit-trail/enum");
|
|
19
|
+
const audit_1 = require("../audit");
|
|
18
20
|
const errors_1 = require("../errors");
|
|
19
21
|
__exportStar(require("./dto"), exports);
|
|
20
22
|
// The public contract is the shared StatusEntity from @managemint-solutions/entities; the
|
|
21
23
|
// `as StatusEntity` casts declare the shape the select string below produces (the columns are
|
|
22
24
|
// defined in the api's supabase/migrations).
|
|
23
25
|
const STATUS_SELECT = 'mms_id, label, colour';
|
|
26
|
+
// The audited write returns the whole row; the wire shape is the STATUS_SELECT columns.
|
|
27
|
+
const toStatus = (row) => ({ mms_id: row.mms_id, label: row.label, colour: row.colour });
|
|
24
28
|
class StatusesResource {
|
|
25
29
|
supabase;
|
|
26
30
|
auth;
|
|
27
|
-
|
|
31
|
+
table;
|
|
32
|
+
constructor(supabase, auth, audit) {
|
|
28
33
|
this.supabase = supabase;
|
|
29
34
|
this.auth = auth;
|
|
35
|
+
this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
|
|
36
|
+
table: 'statuses',
|
|
37
|
+
entityType: enum_1.AuditTrailEntityType.STATUS,
|
|
38
|
+
});
|
|
30
39
|
}
|
|
31
40
|
async list(entity) {
|
|
32
41
|
const { data, error } = await this.supabase
|
|
@@ -39,46 +48,26 @@ class StatusesResource {
|
|
|
39
48
|
return data;
|
|
40
49
|
}
|
|
41
50
|
async create(input) {
|
|
42
|
-
const
|
|
43
|
-
.from('statuses')
|
|
44
|
-
.insert({
|
|
51
|
+
const row = await this.table.insert({
|
|
45
52
|
label: input.label,
|
|
46
53
|
colour: input.colour,
|
|
47
54
|
entity_type: input.entity,
|
|
48
55
|
organization_id: this.auth.organization_id,
|
|
49
56
|
created_by: this.auth.mms_id,
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
.single();
|
|
53
|
-
if (error)
|
|
54
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
55
|
-
return data;
|
|
57
|
+
});
|
|
58
|
+
return toStatus(row);
|
|
56
59
|
}
|
|
57
60
|
async update(statusId, input) {
|
|
58
|
-
const
|
|
59
|
-
.from('statuses')
|
|
60
|
-
.update({
|
|
61
|
+
const row = await this.table.update(statusId, {
|
|
61
62
|
label: input.label,
|
|
62
63
|
colour: input.colour,
|
|
63
64
|
updated_at: new Date().toISOString(),
|
|
64
65
|
last_updated_by: this.auth.mms_id,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
.eq('organization_id', this.auth.organization_id)
|
|
68
|
-
.select(STATUS_SELECT)
|
|
69
|
-
.single();
|
|
70
|
-
if (error)
|
|
71
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
72
|
-
return data;
|
|
66
|
+
});
|
|
67
|
+
return toStatus(row);
|
|
73
68
|
}
|
|
74
69
|
async remove(statusId) {
|
|
75
|
-
|
|
76
|
-
.from('statuses')
|
|
77
|
-
.delete()
|
|
78
|
-
.eq('mms_id', statusId)
|
|
79
|
-
.eq('organization_id', this.auth.organization_id);
|
|
80
|
-
if (error)
|
|
81
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
70
|
+
await this.table.remove(statusId);
|
|
82
71
|
}
|
|
83
72
|
}
|
|
84
73
|
exports.StatusesResource = StatusesResource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/statuses/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/statuses/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,0EAAuF;AAEvF,oCAA8F;AAE9F,sCAA8C;AAE9C,wCAAsB;AAEtB,0FAA0F;AAC1F,8FAA8F;AAC9F,6CAA6C;AAC7C,MAAM,aAAa,GAAG,uBAAgC,CAAC;AAEvD,wFAAwF;AACxF,MAAM,QAAQ,GAAG,CAAC,GAAa,EAAgB,EAAE,CAC/C,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAA4B,CAAC;AAE5F,MAAa,gBAAgB;IAIR;IACA;IAJF,KAAK,CAAe;IAErC,YACmB,QAA6B,EAC7B,IAAiB,EAClC,KAAoB;QAFH,aAAQ,GAAR,QAAQ,CAAqB;QAC7B,SAAI,GAAJ,IAAI,CAAa;QAGlC,IAAI,CAAC,KAAK,GAAG,IAAA,oBAAY,EAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE;YAC/C,KAAK,EAAE,UAAU;YACjB,UAAU,EAAE,2BAAoB,CAAC,MAAM;SACx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I,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;CACF;AAhDD,4CAgDC"}
|
|
@@ -2,13 +2,15 @@ import type { SupportingFileEntity, SupportingFilePresignedUrl } from '@managemi
|
|
|
2
2
|
import type { UploadSupportingFilesDto } from '@managemint-solutions/entities/supporting-files/dto';
|
|
3
3
|
import { SupportingFilesEntityTypes } from '@managemint-solutions/entities/supporting-files/enum';
|
|
4
4
|
import type { AuthContext } from '../auth';
|
|
5
|
+
import { type AuditResource } from '../audit';
|
|
5
6
|
import type { TypedSupabaseClient } from '../client';
|
|
6
7
|
export * from './dto';
|
|
7
8
|
export * from './paths';
|
|
8
9
|
export declare class SupportingFilesResource {
|
|
9
10
|
private readonly supabase;
|
|
10
11
|
private readonly auth;
|
|
11
|
-
|
|
12
|
+
private readonly table;
|
|
13
|
+
constructor(supabase: TypedSupabaseClient, auth: AuthContext, audit: AuditResource);
|
|
12
14
|
getPresignedUrl(supportingFileId: string): Promise<SupportingFilePresignedUrl>;
|
|
13
15
|
list(entity: SupportingFilesEntityTypes, entityId: string): Promise<SupportingFileEntity[]>;
|
|
14
16
|
upload(entity: SupportingFilesEntityTypes, entityId: string, input: UploadSupportingFilesDto): Promise<SupportingFileEntity[]>;
|
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.SupportingFilesResource = void 0;
|
|
18
|
+
const enum_1 = require("@managemint-solutions/entities/audit-trail/enum");
|
|
19
|
+
const audit_1 = require("../audit");
|
|
18
20
|
const errors_1 = require("../errors");
|
|
19
21
|
const paths_1 = require("./paths");
|
|
20
22
|
__exportStar(require("./dto"), exports);
|
|
@@ -31,9 +33,14 @@ const UPLOAD_BATCH_SIZE = 5;
|
|
|
31
33
|
class SupportingFilesResource {
|
|
32
34
|
supabase;
|
|
33
35
|
auth;
|
|
34
|
-
|
|
36
|
+
table;
|
|
37
|
+
constructor(supabase, auth, audit) {
|
|
35
38
|
this.supabase = supabase;
|
|
36
39
|
this.auth = auth;
|
|
40
|
+
this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
|
|
41
|
+
table: 'supporting_files',
|
|
42
|
+
entityType: enum_1.AuditTrailEntityType.SUPPORTING_FILES,
|
|
43
|
+
});
|
|
37
44
|
}
|
|
38
45
|
async getPresignedUrl(supportingFileId) {
|
|
39
46
|
const { data, error } = await this.supabase
|
|
@@ -89,7 +96,7 @@ class SupportingFilesResource {
|
|
|
89
96
|
// Only files without an existing row get one — the rest were refreshed in place above.
|
|
90
97
|
const newFiles = input.files.filter((file) => !existingFileNames.includes(file.name));
|
|
91
98
|
if (newFiles.length > 0) {
|
|
92
|
-
|
|
99
|
+
await this.table.insertMany(newFiles.map((file) => ({
|
|
93
100
|
...(0, paths_1.splitFileName)(file.name),
|
|
94
101
|
entity_type: entity,
|
|
95
102
|
entity_id: entityId,
|
|
@@ -97,30 +104,17 @@ class SupportingFilesResource {
|
|
|
97
104
|
created_at: new Date().toISOString(),
|
|
98
105
|
created_by: this.auth.mms_id,
|
|
99
106
|
})));
|
|
100
|
-
if (error)
|
|
101
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
102
107
|
}
|
|
103
108
|
return this.list(entity, entityId);
|
|
104
109
|
}
|
|
105
110
|
async remove(supportingFileId) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
.select('entity_type, entity_id, name, extension')
|
|
109
|
-
.eq('mms_id', supportingFileId)
|
|
110
|
-
.eq('organization_id', this.auth.organization_id)
|
|
111
|
-
.single();
|
|
112
|
-
if (error)
|
|
113
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
114
|
-
const { error: deleteError } = await this.supabase
|
|
115
|
-
.from('supporting_files')
|
|
116
|
-
.delete()
|
|
117
|
-
.eq('mms_id', supportingFileId)
|
|
118
|
-
.eq('organization_id', this.auth.organization_id);
|
|
119
|
-
if (deleteError)
|
|
120
|
-
throw (0, errors_1.mapPostgrestError)(deleteError);
|
|
111
|
+
// The row goes first — the helper's pre-read hands back what the object path is built from.
|
|
112
|
+
const data = await this.table.remove(supportingFileId);
|
|
121
113
|
const { error: storageError } = await this.supabase.storage
|
|
122
114
|
.from(BUCKET)
|
|
123
|
-
.remove([
|
|
115
|
+
.remove([
|
|
116
|
+
(0, paths_1.storagePath)(data.entity_type, data.entity_id, data.name, data.extension),
|
|
117
|
+
]);
|
|
124
118
|
if (storageError) {
|
|
125
119
|
throw (0, errors_1.mapStorageError)(storageError, `Failed to delete file: ${data.name}.${data.extension}`);
|
|
126
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/supporting-files/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/supporting-files/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAMA,0EAAuF;AAEvF,oCAA+E;AAE/E,sCAA+D;AAC/D,mCAAqD;AAErD,wCAAsB;AACtB,0CAAwB;AAExB,qDAAqD;AACrD,MAAM,MAAM,GAAG,kBAAkB,CAAC;AAClC,qDAAqD;AACrD,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,wDAAwD;AACxD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,kGAAkG;AAClG,2FAA2F;AAC3F,6CAA6C;AAC7C,MAAa,uBAAuB;IAIf;IACA;IAJF,KAAK,CAAe;IAErC,YACmB,QAA6B,EAC7B,IAAiB,EAClC,KAAoB;QAFH,aAAQ,GAAR,QAAQ,CAAqB;QAC7B,SAAI,GAAJ,IAAI,CAAa;QAGlC,IAAI,CAAC,KAAK,GAAG,IAAA,oBAAY,EAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE;YAC/C,KAAK,EAAE,kBAAkB;YACzB,UAAU,EAAE,2BAAoB,CAAC,gBAAgB;SA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CAAC;aACZ,MAAM,CAAC;YACN,IAAA,mBAAW,EACT,IAAI,CAAC,WAAqB,EAC1B,IAAI,CAAC,SAAmB,EACxB,IAAI,CAAC,IAAc,EACnB,IAAI,CAAC,SAAmB,CACzB;SACF,CAAC,CAAC;QACL,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,IAAA,wBAAe,EAAC,YAAY,EAAE,0BAA0B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;CACF;AApHD,0DAoHC"}
|
package/dist/tasks/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { MmsList } from '@managemint-solutions/entities/common';
|
|
2
2
|
import type { TaskEntity, TaskSummary } from '@managemint-solutions/entities/tasks';
|
|
3
3
|
import type { AuthContext } from '../auth';
|
|
4
|
+
import { type AuditResource } from '../audit';
|
|
4
5
|
import type { TypedSupabaseClient } from '../client';
|
|
5
6
|
import type { CreateTaskDto, GetTasksDto, UpdateTaskDto } from './dto';
|
|
6
7
|
export * from './dto';
|
|
7
8
|
export declare class TasksResource {
|
|
8
9
|
private readonly supabase;
|
|
9
10
|
private readonly auth;
|
|
10
|
-
|
|
11
|
+
private readonly table;
|
|
12
|
+
constructor(supabase: TypedSupabaseClient, auth: AuthContext, audit: AuditResource);
|
|
11
13
|
list(query: GetTasksDto): Promise<MmsList<TaskSummary>>;
|
|
12
14
|
getById(taskId: string): Promise<TaskEntity>;
|
|
13
15
|
create(input: CreateTaskDto): Promise<TaskEntity>;
|