@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/client.js
CHANGED
|
@@ -3,19 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createSupabaseClient = exports.SupabaseClient = void 0;
|
|
4
4
|
const supabase_js_1 = require("@supabase/supabase-js");
|
|
5
5
|
const auth_1 = require("./auth");
|
|
6
|
+
const audit_1 = require("./audit");
|
|
6
7
|
const additional_details_1 = require("./additional-details");
|
|
7
8
|
const clients_1 = require("./clients");
|
|
8
9
|
const notes_1 = require("./notes");
|
|
10
|
+
const notifications_1 = require("./notifications");
|
|
11
|
+
const organizations_1 = require("./organizations");
|
|
12
|
+
const permissions_1 = require("./permissions");
|
|
9
13
|
const projects_1 = require("./projects");
|
|
10
14
|
const statuses_1 = require("./statuses");
|
|
11
15
|
const supporting_files_1 = require("./supporting-files");
|
|
12
16
|
const tasks_1 = require("./tasks");
|
|
17
|
+
const users_1 = require("./users");
|
|
13
18
|
class SupabaseClient {
|
|
14
19
|
supabase; // escape hatch for not-yet-migrated queries
|
|
15
20
|
auth;
|
|
21
|
+
audit;
|
|
16
22
|
statuses;
|
|
17
23
|
additionalDetails;
|
|
18
24
|
notes;
|
|
25
|
+
notifications;
|
|
26
|
+
organizations;
|
|
27
|
+
permissions;
|
|
28
|
+
users;
|
|
19
29
|
supportingFiles;
|
|
20
30
|
clients;
|
|
21
31
|
projects;
|
|
@@ -26,13 +36,19 @@ class SupabaseClient {
|
|
|
26
36
|
global: { headers: { Authorization: `Bearer ${config.accessToken}` } },
|
|
27
37
|
auth: { persistSession: false, autoRefreshToken: false },
|
|
28
38
|
});
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
39
|
+
// Built before the resources: every write they make goes through it.
|
|
40
|
+
this.audit = new audit_1.AuditResource(this.supabase, this.auth, config.onAuditError);
|
|
41
|
+
this.statuses = new statuses_1.StatusesResource(this.supabase, this.auth, this.audit);
|
|
42
|
+
this.additionalDetails = new additional_details_1.AdditionalDetailsResource(this.supabase, this.auth, this.audit);
|
|
43
|
+
this.notes = new notes_1.NotesResource(this.supabase, this.auth, this.audit);
|
|
44
|
+
this.notifications = new notifications_1.NotificationsResource(this.supabase, this.auth, this.audit);
|
|
45
|
+
this.organizations = new organizations_1.OrganizationsResource(this.supabase, this.auth, this.audit);
|
|
46
|
+
this.permissions = new permissions_1.PermissionsResource(this.supabase, this.auth, this.audit);
|
|
47
|
+
this.users = new users_1.UsersResource(this.supabase, this.auth, this.audit);
|
|
48
|
+
this.supportingFiles = new supporting_files_1.SupportingFilesResource(this.supabase, this.auth, this.audit);
|
|
49
|
+
this.clients = new clients_1.ClientsResource(this.supabase, this.auth, this.audit);
|
|
50
|
+
this.projects = new projects_1.ProjectsResource(this.supabase, this.auth, this.audit);
|
|
51
|
+
this.tasks = new tasks_1.TasksResource(this.supabase, this.auth, this.audit);
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
54
|
exports.SupabaseClient = SupabaseClient;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,uDAA8F;AAC9F,iCAA6D;AAC7D,6DAAiE;AACjE,uCAA4C;AAC5C,mCAAwC;AACxC,yCAA8C;AAC9C,yCAA8C;AAC9C,yDAA6D;AAC7D,mCAAwC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,uDAA8F;AAC9F,iCAA6D;AAC7D,mCAAgE;AAChE,6DAAiE;AACjE,uCAA4C;AAC5C,mCAAwC;AACxC,mDAAwD;AACxD,mDAAwD;AACxD,+CAAoD;AACpD,yCAA8C;AAC9C,yCAA8C;AAC9C,yDAA6D;AAC7D,mCAAwC;AACxC,mCAAwC;AAexC,MAAa,cAAc;IAChB,QAAQ,CAAsB,CAAC,4CAA4C;IAC3E,IAAI,CAAc;IAClB,KAAK,CAAgB;IACrB,QAAQ,CAAmB;IAC3B,iBAAiB,CAA4B;IAC7C,KAAK,CAAgB;IACrB,aAAa,CAAwB;IACrC,aAAa,CAAwB;IACrC,WAAW,CAAsB;IACjC,KAAK,CAAgB;IACrB,eAAe,CAA0B;IACzC,OAAO,CAAkB;IACzB,QAAQ,CAAmB;IAC3B,KAAK,CAAgB;IAE9B,YAAY,MAA4B;QACtC,IAAI,CAAC,IAAI,GAAG,IAAA,wBAAiB,EAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,IAAA,0BAAY,EAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE;YACnD,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,CAAC,WAAW,EAAE,EAAE,EAAE;YACtE,IAAI,EAAE,E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AI,CAAC,KAAK,CAAC,CAAC;QACzF,IAAI,CAAC,OAAO,GAAG,IAAI,yBAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACzE,IAAI,CAAC,QAAQ,GAAG,IAAI,2BAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3E,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACvE,CAAC;CACF;AApCD,wCAoCC;AAEM,MAAM,oBAAoB,GAAG,CAAC,MAA4B,EAAkB,EAAE,CACnF,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AADhB,QAAA,oBAAoB,wBACJ"}
|
package/dist/clients/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ClientEntity, ClientSummary } from '@managemint-solutions/entities/clients';
|
|
2
2
|
import type { MmsList } from '@managemint-solutions/entities/common';
|
|
3
3
|
import type { AuthContext } from '../auth';
|
|
4
|
+
import { type AuditResource } from '../audit';
|
|
4
5
|
import type { TypedSupabaseClient } from '../client';
|
|
5
6
|
import type { CreateClientDto, GetClientsDto, UpdateClientDto } from './dto';
|
|
6
7
|
export * from './dto';
|
|
7
8
|
export declare class ClientsResource {
|
|
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: GetClientsDto): Promise<MmsList<ClientSummary>>;
|
|
12
14
|
getById(clientId: string): Promise<ClientEntity>;
|
|
13
15
|
create(input: CreateClientDto): Promise<ClientEntity>;
|
package/dist/clients/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.ClientsResource = 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 ClientSummary / ClientEntity from
|
|
@@ -98,9 +100,14 @@ const CLIENT_DETAIL_SELECT = `
|
|
|
98
100
|
class ClientsResource {
|
|
99
101
|
supabase;
|
|
100
102
|
auth;
|
|
101
|
-
|
|
103
|
+
table;
|
|
104
|
+
constructor(supabase, auth, audit) {
|
|
102
105
|
this.supabase = supabase;
|
|
103
106
|
this.auth = auth;
|
|
107
|
+
this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
|
|
108
|
+
table: 'clients',
|
|
109
|
+
entityType: enum_1.AuditTrailEntityType.CLIENTS,
|
|
110
|
+
});
|
|
104
111
|
}
|
|
105
112
|
async list(query) {
|
|
106
113
|
const page = query.page;
|
|
@@ -169,97 +176,53 @@ class ClientsResource {
|
|
|
169
176
|
return data;
|
|
170
177
|
}
|
|
171
178
|
async create(input) {
|
|
172
|
-
const
|
|
173
|
-
.from('clients')
|
|
174
|
-
.insert({
|
|
179
|
+
const row = await this.table.insert({
|
|
175
180
|
...input,
|
|
176
181
|
organization_id: this.auth.organization_id,
|
|
177
182
|
created_by: this.auth.mms_id,
|
|
178
183
|
created_at: new Date().toISOString(),
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
.single();
|
|
182
|
-
if (error)
|
|
183
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
184
|
-
return this.getById(data.mms_id);
|
|
184
|
+
});
|
|
185
|
+
return this.getById(row.mms_id);
|
|
185
186
|
}
|
|
186
187
|
async update(clientId, input) {
|
|
187
|
-
|
|
188
|
-
.from('clients')
|
|
189
|
-
.update({
|
|
188
|
+
await this.table.update(clientId, {
|
|
190
189
|
...input,
|
|
191
190
|
last_updated_by: this.auth.mms_id,
|
|
192
191
|
updated_at: new Date().toISOString(),
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
.eq('mms_id', clientId)
|
|
196
|
-
.select('mms_id')
|
|
197
|
-
.single();
|
|
198
|
-
if (error)
|
|
199
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
200
|
-
return this.getById(data.mms_id);
|
|
192
|
+
});
|
|
193
|
+
return this.getById(clientId);
|
|
201
194
|
}
|
|
202
195
|
async archive(clientId) {
|
|
203
|
-
|
|
204
|
-
.from('clients')
|
|
205
|
-
.update({
|
|
196
|
+
await this.table.transition(clientId, enum_1.AuditTrailAction.ARCHIVE, {
|
|
206
197
|
archived: true,
|
|
207
198
|
archived_at: new Date().toISOString(),
|
|
208
199
|
archived_by: this.auth.mms_id,
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
.eq('mms_id', clientId)
|
|
212
|
-
.select('mms_id')
|
|
213
|
-
.single();
|
|
214
|
-
if (error)
|
|
215
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
216
|
-
return this.getById(data.mms_id);
|
|
200
|
+
});
|
|
201
|
+
return this.getById(clientId);
|
|
217
202
|
}
|
|
218
203
|
async unarchive(clientId) {
|
|
219
|
-
|
|
220
|
-
.from('clients')
|
|
221
|
-
.update({
|
|
204
|
+
await this.table.transition(clientId, enum_1.AuditTrailAction.UNARCHIVE, {
|
|
222
205
|
archived: false,
|
|
223
206
|
unarchived_at: new Date().toISOString(),
|
|
224
207
|
unarchived_by: this.auth.mms_id,
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
.eq('mms_id', clientId)
|
|
228
|
-
.select('mms_id')
|
|
229
|
-
.single();
|
|
230
|
-
if (error)
|
|
231
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
232
|
-
return this.getById(data.mms_id);
|
|
208
|
+
});
|
|
209
|
+
return this.getById(clientId);
|
|
233
210
|
}
|
|
234
211
|
async restore(clientId) {
|
|
235
|
-
|
|
236
|
-
.from('clients')
|
|
237
|
-
.update({
|
|
212
|
+
await this.table.transition(clientId, enum_1.AuditTrailAction.RESTORE, {
|
|
238
213
|
deleted: false,
|
|
239
214
|
restored_at: new Date().toISOString(),
|
|
240
215
|
restored_by: this.auth.mms_id,
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
.eq('mms_id', clientId)
|
|
244
|
-
.select('mms_id')
|
|
245
|
-
.single();
|
|
246
|
-
if (error)
|
|
247
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
248
|
-
return this.getById(data.mms_id);
|
|
216
|
+
});
|
|
217
|
+
return this.getById(clientId);
|
|
249
218
|
}
|
|
250
219
|
/** Soft delete — the row stays, flagged `deleted`, and `restore()` brings it back. */
|
|
251
220
|
async remove(clientId) {
|
|
252
|
-
|
|
253
|
-
.from('clients')
|
|
254
|
-
.update({
|
|
221
|
+
await this.table.transition(clientId, enum_1.AuditTrailAction.DELETE, {
|
|
255
222
|
deleted: true,
|
|
256
223
|
deleted_at: new Date().toISOString(),
|
|
257
224
|
deleted_by: this.auth.mms_id,
|
|
258
|
-
})
|
|
259
|
-
.eq('organization_id', this.auth.organization_id)
|
|
260
|
-
.eq('mms_id', clientId);
|
|
261
|
-
if (error)
|
|
262
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
225
|
+
});
|
|
263
226
|
}
|
|
264
227
|
}
|
|
265
228
|
exports.ClientsResource = ClientsResource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,0EAGyD;AAEzD,oCAA+E;AAE/E,sCAA8C;AAG9C,wCAAsB;AAEtB,sEAA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FAAsF;IACtF,KAAK,CAAC,MAAM,CAAC,QAAgB;QAC3B,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,uBAAgB,CAAC,MAAM,EAAE;YAC7D,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;SAC7B,CAAC,CAAC;IACL,CAAC;CACF;AAvJD,0CAuJC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
export * from './client';
|
|
2
2
|
export * from './auth';
|
|
3
3
|
export * from './auth-client';
|
|
4
|
+
export * from './service-client';
|
|
4
5
|
export * from './errors';
|
|
5
6
|
export * from './validators';
|
|
6
7
|
export * from './transforms';
|
|
8
|
+
export * from './audit';
|
|
9
|
+
export * from './billing';
|
|
7
10
|
export * from './statuses';
|
|
8
11
|
export * from './additional-details';
|
|
9
12
|
export * from './notes';
|
|
13
|
+
export * from './notifications';
|
|
14
|
+
export * from './organizations';
|
|
15
|
+
export * from './permissions';
|
|
16
|
+
export * from './users';
|
|
17
|
+
export * from './webhook-events';
|
|
10
18
|
export * from './supporting-files';
|
|
11
19
|
export * from './clients';
|
|
12
20
|
export * from './projects';
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./client"), exports);
|
|
18
18
|
__exportStar(require("./auth"), exports);
|
|
19
19
|
__exportStar(require("./auth-client"), exports);
|
|
20
|
+
__exportStar(require("./service-client"), exports);
|
|
20
21
|
__exportStar(require("./errors"), exports);
|
|
21
22
|
__exportStar(require("./validators"), exports);
|
|
22
23
|
__exportStar(require("./transforms"), exports);
|
|
24
|
+
__exportStar(require("./audit"), exports);
|
|
25
|
+
__exportStar(require("./billing"), exports);
|
|
23
26
|
__exportStar(require("./statuses"), exports);
|
|
24
27
|
__exportStar(require("./additional-details"), exports);
|
|
25
28
|
__exportStar(require("./notes"), exports);
|
|
29
|
+
__exportStar(require("./notifications"), exports);
|
|
30
|
+
__exportStar(require("./organizations"), exports);
|
|
31
|
+
__exportStar(require("./permissions"), exports);
|
|
32
|
+
__exportStar(require("./users"), exports);
|
|
33
|
+
__exportStar(require("./webhook-events"), exports);
|
|
26
34
|
__exportStar(require("./supporting-files"), exports);
|
|
27
35
|
__exportStar(require("./clients"), exports);
|
|
28
36
|
__exportStar(require("./projects"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,yCAAuB;AACvB,gDAA8B;AAC9B,2CAAyB;AACzB,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,uDAAqC;AACrC,0CAAwB;AACxB,qDAAmC;AACnC,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,yCAAuB;AACvB,gDAA8B;AAC9B,mDAAiC;AACjC,2CAAyB;AACzB,+CAA6B;AAC7B,+CAA6B;AAC7B,0CAAwB;AACxB,4CAA0B;AAC1B,6CAA2B;AAC3B,uDAAqC;AACrC,0CAAwB;AACxB,kDAAgC;AAChC,kDAAgC;AAChC,gDAA8B;AAC9B,0CAAwB;AACxB,mDAAiC;AACjC,qDAAmC;AACnC,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,+CAA6B"}
|
package/dist/nest/index.d.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import { HttpException } from '@nestjs/common';
|
|
2
|
+
import type { AuditErrorHandler } from '../audit';
|
|
2
3
|
import { SupabaseClientError } from '../errors';
|
|
4
|
+
import { type SupabaseServiceClient } from '../service-client';
|
|
3
5
|
/**
|
|
4
6
|
* The HttpException Nest should send for an SDK error: same status, and the body is
|
|
5
7
|
* exactly `{ error, message }`. Register this in a global exception filter so
|
|
6
8
|
* services can let SupabaseClientError propagate untouched.
|
|
7
9
|
*/
|
|
8
10
|
export declare const toHttpException: (error: SupabaseClientError) => HttpException;
|
|
11
|
+
export type SupabaseUserClientOptions = {
|
|
12
|
+
/** Where a failed audit insert is reported — e.g. `(error) => Sentry.captureException(error)`. */
|
|
13
|
+
onAuditError?: AuditErrorHandler;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Options the `@SupabaseUserClient()` decorator builds its per-request clients with. Call it
|
|
17
|
+
* once at startup (the decorator constructs the client itself, so there is nowhere else to
|
|
18
|
+
* pass them).
|
|
19
|
+
*/
|
|
20
|
+
export declare const configureSupabaseUserClient: (options: SupabaseUserClientOptions) => void;
|
|
9
21
|
export declare const SupabaseUserClient: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
22
|
+
/**
|
|
23
|
+
* A `SupabaseServiceClient` from the ambient env — the SDK-side replacement for the api's
|
|
24
|
+
* `createSupabaseAdminClient()`.
|
|
25
|
+
*
|
|
26
|
+
* Deliberately a factory rather than a param decorator: a service client carries no per-request
|
|
27
|
+
* state, so it is built once and held in a field (`private readonly service =
|
|
28
|
+
* createSupabaseServiceClientFromEnv()`), exactly as the admin client is today. The webhook and
|
|
29
|
+
* queue-worker paths that need it have no request to decorate in the first place.
|
|
30
|
+
*/
|
|
31
|
+
export declare const createSupabaseServiceClientFromEnv: (options?: SupabaseUserClientOptions) => SupabaseServiceClient;
|
|
10
32
|
/**
|
|
11
33
|
* A `SupabaseAuthClient` for routes a logged-out caller hits (sign-in, refresh, password
|
|
12
34
|
* reset) — built from the publishable key alone, with no bearer token involved.
|
package/dist/nest/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SupabasePublicClient = exports.SupabaseUserClient = exports.toHttpException = void 0;
|
|
3
|
+
exports.SupabasePublicClient = exports.createSupabaseServiceClientFromEnv = exports.SupabaseUserClient = exports.configureSupabaseUserClient = exports.toHttpException = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const auth_client_1 = require("../auth-client");
|
|
6
6
|
const client_1 = require("../client");
|
|
7
7
|
const errors_1 = require("../errors");
|
|
8
|
+
const service_client_1 = require("../service-client");
|
|
8
9
|
/**
|
|
9
10
|
* The HttpException Nest should send for an SDK error: same status, and the body is
|
|
10
11
|
* exactly `{ error, message }`. Register this in a global exception filter so
|
|
@@ -28,6 +29,16 @@ const getBearerToken = (request) => {
|
|
|
28
29
|
}
|
|
29
30
|
return token;
|
|
30
31
|
};
|
|
32
|
+
let userClientOptions = {};
|
|
33
|
+
/**
|
|
34
|
+
* Options the `@SupabaseUserClient()` decorator builds its per-request clients with. Call it
|
|
35
|
+
* once at startup (the decorator constructs the client itself, so there is nowhere else to
|
|
36
|
+
* pass them).
|
|
37
|
+
*/
|
|
38
|
+
const configureSupabaseUserClient = (options) => {
|
|
39
|
+
userClientOptions = options;
|
|
40
|
+
};
|
|
41
|
+
exports.configureSupabaseUserClient = configureSupabaseUserClient;
|
|
31
42
|
exports.SupabaseUserClient = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
32
43
|
const token = getBearerToken(ctx.switchToHttp().getRequest());
|
|
33
44
|
try {
|
|
@@ -35,6 +46,7 @@ exports.SupabaseUserClient = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
|
35
46
|
url: getEnvOrThrow('SUPABASE_URL'),
|
|
36
47
|
key: getEnvOrThrow('SUPABASE_PUBLISHABLE_KEY'),
|
|
37
48
|
accessToken: token,
|
|
49
|
+
onAuditError: userClientOptions.onAuditError,
|
|
38
50
|
});
|
|
39
51
|
}
|
|
40
52
|
catch (error) {
|
|
@@ -45,6 +57,21 @@ exports.SupabaseUserClient = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
|
45
57
|
throw error;
|
|
46
58
|
}
|
|
47
59
|
});
|
|
60
|
+
/**
|
|
61
|
+
* A `SupabaseServiceClient` from the ambient env — the SDK-side replacement for the api's
|
|
62
|
+
* `createSupabaseAdminClient()`.
|
|
63
|
+
*
|
|
64
|
+
* Deliberately a factory rather than a param decorator: a service client carries no per-request
|
|
65
|
+
* state, so it is built once and held in a field (`private readonly service =
|
|
66
|
+
* createSupabaseServiceClientFromEnv()`), exactly as the admin client is today. The webhook and
|
|
67
|
+
* queue-worker paths that need it have no request to decorate in the first place.
|
|
68
|
+
*/
|
|
69
|
+
const createSupabaseServiceClientFromEnv = (options = {}) => (0, service_client_1.createSupabaseServiceClient)({
|
|
70
|
+
url: getEnvOrThrow('SUPABASE_URL'),
|
|
71
|
+
serviceRoleKey: getEnvOrThrow('SUPABASE_SERVICE_ROLE_KEY'),
|
|
72
|
+
onAuditError: options.onAuditError ?? userClientOptions.onAuditError,
|
|
73
|
+
});
|
|
74
|
+
exports.createSupabaseServiceClientFromEnv = createSupabaseServiceClientFromEnv;
|
|
48
75
|
/**
|
|
49
76
|
* A `SupabaseAuthClient` for routes a logged-out caller hits (sign-in, refresh, password
|
|
50
77
|
* reset) — built from the publishable key alone, with no bearer token involved.
|
package/dist/nest/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nest/index.ts"],"names":[],"mappings":";;;AAAA,2CAMwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nest/index.ts"],"names":[],"mappings":";;;AAAA,2CAMwB;AAGxB,gDAAmF;AACnF,sCAAsE;AACtE,sCAAgD;AAChD,sDAA4F;AAE5F;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAAC,KAA0B,EAAiB,EAAE,CAC3E,IAAI,sBAAa,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE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EAAE,aAAa,CAAC,cAAc,CAAC;YAClC,GAAG,EAAE,aAAa,CAAC,0BAA0B,CAAC;YAC9C,WAAW,EAAE,KAAK;YAClB,YAAY,EAAE,iBAAiB,CAAC,YAAY;SAC7C,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+EAA+E;QAC/E,qCAAqC;QACrC,IAAI,KAAK,YAAY,4BAAmB;YAAE,MAAM,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAC;QACvE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,kCAAkC,GAAG,CAChD,UAAqC,EAAE,EAChB,EAAE,CACzB,IAAA,4CAA2B,EAAC;IAC1B,GAAG,EAAE,aAAa,CAAC,cAAc,CAAC;IAClC,cAAc,EAAE,aAAa,CAAC,2BAA2B,CAAC;IAC1D,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,iBAAiB,CAAC,YAAY;CACrE,CAAC,CAAC;AAPQ,QAAA,kCAAkC,sCAO1C;AAEL;;;GAGG;AACU,QAAA,oBAAoB,GAAG,IAAA,6BAAoB,EACtD,GAAuB,EAAE,CACvB,IAAA,sCAAwB,EAAC;IACvB,GAAG,EAAE,aAAa,CAAC,cAAc,CAAC;IAClC,GAAG,EAAE,aAAa,CAAC,0BAA0B,CAAC;CAC/C,CAAC,CACL,CAAC"}
|
package/dist/notes/index.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import type { NoteEntity } from '@managemint-solutions/entities/notes';
|
|
|
2
2
|
import type { AddNoteDto } from '@managemint-solutions/entities/notes/dto';
|
|
3
3
|
import { NotesEntityTypes } from '@managemint-solutions/entities/notes/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 NotesResource {
|
|
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
|
getById(noteId: string): Promise<NoteEntity>;
|
|
12
14
|
list(entity: NotesEntityTypes, entityId: string): Promise<NoteEntity[]>;
|
|
13
15
|
create(entity: NotesEntityTypes, entityId: string, input: AddNoteDto): Promise<NoteEntity>;
|
package/dist/notes/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.NotesResource = 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 NoteEntity from @managemint-solutions/entities; the casts at
|
|
@@ -24,9 +26,14 @@ const NOTE_SELECT = 'mms_id, created_at, content, pinned, user:user_profiles!use
|
|
|
24
26
|
class NotesResource {
|
|
25
27
|
supabase;
|
|
26
28
|
auth;
|
|
27
|
-
|
|
29
|
+
table;
|
|
30
|
+
constructor(supabase, auth, audit) {
|
|
28
31
|
this.supabase = supabase;
|
|
29
32
|
this.auth = auth;
|
|
33
|
+
this.table = (0, audit_1.auditedTable)(supabase, auth, audit, {
|
|
34
|
+
table: 'notes',
|
|
35
|
+
entityType: enum_1.AuditTrailEntityType.NOTES,
|
|
36
|
+
});
|
|
30
37
|
}
|
|
31
38
|
async getById(noteId) {
|
|
32
39
|
const { data, error } = await this.supabase
|
|
@@ -52,44 +59,26 @@ class NotesResource {
|
|
|
52
59
|
return data;
|
|
53
60
|
}
|
|
54
61
|
async create(entity, entityId, input) {
|
|
55
|
-
const
|
|
56
|
-
.from('notes')
|
|
57
|
-
.insert({
|
|
62
|
+
const row = await this.table.insert({
|
|
58
63
|
content: input.content,
|
|
59
64
|
entity_type: entity,
|
|
60
65
|
entity_id: entityId,
|
|
61
66
|
organization_id: this.auth.organization_id,
|
|
62
67
|
user_id: this.auth.mms_id,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
.single();
|
|
66
|
-
if (error)
|
|
67
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
68
|
-
return data;
|
|
68
|
+
});
|
|
69
|
+
return this.getById(row.mms_id);
|
|
69
70
|
}
|
|
70
71
|
async togglePin(noteId) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.
|
|
74
|
-
.update({
|
|
75
|
-
pinned: !existing.pinned,
|
|
72
|
+
// The helper pre-reads the row anyway, so the flip is a function of what it read.
|
|
73
|
+
await this.table.update(noteId, (before) => ({
|
|
74
|
+
pinned: !before.pinned,
|
|
76
75
|
updated_at: new Date().toISOString(),
|
|
77
76
|
last_updated_by: this.auth.mms_id,
|
|
78
|
-
})
|
|
79
|
-
.eq('mms_id', noteId)
|
|
80
|
-
.eq('organization_id', this.auth.organization_id);
|
|
81
|
-
if (error)
|
|
82
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
77
|
+
}));
|
|
83
78
|
return this.getById(noteId);
|
|
84
79
|
}
|
|
85
80
|
async remove(noteId) {
|
|
86
|
-
|
|
87
|
-
.from('notes')
|
|
88
|
-
.delete()
|
|
89
|
-
.eq('mms_id', noteId)
|
|
90
|
-
.eq('organization_id', this.auth.organization_id);
|
|
91
|
-
if (error)
|
|
92
|
-
throw (0, errors_1.mapPostgrestError)(error);
|
|
81
|
+
await this.table.remove(noteId);
|
|
93
82
|
}
|
|
94
83
|
}
|
|
95
84
|
exports.NotesResource = NotesResource;
|
package/dist/notes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"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ationsDto as GetNotificationsDtoType, NotificationIdDto as NotificationIdDtoType } from '@managemint-solutions/entities/notifications/dto';
|
|
2
|
+
export declare class NotificationIdDto implements NotificationIdDtoType {
|
|
3
|
+
readonly notificationId: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class GetNotificationsDto implements GetNotificationsDtoType {
|
|
6
|
+
readonly search?: string | null;
|
|
7
|
+
readonly page: number;
|
|
8
|
+
readonly page_size: number;
|
|
9
|
+
readonly unread?: boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GetNotificationsDto = exports.NotificationIdDto = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
const class_transformer_1 = require("class-transformer");
|
|
15
|
+
const validators_1 = require("../validators");
|
|
16
|
+
// class-validator versions of the shared DTO types from @managemint-solutions/entities.
|
|
17
|
+
// Each class `implements` its entities type so the wire contract cannot drift.
|
|
18
|
+
class NotificationIdDto {
|
|
19
|
+
notificationId;
|
|
20
|
+
}
|
|
21
|
+
exports.NotificationIdDto = NotificationIdDto;
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsUUID)('4', { message: 'Invalid notification ID format' }),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], NotificationIdDto.prototype, "notificationId", void 0);
|
|
26
|
+
class GetNotificationsDto {
|
|
27
|
+
search;
|
|
28
|
+
page = 1;
|
|
29
|
+
page_size = 10;
|
|
30
|
+
unread;
|
|
31
|
+
}
|
|
32
|
+
exports.GetNotificationsDto = GetNotificationsDto;
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, class_validator_1.IsOptional)(),
|
|
35
|
+
(0, validators_1.IsNullable)(),
|
|
36
|
+
(0, class_validator_1.IsString)({ message: 'Search query must be a string' }),
|
|
37
|
+
(0, class_validator_1.MinLength)(1, { message: 'Search query cannot be empty' }),
|
|
38
|
+
(0, class_validator_1.MaxLength)(255, { message: 'Search query cannot exceed 255 characters' }),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], GetNotificationsDto.prototype, "search", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, class_validator_1.IsOptional)(),
|
|
43
|
+
(0, class_transformer_1.Transform)(({ value }) => (value ? Number(value) : 1), { toClassOnly: true }),
|
|
44
|
+
(0, class_validator_1.IsNumber)({}, { message: 'Page must be a number' }),
|
|
45
|
+
(0, class_validator_1.Min)(1, { message: 'Page must be at least 1' }),
|
|
46
|
+
__metadata("design:type", Number)
|
|
47
|
+
], GetNotificationsDto.prototype, "page", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, class_validator_1.IsOptional)(),
|
|
50
|
+
(0, class_transformer_1.Transform)(({ value }) => (value ? Number(value) : 10), { toClassOnly: true }),
|
|
51
|
+
(0, class_validator_1.IsNumber)({}, { message: 'Page size must be a number' }),
|
|
52
|
+
(0, class_validator_1.Min)(1, { message: 'Page size must be at least 1' }),
|
|
53
|
+
(0, class_validator_1.Max)(100, { message: 'Page size cannot exceed 100' }),
|
|
54
|
+
__metadata("design:type", Number)
|
|
55
|
+
], GetNotificationsDto.prototype, "page_size", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, class_validator_1.IsOptional)(),
|
|
58
|
+
(0, validators_1.IsNullable)(),
|
|
59
|
+
(0, class_transformer_1.Transform)(({ value }) => (value ? value === 'true' : false), { toClassOnly: true }),
|
|
60
|
+
(0, class_validator_1.IsBoolean)({ message: 'Unread only must be a boolean' }),
|
|
61
|
+
__metadata("design:type", Boolean)
|
|
62
|
+
], GetNotificationsDto.prototype, "unread", void 0);
|
|
63
|
+
//# sourceMappingURL=dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto.js","sourceRoot":"","sources":["../../src/notifications/dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAoH;AACpH,yDAA8C;AAK9C,8CAA2C;AAE3C,wFAAwF;AACxF,+EAA+E;AAE/E,MAAa,iBAAiB;IAEnB,cAAc,CAAU;CAClC;AAHD,8CAGC;AADU;IADR,IAAA,wBAAM,EAAC,GAAG,EAAE,EAAE,OAAO,EAAE,gCAAgC,EAAE,CAAC;;yDAC1B;AAGnC,MAAa,mBAAmB;IAMrB,MAAM,CAAiB;IAMvB,IAAI,GAAW,CAAC,CAAC;IAOjB,SAAS,GAAW,EAAE,CAAC;IAMvB,MAAM,CAAW;CAC3B;AA1BD,kDA0BC;AApBU;IALR,IAAA,4BAAU,GAAE;IACZ,IAAA,uBAAU,GAAE;IACZ,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,+BAA+B,EAAE,CAAC;IACtD,IAAA,2BAAS,EAAC,CAAC,EAAE,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC;IACzD,IAAA,2BAAS,EAAC,GAAG,EAAE,EAAE,OAAO,EAAE,2CAA2C,EAAE,CAAC;;mDACzC;AAMvB;IAJR,IAAA,4BAAU,GAAE;IACZ,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,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