@things-factory/notification 10.1.258 → 10.1.259
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/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/controllers/notice/index.d.ts +1 -0
- package/dist-server/controllers/notice/index.js +1 -0
- package/dist-server/controllers/notice/index.js.map +1 -1
- package/dist-server/controllers/notice/notice-delivery-record.d.ts +26 -0
- package/dist-server/controllers/notice/notice-delivery-record.js +44 -0
- package/dist-server/controllers/notice/notice-delivery-record.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/tests/notice-delivery-record.test.ts +19 -0
|
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./notice-channels.js"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./deliver-notice.js"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./send-notice.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./notice-delivery-record.js"), exports);
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/notice/index.ts"],"names":[],"mappings":";;;AAAA,+DAAoC;AACpC,8DAAmC;AACnC,2DAAgC","sourcesContent":["export * from './notice-channels.js'\nexport * from './deliver-notice.js'\nexport * from './send-notice.js'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/notice/index.ts"],"names":[],"mappings":";;;AAAA,+DAAoC;AACpC,8DAAmC;AACnC,2DAAgC;AAChC,sEAA2C","sourcesContent":["export * from './notice-channels.js'\nexport * from './deliver-notice.js'\nexport * from './send-notice.js'\nexport * from './notice-delivery-record.js'\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { NoticeResult } from './deliver-notice.js';
|
|
2
|
+
/** One telling - when, why, and what went out. `failed` says nothing could go at all. */
|
|
3
|
+
export type NoticeDelivery = {
|
|
4
|
+
at: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
receivers: number;
|
|
7
|
+
email: {
|
|
8
|
+
sent: number;
|
|
9
|
+
failed: number;
|
|
10
|
+
};
|
|
11
|
+
teams: {
|
|
12
|
+
sent: number;
|
|
13
|
+
failed: number;
|
|
14
|
+
};
|
|
15
|
+
failed?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** A send that could not go at all counts its receivers, nothing sent. */
|
|
18
|
+
export declare function noticeDeliveryOf(kind: string, result: NoticeResult | undefined, receivers: number, at?: Date): NoticeDelivery;
|
|
19
|
+
/** The record keeps the newest tellings, at most `MAX_NOTICE_DELIVERIES`. */
|
|
20
|
+
export declare const MAX_NOTICE_DELIVERIES = 50;
|
|
21
|
+
export declare function withNoticeDelivery<T>(deliveries: T[] | null | undefined, one: T): T[];
|
|
22
|
+
/**
|
|
23
|
+
* Adds one telling to `column` of row `id` - in its own transaction, the request's being over. A record that cannot be
|
|
24
|
+
* kept is reported; what was told of stands.
|
|
25
|
+
*/
|
|
26
|
+
export declare function keepNoticeDelivery(entity: any, id: string, column: string, delivery: NoticeDelivery): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_NOTICE_DELIVERIES = void 0;
|
|
4
|
+
exports.noticeDeliveryOf = noticeDeliveryOf;
|
|
5
|
+
exports.withNoticeDelivery = withNoticeDelivery;
|
|
6
|
+
exports.keepNoticeDelivery = keepNoticeDelivery;
|
|
7
|
+
/*
|
|
8
|
+
* What one telling sent, kept on the thing it told of (ADR-0164) - an announcement, an approval. Mail goes out after the
|
|
9
|
+
* request is over, so whether it went is known only from this record: the screens and an operator read it.
|
|
10
|
+
*/
|
|
11
|
+
const env_1 = require("@things-factory/env");
|
|
12
|
+
const shell_1 = require("@things-factory/shell");
|
|
13
|
+
/** A send that could not go at all counts its receivers, nothing sent. */
|
|
14
|
+
function noticeDeliveryOf(kind, result, receivers, at = new Date()) {
|
|
15
|
+
return {
|
|
16
|
+
at: at.toISOString(),
|
|
17
|
+
kind,
|
|
18
|
+
receivers: result?.receivers ?? receivers,
|
|
19
|
+
email: result?.email ?? { sent: 0, failed: 0 },
|
|
20
|
+
teams: result?.teams ?? { sent: 0, failed: 0 },
|
|
21
|
+
...(result ? {} : { failed: true })
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** The record keeps the newest tellings, at most `MAX_NOTICE_DELIVERIES`. */
|
|
25
|
+
exports.MAX_NOTICE_DELIVERIES = 50;
|
|
26
|
+
function withNoticeDelivery(deliveries, one) {
|
|
27
|
+
return [...(deliveries ?? []), one].slice(-exports.MAX_NOTICE_DELIVERIES);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Adds one telling to `column` of row `id` - in its own transaction, the request's being over. A record that cannot be
|
|
31
|
+
* kept is reported; what was told of stands.
|
|
32
|
+
*/
|
|
33
|
+
async function keepNoticeDelivery(entity, id, column, delivery) {
|
|
34
|
+
try {
|
|
35
|
+
const repository = (0, shell_1.getRepository)(entity);
|
|
36
|
+
const one = await repository.findOneBy({ id });
|
|
37
|
+
if (one)
|
|
38
|
+
await repository.update(id, { [column]: withNoticeDelivery(one[column], delivery) });
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
env_1.logger.error(`[notification] ${entity?.name ?? 'row'} ${id}: what was sent could not be kept`, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=notice-delivery-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notice-delivery-record.js","sourceRoot":"","sources":["../../../server/controllers/notice/notice-delivery-record.ts"],"names":[],"mappings":";;;AAoBA,4CASC;AAID,gDAEC;AAMD,gDAQC;AAjDD;;;GAGG;AACH,6CAA4C;AAC5C,iDAAqD;AAcrD,0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;QACf,YAAM,CAAC,KAAK,CAAC,kBAAkB,MAAM,EAAE,IAAI,IAAI,KAAK,IAAI,EAAE,mCAAmC,EAAE,KAAK,CAAC,CAAA;IACvG,CAAC;AACH,CAAC","sourcesContent":["/*\n * What one telling sent, kept on the thing it told of (ADR-0164) - an announcement, an approval. Mail goes out after the\n * request is over, so whether it went is known only from this record: the screens and an operator read it.\n */\nimport { logger } from '@things-factory/env'\nimport { getRepository } from '@things-factory/shell'\n\nimport type { NoticeResult } from './deliver-notice.js'\n\n/** One telling - when, why, and what went out. `failed` says nothing could go at all. */\nexport type NoticeDelivery = {\n at: string\n kind: string\n receivers: number\n email: { sent: number; failed: number }\n teams: { sent: number; failed: number }\n failed?: boolean\n}\n\n/** A send that could not go at all counts its receivers, nothing sent. */\nexport function noticeDeliveryOf(kind: string, result: NoticeResult | undefined, receivers: number, at = new Date()): NoticeDelivery {\n return {\n at: at.toISOString(),\n kind,\n receivers: result?.receivers ?? receivers,\n email: result?.email ?? { sent: 0, failed: 0 },\n teams: result?.teams ?? { sent: 0, failed: 0 },\n ...(result ? {} : { failed: true })\n }\n}\n\n/** The record keeps the newest tellings, at most `MAX_NOTICE_DELIVERIES`. */\nexport const MAX_NOTICE_DELIVERIES = 50\nexport function withNoticeDelivery<T>(deliveries: T[] | null | undefined, one: T): T[] {\n return [...(deliveries ?? []), one].slice(-MAX_NOTICE_DELIVERIES)\n}\n\n/**\n * Adds one telling to `column` of row `id` - in its own transaction, the request's being over. A record that cannot be\n * kept is reported; what was told of stands.\n */\nexport async function keepNoticeDelivery(entity: any, id: string, column: string, delivery: NoticeDelivery): Promise<void> {\n try {\n const repository = getRepository(entity)\n const one: any = await repository.findOneBy({ id } as any)\n if (one) await repository.update(id, { [column]: withNoticeDelivery(one[column], delivery) } as any)\n } catch (error) {\n logger.error(`[notification] ${entity?.name ?? 'row'} ${id}: what was sent could not be kept`, error)\n }\n}\n"]}
|