@tstdl/base 0.93.118 → 0.93.120

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,10 +1,12 @@
1
+ import { afterResolve } from '../../../injector/index.js';
1
2
  import { type NewEntity } from '../../../orm/index.js';
2
3
  import { Transactional, type Transaction } from '../../../orm/server/index.js';
3
4
  import type { TypedOmit } from '../../../types/types.js';
4
- import { NotificationPreference, type InAppNotificationView, type NotificationChannel, type NotificationDefinitionMap, type NotificationLog } from '../../models/index.js';
5
+ import { NotificationChannel, NotificationPreference, type InAppNotificationView, type NotificationDefinitionMap, type NotificationLog } from '../../models/index.js';
5
6
  export type NewNotificationData<Definitions extends NotificationDefinitionMap = NotificationDefinitionMap> = TypedOmit<NewEntity<NotificationLog<Definitions>>, 'tenantId' | 'id' | 'userId' | 'timestamp' | 'status' | 'currentStep' | 'priority'> & Partial<Pick<NotificationLog<Definitions>, 'priority'>>;
6
7
  export declare class NotificationService<Definitions extends NotificationDefinitionMap = NotificationDefinitionMap> extends Transactional {
7
8
  #private;
9
+ [afterResolve](): void;
8
10
  send(tenantId: string, userId: string, notification: NewNotificationData<Definitions>, options?: {
9
11
  transaction: Transaction;
10
12
  }): Promise<void>;
@@ -7,17 +7,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var _a;
8
8
  var NotificationService_1;
9
9
  import { and, desc, eq, isNull, lt, or } from 'drizzle-orm';
10
+ import { CancellationSignal } from '../../../cancellation/token.js';
10
11
  import { BadRequestError } from '../../../errors/bad-request.error.js';
11
- import { inject, Singleton } from '../../../injector/index.js';
12
+ import { afterResolve, inject, Singleton } from '../../../injector/index.js';
12
13
  import { Logger } from '../../../logger/logger.js';
13
14
  import { TRANSACTION_TIMESTAMP } from '../../../orm/index.js';
14
15
  import { injectRepository, Transactional } from '../../../orm/server/index.js';
15
16
  import { TaskQueue } from '../../../task-queue/task-queue.js';
16
17
  import { tryIgnoreLogAsync } from '../../../utils/try-ignore.js';
17
18
  import { isDefined } from '../../../utils/type-guards.js';
18
- import { InAppNotification, NotificationLogEntity, NotificationPreference, NotificationPriority, NotificationStatus, toInAppNotificationView, WebPushSubscription } from '../../models/index.js';
19
+ import { InAppNotification, NotificationChannel, NotificationLogEntity, NotificationPreference, NotificationPriority, NotificationStatus, toInAppNotificationView, WebPushSubscription } from '../../models/index.js';
20
+ import { InAppChannelProvider } from '../providers/index.js';
19
21
  import { inAppNotification, notificationLog } from '../schemas.js';
20
22
  import { NotificationAncillaryService } from './notification-ancillary.service.js';
23
+ import { NotificationDeliveryWorker } from './notification-delivery.worker.js';
21
24
  import { NotificationSseService } from './notification-sse.service.js';
22
25
  let NotificationService = NotificationService_1 = class NotificationService extends Transactional {
23
26
  #notificationLogRepository = injectRepository(NotificationLogEntity);
@@ -25,9 +28,16 @@ let NotificationService = NotificationService_1 = class NotificationService exte
25
28
  #preferenceRepository = injectRepository(NotificationPreference);
26
29
  #webPushSubscriptionRepository = injectRepository(WebPushSubscription);
27
30
  #notificationAncillaryService = inject(NotificationAncillaryService);
31
+ #deliveryWorker = inject(NotificationDeliveryWorker);
32
+ #inAppChannelProvider = inject(InAppChannelProvider);
28
33
  #taskQueue = inject((TaskQueue), 'notification');
29
34
  #sseService = inject(NotificationSseService);
30
35
  #logger = inject(Logger, NotificationService_1.name);
36
+ #cancellationSignal = inject(CancellationSignal);
37
+ [afterResolve]() {
38
+ this.#deliveryWorker.registerProvider(NotificationChannel.InApp, this.#inAppChannelProvider);
39
+ this.#deliveryWorker.run(this.#cancellationSignal);
40
+ }
31
41
  async send(tenantId, userId, notification, options) {
32
42
  await this.useTransaction(options?.transaction, async (tx) => {
33
43
  const notificationToInsert = {
@@ -135,7 +145,7 @@ let NotificationService = NotificationService_1 = class NotificationService exte
135
145
  async dispatchUnreadCountUpdate(tenantId, userId) {
136
146
  await tryIgnoreLogAsync(this.#logger, async () => {
137
147
  const unreadCount = await this.unreadCount(tenantId, userId);
138
- this.#sseService.dispatchUnreadCountUpdate(tenantId, userId, unreadCount);
148
+ await this.#sseService.dispatchUnreadCountUpdate(tenantId, userId, unreadCount);
139
149
  });
140
150
  }
141
151
  };
@@ -30,5 +30,6 @@ export declare class S3ObjectStorage extends ObjectStorage {
30
30
  private getKey;
31
31
  isNotFoundError(error: unknown): boolean;
32
32
  isForbiddenError(error: unknown): boolean;
33
+ isBadRequestError(error: unknown): boolean;
33
34
  isError(error: unknown, ...names: string[]): boolean;
34
35
  }
@@ -12,6 +12,7 @@ import { Readable } from 'node:stream';
12
12
  import { CopyObjectCommand, CreateBucketCommand, DeleteBucketLifecycleCommand, DeleteObjectCommand, DeleteObjectsCommand, GetBucketLifecycleConfigurationCommand, GetObjectCommand, HeadBucketCommand, HeadObjectCommand, ListObjectsV2Command, PutBucketLifecycleConfigurationCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
13
13
  import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
14
14
  import { match, P } from 'ts-pattern';
15
+ import { BadRequestError } from '../../errors/bad-request.error.js';
15
16
  import { Singleton } from '../../injector/decorators.js';
16
17
  import { registerAfterResolve } from '../../injector/resolution.js';
17
18
  import { ObjectStorage } from '../../object-storage/index.js';
@@ -55,6 +56,9 @@ let S3ObjectStorage = S3ObjectStorage_1 = class S3ObjectStorage extends ObjectSt
55
56
  }));
56
57
  return;
57
58
  }
59
+ if (this.isBadRequestError(error)) {
60
+ throw new BadRequestError(`S3 request failed with 400 Bad Request. This often indicates an invalid bucket name ("${this.bucket}") or missing "forcePathStyle: true" for local S3 providers.`);
61
+ }
58
62
  throw error;
59
63
  }
60
64
  }
@@ -280,11 +284,14 @@ let S3ObjectStorage = S3ObjectStorage_1 = class S3ObjectStorage extends ObjectSt
280
284
  return bucketKey.slice(this.prefix.length);
281
285
  }
282
286
  isNotFoundError(error) {
283
- return this.isError(error, 'NotFound', 'NoSuchKey');
287
+ return this.isError(error, 'NotFound', 'NoSuchKey', 'NoSuchBucket') || ((isObject(error) && isObject(error.$metadata) && error.$metadata.httpStatusCode == 404));
284
288
  }
285
289
  isForbiddenError(error) {
286
290
  return this.isError(error, 'Forbidden', 'AccessDenied', 'InvalidAccessKeyId', 'SignatureDoesNotMatch') || ((isObject(error) && isObject(error.$metadata) && error.$metadata.httpStatusCode == 403));
287
291
  }
292
+ isBadRequestError(error) {
293
+ return (isObject(error) && isObject(error.$metadata) && error.$metadata.httpStatusCode == 400);
294
+ }
288
295
  isError(error, ...names) {
289
296
  return isObject(error) && names.includes(error.name);
290
297
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.118",
3
+ "version": "0.93.120",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"