@tstdl/base 0.93.185 → 0.93.186

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.
@@ -1,3 +1,4 @@
1
+ /** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
1
2
  import { TenantEntity, type Uuid } from '../../orm/index.js';
2
3
  import { NotificationChannel } from './notification-log.model.js';
3
4
  export declare class NotificationPreference extends TenantEntity {
@@ -7,3 +8,9 @@ export declare class NotificationPreference extends TenantEntity {
7
8
  channel: NotificationChannel;
8
9
  enabled: boolean;
9
10
  }
11
+ export declare class NotificationPreferenceView {
12
+ type: string;
13
+ channel: NotificationChannel;
14
+ enabled: boolean;
15
+ }
16
+ export declare function toNotificationPreferenceView(preference: NotificationPreference): NotificationPreferenceView;
@@ -1,3 +1,4 @@
1
+ /** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
1
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -43,3 +44,27 @@ NotificationPreference = __decorate([
43
44
  Unique(['tenantId', 'userId', 'type', 'channel'])
44
45
  ], NotificationPreference);
45
46
  export { NotificationPreference };
47
+ export class NotificationPreferenceView {
48
+ type;
49
+ channel;
50
+ enabled;
51
+ }
52
+ __decorate([
53
+ StringProperty(),
54
+ __metadata("design:type", String)
55
+ ], NotificationPreferenceView.prototype, "type", void 0);
56
+ __decorate([
57
+ Enumeration(NotificationChannel),
58
+ __metadata("design:type", String)
59
+ ], NotificationPreferenceView.prototype, "channel", void 0);
60
+ __decorate([
61
+ BooleanProperty(),
62
+ __metadata("design:type", Boolean)
63
+ ], NotificationPreferenceView.prototype, "enabled", void 0);
64
+ export function toNotificationPreferenceView(preference) {
65
+ return {
66
+ type: preference.type,
67
+ channel: preference.channel,
68
+ enabled: preference.enabled,
69
+ };
70
+ }
@@ -1,22 +1,23 @@
1
1
  import type { ApiController, ApiRequestContext, ApiServerResult } from '../../../api/types.js';
2
2
  import type { NotificationApiDefinition } from '../../api/notification.api.js';
3
+ import type { InAppNotificationView, NotificationPreferenceView } from '../../models/index.js';
3
4
  import { NotificationSseService } from '../services/notification-sse.service.js';
4
5
  import { NotificationTypeService } from '../services/notification-type.service.js';
5
6
  import { NotificationService } from '../services/notification.service.js';
6
7
  export declare class NotificationApiController implements ApiController<NotificationApiDefinition> {
7
- protected readonly notificationService: NotificationService<Record<string, import("../../index.js").NotificationDefinition<import("../../../types/types.js").ObjectLiteral, import("../../../types/types.js").ObjectLiteral>>>;
8
+ protected readonly notificationService: NotificationService<Record<string, import("../../models/notification-log.model.js").NotificationDefinition<import("../../../types/types.js").ObjectLiteral, import("../../../types/types.js").ObjectLiteral>>>;
8
9
  protected readonly notificationTypeService: NotificationTypeService;
9
10
  protected readonly sseService: NotificationSseService;
10
11
  stream({ abortSignal, getToken, serverSentEvents: { lastEventId } }: ApiRequestContext<NotificationApiDefinition, 'stream'>): ApiServerResult<NotificationApiDefinition, 'stream'>;
11
12
  types(): Promise<Record<string, string>>;
12
- listInApp({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'listInApp'>): Promise<any>;
13
- listArchivedInApp({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'listArchivedInApp'>): Promise<any>;
13
+ listInApp({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'listInApp'>): Promise<InAppNotificationView[]>;
14
+ listArchivedInApp({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'listArchivedInApp'>): Promise<InAppNotificationView[]>;
14
15
  markRead({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'markRead'>): Promise<'ok'>;
15
16
  markAllRead({ getToken }: ApiRequestContext<NotificationApiDefinition, 'markAllRead'>): Promise<'ok'>;
16
17
  archive({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'archive'>): Promise<'ok'>;
17
18
  archiveAll({ getToken }: ApiRequestContext<NotificationApiDefinition, 'archiveAll'>): Promise<'ok'>;
18
19
  unreadCount({ getToken }: ApiRequestContext<NotificationApiDefinition, 'unreadCount'>): Promise<number>;
19
- getPreferences({ getToken }: ApiRequestContext<NotificationApiDefinition, 'getPreferences'>): Promise<any>;
20
+ getPreferences({ getToken }: ApiRequestContext<NotificationApiDefinition, 'getPreferences'>): Promise<NotificationPreferenceView[]>;
20
21
  updatePreferences({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'updatePreferences'>): Promise<'ok'>;
21
22
  registerWebPush({ parameters, getToken }: ApiRequestContext<NotificationApiDefinition, 'registerWebPush'>): Promise<'ok'>;
22
23
  }
@@ -83,7 +83,7 @@ let NotificationApiController = class NotificationApiController {
83
83
  }
84
84
  async getPreferences({ getToken }) {
85
85
  const token = await getToken();
86
- return await this.notificationService.getPreferences(token.payload.tenant, token.payload.subject);
86
+ return await this.notificationService.getPreferenceViews(token.payload.tenant, token.payload.subject);
87
87
  }
88
88
  async updatePreferences({ parameters, getToken }) {
89
89
  const token = await getToken();
@@ -1,7 +1,7 @@
1
1
  import { type NewEntity, type Query } from '../../../orm/index.js';
2
2
  import { Transactional, type Transaction } from '../../../orm/server/index.js';
3
3
  import type { TypedOmit } from '../../../types/types.js';
4
- import { NotificationChannel, NotificationLogEntity, NotificationPreference, type InAppNotificationView, type NotificationDefinitionMap, type NotificationLog } from '../../models/index.js';
4
+ import { NotificationChannel, NotificationLogEntity, NotificationPreference, type InAppNotificationView, type NotificationDefinitionMap, type NotificationLog, type NotificationPreferenceView } from '../../models/index.js';
5
5
  export type NewNotificationData<Definitions extends NotificationDefinitionMap = NotificationDefinitionMap> = TypedOmit<NewEntity<NotificationLog<Definitions>>, 'tenantId' | 'id' | 'userId' | 'timestamp' | 'status' | 'currentStep' | 'priority'> & Partial<Pick<NotificationLog<Definitions>, 'priority'>>;
6
6
  export declare class NotificationService<Definitions extends NotificationDefinitionMap = NotificationDefinitionMap> extends Transactional {
7
7
  #private;
@@ -33,6 +33,7 @@ export declare class NotificationService<Definitions extends NotificationDefinit
33
33
  archiveIds: string[];
34
34
  }>;
35
35
  getPreferences(tenantId: string, userId: string): Promise<NotificationPreference[]>;
36
+ getPreferenceViews(tenantId: string, userId: string): Promise<NotificationPreferenceView[]>;
36
37
  updatePreference(tenantId: string, userId: string, type: string, channel: NotificationChannel, enabled: boolean): Promise<void>;
37
38
  updatePreferences(tenantId: string, userId: string, preferences: {
38
39
  type: string;
@@ -16,7 +16,7 @@ import { injectRepository, Transactional } from '../../../orm/server/index.js';
16
16
  import { TaskQueue } from '../../../task-queue/task-queue.js';
17
17
  import { tryIgnoreLogAsync } from '../../../utils/try-ignore.js';
18
18
  import { isDefined, isUndefined } from '../../../utils/type-guards.js';
19
- import { InAppNotification, InAppNotificationArchive, NotificationChannel, NotificationLogEntity, NotificationPreference, NotificationPriority, NotificationStatus, toInAppNotificationView, WebPushSubscription } from '../../models/index.js';
19
+ import { InAppNotification, InAppNotificationArchive, NotificationChannel, NotificationLogEntity, NotificationPreference, NotificationPriority, NotificationStatus, toInAppNotificationView, toNotificationPreferenceView, WebPushSubscription } from '../../models/index.js';
20
20
  import { NotificationConfiguration } from '../module.js';
21
21
  import { inAppNotification, inAppNotificationArchive, notificationLog } from '../schemas.js';
22
22
  import { NotificationAncillaryService } from './notification-ancillary.service.js';
@@ -234,6 +234,10 @@ let NotificationService = NotificationService_1 = class NotificationService exte
234
234
  async getPreferences(tenantId, userId) {
235
235
  return await this.#preferenceRepository.loadManyByQuery({ tenantId, userId });
236
236
  }
237
+ async getPreferenceViews(tenantId, userId) {
238
+ const preferences = await this.getPreferences(tenantId, userId);
239
+ return preferences.map(toNotificationPreferenceView);
240
+ }
237
241
  async updatePreference(tenantId, userId, type, channel, enabled) {
238
242
  await this.#preferenceRepository.upsert(['tenantId', 'userId', 'type', 'channel'], { tenantId, userId, type, channel, enabled });
239
243
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.185",
3
+ "version": "0.93.186",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"