@managemint-solutions/sdk 0.7.0 → 0.9.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 +94 -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 +89 -0
- package/dist/audit/index.js +285 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/auth-client/index.d.ts +4 -1
- package/dist/auth-client/index.js +5 -1
- package/dist/auth-client/index.js.map +1 -1
- package/dist/client.d.ts +4 -0
- package/dist/client.js +11 -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 +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/nest/index.d.ts +11 -0
- package/dist/nest/index.js +12 -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/pricebooks/index.d.ts +19 -0
- package/dist/pricebooks/index.js +88 -0
- package/dist/pricebooks/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/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/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './auth-client';
|
|
|
4
4
|
export * from './errors';
|
|
5
5
|
export * from './validators';
|
|
6
6
|
export * from './transforms';
|
|
7
|
+
export * from './audit';
|
|
7
8
|
export * from './statuses';
|
|
8
9
|
export * from './additional-details';
|
|
9
10
|
export * from './notes';
|
|
@@ -11,3 +12,4 @@ export * from './supporting-files';
|
|
|
11
12
|
export * from './clients';
|
|
12
13
|
export * from './projects';
|
|
13
14
|
export * from './tasks';
|
|
15
|
+
export * from './pricebooks';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./auth-client"), exports);
|
|
|
20
20
|
__exportStar(require("./errors"), exports);
|
|
21
21
|
__exportStar(require("./validators"), exports);
|
|
22
22
|
__exportStar(require("./transforms"), exports);
|
|
23
|
+
__exportStar(require("./audit"), exports);
|
|
23
24
|
__exportStar(require("./statuses"), exports);
|
|
24
25
|
__exportStar(require("./additional-details"), exports);
|
|
25
26
|
__exportStar(require("./notes"), exports);
|
|
@@ -27,4 +28,5 @@ __exportStar(require("./supporting-files"), exports);
|
|
|
27
28
|
__exportStar(require("./clients"), exports);
|
|
28
29
|
__exportStar(require("./projects"), exports);
|
|
29
30
|
__exportStar(require("./tasks"), exports);
|
|
31
|
+
__exportStar(require("./pricebooks"), exports);
|
|
30
32
|
//# sourceMappingURL=index.js.map
|
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"}
|
|
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,0CAAwB;AACxB,6CAA2B;AAC3B,uDAAqC;AACrC,0CAAwB;AACxB,qDAAmC;AACnC,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,+CAA6B"}
|
package/dist/nest/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HttpException } from '@nestjs/common';
|
|
2
|
+
import type { AuditErrorHandler } from '../audit';
|
|
2
3
|
import { SupabaseClientError } from '../errors';
|
|
3
4
|
/**
|
|
4
5
|
* The HttpException Nest should send for an SDK error: same status, and the body is
|
|
@@ -6,6 +7,16 @@ import { SupabaseClientError } from '../errors';
|
|
|
6
7
|
* services can let SupabaseClientError propagate untouched.
|
|
7
8
|
*/
|
|
8
9
|
export declare const toHttpException: (error: SupabaseClientError) => HttpException;
|
|
10
|
+
export type SupabaseUserClientOptions = {
|
|
11
|
+
/** Where a failed audit insert is reported — e.g. `(error) => Sentry.captureException(error)`. */
|
|
12
|
+
onAuditError?: AuditErrorHandler;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Options the `@SupabaseUserClient()` decorator builds its per-request clients with. Call it
|
|
16
|
+
* once at startup (the decorator constructs the client itself, so there is nowhere else to
|
|
17
|
+
* pass them).
|
|
18
|
+
*/
|
|
19
|
+
export declare const configureSupabaseUserClient: (options: SupabaseUserClientOptions) => void;
|
|
9
20
|
export declare const SupabaseUserClient: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
10
21
|
/**
|
|
11
22
|
* A `SupabaseAuthClient` for routes a logged-out caller hits (sign-in, refresh, password
|
package/dist/nest/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.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");
|
|
@@ -28,6 +28,16 @@ const getBearerToken = (request) => {
|
|
|
28
28
|
}
|
|
29
29
|
return token;
|
|
30
30
|
};
|
|
31
|
+
let userClientOptions = {};
|
|
32
|
+
/**
|
|
33
|
+
* Options the `@SupabaseUserClient()` decorator builds its per-request clients with. Call it
|
|
34
|
+
* once at startup (the decorator constructs the client itself, so there is nowhere else to
|
|
35
|
+
* pass them).
|
|
36
|
+
*/
|
|
37
|
+
const configureSupabaseUserClient = (options) => {
|
|
38
|
+
userClientOptions = options;
|
|
39
|
+
};
|
|
40
|
+
exports.configureSupabaseUserClient = configureSupabaseUserClient;
|
|
31
41
|
exports.SupabaseUserClient = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
32
42
|
const token = getBearerToken(ctx.switchToHttp().getRequest());
|
|
33
43
|
try {
|
|
@@ -35,6 +45,7 @@ exports.SupabaseUserClient = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
|
35
45
|
url: getEnvOrThrow('SUPABASE_URL'),
|
|
36
46
|
key: getEnvOrThrow('SUPABASE_PUBLISHABLE_KEY'),
|
|
37
47
|
accessToken: token,
|
|
48
|
+
onAuditError: userClientOptions.onAuditError,
|
|
38
49
|
});
|
|
39
50
|
}
|
|
40
51
|
catch (error) {
|
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;AAEhD;;;;GAIG;AACI,MAAM,eAAe,GAA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AAU,EAAW,CAAC,CAAC;IACvE,IAAI,CAAC;QACH,OAAO,IAAA,6BAAoB,EAAC;YAC1B,GAAG,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;;;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,"file":"index.js","sourceRoot":"","sources":["../../src/notes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,0EAAuF;AAEvF,oCAA+E;AAE/E,sCAA8C;AAE9C,wCAAsB;AAEtB,iGAAiG;AACjG,iGAAiG;AACjG,8BAA8B;AAC9B,MAAM,WAAW,GAAG,oEAA6E,CAAC;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1C,OAAO,IAA+B,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,MAAM,CACV,MAAwB,EACxB,QAAgB,EAChB,KAAiB;QAEjB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAClC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,WAAW,EAAE,MAAM;YACnB,SAAS,EAAE,QAAQ;YACnB,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe;YAC1C,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;SAC1B,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAc;QAC5B,kFAAkF;QAClF,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAC3C,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM;YACtB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;SAClC,CAAC,CAAC,CAAC;QAEJ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF;AAnED,sCAmEC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SupabaseClient as SupabaseJsClient } from '@supabase/supabase-js';
|
|
2
|
+
import type { PricebookWithModules } from '@managemint-solutions/entities/modules';
|
|
3
|
+
/**
|
|
4
|
+
* The public price catalog. `pricebooks`, `pricebook_modules` and `billing_modules` are readable
|
|
5
|
+
* by `anon` by design — unauthenticated signup prices against them — so this resource takes no
|
|
6
|
+
* auth context and scopes by nothing.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PricebooksResource {
|
|
9
|
+
private readonly supabase;
|
|
10
|
+
constructor(supabase: SupabaseJsClient);
|
|
11
|
+
getActive(): Promise<PricebookWithModules>;
|
|
12
|
+
getById(pricebookId: string): Promise<PricebookWithModules>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What the given modules cost per month, in minor units: every module's unit price summed and
|
|
16
|
+
* multiplied by the seat count. A module the pricebook does not price is a 400 — the caller
|
|
17
|
+
* asked for something that cannot be billed.
|
|
18
|
+
*/
|
|
19
|
+
export declare const monthlyTotalMinor: (pricebook: PricebookWithModules, moduleKeys: string[], seatCount: number) => number;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monthlyTotalMinor = exports.PricebooksResource = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
// The public contract is PricebookWithModules from @managemint-solutions/entities; the row
|
|
6
|
+
// types below only declare the shape this select string produces (the columns are defined in
|
|
7
|
+
// the api's supabase/migrations).
|
|
8
|
+
const PRICEBOOK_SELECT = `
|
|
9
|
+
mms_id,
|
|
10
|
+
name,
|
|
11
|
+
description,
|
|
12
|
+
active,
|
|
13
|
+
pricebook_modules (
|
|
14
|
+
module_id,
|
|
15
|
+
unit_amount_minor,
|
|
16
|
+
currency,
|
|
17
|
+
billing_modules (
|
|
18
|
+
module_key
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
`;
|
|
22
|
+
// A pricebook_modules row whose catalog entry did not come back leaves `module_key` undefined —
|
|
23
|
+
// the cast keeps the mapping honest about that rather than inventing a key.
|
|
24
|
+
const toPricebookWithModules = (row) => ({
|
|
25
|
+
mms_id: row.mms_id,
|
|
26
|
+
name: row.name,
|
|
27
|
+
active: row.active,
|
|
28
|
+
description: row.description,
|
|
29
|
+
modules: (row.pricebook_modules || []).map((pricedModule) => ({
|
|
30
|
+
module_id: pricedModule.module_id,
|
|
31
|
+
module_key: pricedModule.billing_modules?.module_key,
|
|
32
|
+
unit_amount_minor: pricedModule.unit_amount_minor,
|
|
33
|
+
currency: pricedModule.currency,
|
|
34
|
+
})),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* The public price catalog. `pricebooks`, `pricebook_modules` and `billing_modules` are readable
|
|
38
|
+
* by `anon` by design — unauthenticated signup prices against them — so this resource takes no
|
|
39
|
+
* auth context and scopes by nothing.
|
|
40
|
+
*/
|
|
41
|
+
class PricebooksResource {
|
|
42
|
+
supabase;
|
|
43
|
+
constructor(supabase) {
|
|
44
|
+
this.supabase = supabase;
|
|
45
|
+
}
|
|
46
|
+
async getActive() {
|
|
47
|
+
const { data, error } = await this.supabase
|
|
48
|
+
.from('pricebooks')
|
|
49
|
+
.select(PRICEBOOK_SELECT)
|
|
50
|
+
.eq('active', true)
|
|
51
|
+
.single();
|
|
52
|
+
if (error)
|
|
53
|
+
throw (0, errors_1.mapPostgrestError)(error);
|
|
54
|
+
return toPricebookWithModules(data);
|
|
55
|
+
}
|
|
56
|
+
async getById(pricebookId) {
|
|
57
|
+
const { data, error } = await this.supabase
|
|
58
|
+
.from('pricebooks')
|
|
59
|
+
.select(PRICEBOOK_SELECT)
|
|
60
|
+
.eq('mms_id', pricebookId)
|
|
61
|
+
.single();
|
|
62
|
+
if (error)
|
|
63
|
+
throw (0, errors_1.mapPostgrestError)(error);
|
|
64
|
+
return toPricebookWithModules(data);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.PricebooksResource = PricebooksResource;
|
|
68
|
+
/**
|
|
69
|
+
* What the given modules cost per month, in minor units: every module's unit price summed and
|
|
70
|
+
* multiplied by the seat count. A module the pricebook does not price is a 400 — the caller
|
|
71
|
+
* asked for something that cannot be billed.
|
|
72
|
+
*/
|
|
73
|
+
const monthlyTotalMinor = (pricebook, moduleKeys, seatCount) => {
|
|
74
|
+
const total = moduleKeys.reduce((sum, moduleKey) => {
|
|
75
|
+
const pricedModule = pricebook.modules.find((module) => module.module_key === moduleKey);
|
|
76
|
+
if (!pricedModule) {
|
|
77
|
+
throw new errors_1.SupabaseClientError({
|
|
78
|
+
status: 400,
|
|
79
|
+
error: 'Pricing Error',
|
|
80
|
+
message: `Module ${moduleKey} is not priced by pricebook ${pricebook.name}`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return sum + pricedModule.unit_amount_minor;
|
|
84
|
+
}, 0);
|
|
85
|
+
return total * seatCount;
|
|
86
|
+
};
|
|
87
|
+
exports.monthlyTotalMinor = monthlyTotalMinor;
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pricebooks/index.ts"],"names":[],"mappings":";;;AAEA,sCAAmE;AAEnE,2FAA2F;AAC3F,6FAA6F;AAC7F,kCAAkC;AAClC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;CAaf,CAAC;AAoBX,gGAAgG;AAChG,4EAA4E;AAC5E,MAAM,sBAAsB,GAAG,CAAC,GAAiB,EAAwB,EAAE,CAAC,CAAC;IAC3E,MAAM,EAAE,GAAG,CAAC,MAAM;IAClB,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,MAAM,EAAE,GAAG,CAAC,MAAM;IAClB,WAAW,EAAE,GAAG,CAAC,WAAW;IAC5B,OAAO,EAAE,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC5D,SAAS,EAAE,YAAY,CAAC,SAAS;QACjC,UAAU,EAAE,YAAY,CAAC,eAAe,EAAE,UAAU;QACpD,iBAAiB,EAAE,YAAY,CAAC,iBAAiB;QACjD,QAAQ,EAAE,YAAY,CAAC,QAAQ;KAChC,CAAC,CAAmB;CACtB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAa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BACX,KAAK,EAAE,eAAe;gBACtB,OAAO,EAAE,UAAU,SAAS,+BAA+B,SAAS,CAAC,IAAI,EAAE;aAC5E,CAAC,CAAC;QACL,CAAC;QAED,OAAO,GAAG,GAAG,YAAY,CAAC,iBAAiB,CAAC;IAC9C,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,OAAO,KAAK,GAAG,SAAS,CAAC;AAC3B,CAAC,CAAC;AApBW,QAAA,iBAAiB,qBAoB5B"}
|
package/dist/projects/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { MmsList } from '@managemint-solutions/entities/common';
|
|
2
2
|
import type { ProjectEntity, ProjectSummary } from '@managemint-solutions/entities/projects';
|
|
3
3
|
import type { AuthContext } from '../auth';
|
|
4
|
+
import { type AuditResource } from '../audit';
|
|
4
5
|
import type { TypedSupabaseClient } from '../client';
|
|
5
6
|
import type { CreateProjectDto, GetProjectsDto, UpdateProjectDto } from './dto';
|
|
6
7
|
export * from './dto';
|
|
7
8
|
export declare class ProjectsResource {
|
|
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: GetProjectsDto): Promise<MmsList<ProjectSummary>>;
|
|
12
14
|
getById(projectId: string): Promise<ProjectEntity>;
|
|
13
15
|
create(input: CreateProjectDto): Promise<ProjectEntity>;
|
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;;;;;;;;;;;;;;OAc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AI;YACb,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;SAC7B,CAAC,CAAC;IACL,CAAC;CACF;AAvLD,4CAuLC"}
|
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,I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