@things-factory/announcement 10.1.257 → 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/service/announcement/announcement-rules.d.ts +0 -29
- package/dist-server/service/announcement/announcement-rules.js +1 -19
- package/dist-server/service/announcement/announcement-rules.js.map +1 -1
- package/dist-server/service/announcement/announcement-service.js +2 -14
- package/dist-server/service/announcement/announcement-service.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/server/service/announcement/announcement-rules.ts +0 -20
- package/server/service/announcement/announcement-service.ts +4 -15
- package/test/announcement-persistence.test.ts +3 -1
- package/test/announcement-rules.test.ts +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/announcement",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.259",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"@operato/shell": "^10.29.69",
|
|
37
37
|
"@operato/styles": "^10.29.1",
|
|
38
38
|
"@operato/utils": "^10.0.0",
|
|
39
|
-
"@things-factory/ai-assistant": "^10.1.
|
|
40
|
-
"@things-factory/attachment-base": "^10.1.
|
|
41
|
-
"@things-factory/auth-base": "^10.1.
|
|
39
|
+
"@things-factory/ai-assistant": "^10.1.259",
|
|
40
|
+
"@things-factory/attachment-base": "^10.1.259",
|
|
41
|
+
"@things-factory/auth-base": "^10.1.259",
|
|
42
42
|
"@things-factory/env": "^10.1.149",
|
|
43
|
-
"@things-factory/i18n-base": "^10.1.
|
|
44
|
-
"@things-factory/notification": "^10.1.
|
|
45
|
-
"@things-factory/organization": "^10.1.
|
|
46
|
-
"@things-factory/shell": "^10.1.
|
|
43
|
+
"@things-factory/i18n-base": "^10.1.259",
|
|
44
|
+
"@things-factory/notification": "^10.1.259",
|
|
45
|
+
"@things-factory/organization": "^10.1.259",
|
|
46
|
+
"@things-factory/shell": "^10.1.259",
|
|
47
47
|
"graphql-scalars": "^1.22.0",
|
|
48
48
|
"graphql-tag": "^2.12.6",
|
|
49
49
|
"graphql-upload": "^15.0.2",
|
|
50
50
|
"lit": "^3.1.2"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "e7283779ee700b4b124226f0ad22d7c1e4063ae7"
|
|
53
53
|
}
|
|
@@ -217,23 +217,3 @@ export function noticeWordsOf(one: { title: string; body?: string | null }, kind
|
|
|
217
217
|
note: say('announcement.notice.note', 'Open Announcements in the application to read it.')
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
|
|
221
|
-
export type NoticeCount = { receivers: number; email: { sent: number; failed: number }; teams: { sent: number; failed: number } }
|
|
222
|
-
|
|
223
|
-
/** One telling as the announcement keeps it - when, why, and what went out. A send that could not go at all counts its receivers, nothing sent. */
|
|
224
|
-
export function deliveryOf(kind: NoticeKind, result: NoticeCount | undefined, receivers: number, at = new Date()) {
|
|
225
|
-
return {
|
|
226
|
-
at: at.toISOString(),
|
|
227
|
-
kind,
|
|
228
|
-
receivers: result?.receivers ?? receivers,
|
|
229
|
-
email: result?.email ?? { sent: 0, failed: 0 },
|
|
230
|
-
teams: result?.teams ?? { sent: 0, failed: 0 },
|
|
231
|
-
...(result ? {} : { failed: true })
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** The record kept on an announcement - the newest tellings, at most `MAX_DELIVERIES`. */
|
|
236
|
-
export const MAX_DELIVERIES = 50
|
|
237
|
-
export function withDelivery<T>(deliveries: T[] | null | undefined, one: T): T[] {
|
|
238
|
-
return [...(deliveries ?? []), one].slice(-MAX_DELIVERIES)
|
|
239
|
-
}
|
|
@@ -7,12 +7,12 @@ import { EntityManager, In, IsNull, LessThanOrEqual } from 'typeorm'
|
|
|
7
7
|
import { checkPermission, User, UserStatus } from '@things-factory/auth-base'
|
|
8
8
|
import { logger } from '@things-factory/env'
|
|
9
9
|
import { translatorFor } from '@things-factory/i18n-base/translator'
|
|
10
|
-
import { noticeLinkOf, sendNotice, sendNoticeWhenCommitted, type Notice
|
|
10
|
+
import { keepNoticeDelivery, noticeDeliveryOf, noticeLinkOf, sendNotice, sendNoticeWhenCommitted, type Notice } from '@things-factory/notification'
|
|
11
11
|
import { audienceMemberOf, audienceUserIds, type AudienceMember } from '@things-factory/organization'
|
|
12
12
|
import { Domain, getDataSource, getRepository } from '@things-factory/shell'
|
|
13
13
|
|
|
14
14
|
import { Announcement, AnnouncementAudience, AnnouncementReceipt, AnnouncementRevision, AnnouncementStatus } from './announcement'
|
|
15
|
-
import { broadcastOf,
|
|
15
|
+
import { broadcastOf, noticeWordsOf, viewAddressOf, type NoticeKind, type Say } from './announcement-rules'
|
|
16
16
|
|
|
17
17
|
/** The attachments of an announcement hang on it under this `refType` (attachment-base). */
|
|
18
18
|
export const ANNOUNCEMENT_REF_TYPE = 'Announcement'
|
|
@@ -173,17 +173,6 @@ function noticeOf(one: Announcement, kind: NoticeKind, receivers: Notice['receiv
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
/** Keeps what one telling sent on the announcement - in its own transaction, the request's being over. */
|
|
177
|
-
async function recordDelivery(id: string, kind: NoticeKind, result: NoticeResult | undefined, receivers: number): Promise<void> {
|
|
178
|
-
try {
|
|
179
|
-
const repository = getRepository(Announcement)
|
|
180
|
-
const one = await repository.findOneBy({ id })
|
|
181
|
-
if (one) await repository.update(id, { deliveries: withDelivery(one.deliveries, deliveryOf(kind, result, receivers)) } as any)
|
|
182
|
-
} catch (error) {
|
|
183
|
-
logger.error(`announcement ${id}: what was sent could not be kept`, error)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
176
|
/**
|
|
188
177
|
* Tells `userIds` of it once the request's transaction has committed - a reader told before it would not find it yet -
|
|
189
178
|
* and keeps what went out. A notice that does not arrive does not undo the announcement: its list, badge and popup
|
|
@@ -194,7 +183,7 @@ export async function tellWhenCommitted(context: any, one: Announcement, kind: N
|
|
|
194
183
|
if (!receivers.length) return
|
|
195
184
|
const broadcast = toEveryone && broadcastOf(await audiencesOf(one.id, context.state.tx), context.state.domain?.id)
|
|
196
185
|
sendNoticeWhenCommitted(context, noticeOf(one, kind, receivers, broadcast, noticeLinkOf(context, viewAddressOf(one.id))), result =>
|
|
197
|
-
|
|
186
|
+
keepNoticeDelivery(Announcement, one.id, 'deliveries', noticeDeliveryOf(kind, result, receivers.length))
|
|
198
187
|
)
|
|
199
188
|
}
|
|
200
189
|
|
|
@@ -222,7 +211,7 @@ export async function publishDue(now = new Date()): Promise<number> {
|
|
|
222
211
|
/* No request, so no address to put on a mail button - the mail says where to find it instead. */
|
|
223
212
|
const people = await receiversOf(receivers)
|
|
224
213
|
const broadcast = broadcastOf(await audiencesOf(one.id), one.domain?.id)
|
|
225
|
-
if (people.length) await
|
|
214
|
+
if (people.length) await keepNoticeDelivery(Announcement, one.id, 'deliveries', noticeDeliveryOf('published', await sendNotice(one.domain, noticeOf(one, 'published', people, broadcast)), people.length))
|
|
226
215
|
} catch (error) {
|
|
227
216
|
logger.error(`announcement ${one.id}: publishing at its start failed`, error)
|
|
228
217
|
}
|
|
@@ -11,9 +11,11 @@ const { existsSync } = require('fs')
|
|
|
11
11
|
const { join } = require('path')
|
|
12
12
|
const { DataSource } = require('typeorm')
|
|
13
13
|
|
|
14
|
-
/* What notification was asked to send (ADR-0164) - the channels themselves are notification's tests.
|
|
14
|
+
/* What notification was asked to send (ADR-0164) - the channels themselves are notification's tests. What went out is
|
|
15
|
+
* kept on the announcement by notification's own record (`keepNoticeDelivery`), so the real one is used. */
|
|
15
16
|
const told: { domain: any; notice: any }[] = []
|
|
16
17
|
jest.mock('@things-factory/notification', () => ({
|
|
18
|
+
...jest.requireActual('@things-factory/notification/dist-server/controllers/notice/notice-delivery-record.js'),
|
|
17
19
|
sendNotice: async (domain: any, notice: any) => {
|
|
18
20
|
told.push({ domain, notice })
|
|
19
21
|
return { receivers: notice.receivers.length, email: { sent: notice.channels?.email ? notice.receivers.length : 0, failed: 0 }, teams: { sent: 0, failed: 0 } }
|
|
@@ -7,9 +7,7 @@ import {
|
|
|
7
7
|
inputRefusal,
|
|
8
8
|
isCurrent,
|
|
9
9
|
linkRefusal,
|
|
10
|
-
deliveryOf,
|
|
11
10
|
noticeWordsOf,
|
|
12
|
-
withDelivery,
|
|
13
11
|
owedReminder,
|
|
14
12
|
periodOf,
|
|
15
13
|
readerNarrowingOf,
|
|
@@ -194,19 +192,6 @@ describe('the notice', () => {
|
|
|
194
192
|
expect(noticeWordsOf({ title: 'x' }, 'published', say).body).toBe('')
|
|
195
193
|
})
|
|
196
194
|
|
|
197
|
-
it('★ each telling is kept - what went out, or that nothing could go', () => {
|
|
198
|
-
const at = new Date('2026-10-26T09:00:00Z')
|
|
199
|
-
const sent = { receivers: 3, email: { sent: 2, failed: 1 }, teams: { sent: 0, failed: 0 } }
|
|
200
|
-
expect(deliveryOf('published', sent, 3, at)).toEqual({ at: '2026-10-26T09:00:00.000Z', kind: 'published', ...sent })
|
|
201
|
-
expect(deliveryOf('reminder', undefined, 4, at)).toEqual({ at: '2026-10-26T09:00:00.000Z', kind: 'reminder', receivers: 4, email: { sent: 0, failed: 0 }, teams: { sent: 0, failed: 0 }, failed: true })
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
it('the record keeps the newest fifty', () => {
|
|
205
|
-
const many = Array.from({ length: 50 }, (_, i) => i)
|
|
206
|
-
expect(withDelivery(many, 50)).toEqual(Array.from({ length: 50 }, (_, i) => i + 1))
|
|
207
|
-
expect(withDelivery(null, 1)).toEqual([1])
|
|
208
|
-
})
|
|
209
|
-
|
|
210
195
|
it('★ only the marks that wrap words go - a lone ~, _ or | is part of the text', () => {
|
|
211
196
|
expect(plainSummary('**11월 2일(월) 22시~24시** 점검 · ~~취소~~ `a_b` *기울임* | 표')).toBe('11월 2일(월) 22시~24시 점검 · 취소 a_b 기울임 | 표')
|
|
212
197
|
})
|