@webtypen/webframez-core 0.3.62 → 0.3.64

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.
@@ -123,6 +123,8 @@ declare class NotificationServiceFacade {
123
123
  set registy(registry: {
124
124
  [key: string]: NotificationDefinition;
125
125
  });
126
+ private getObjectIdString;
127
+ private normalizeObjectId;
126
128
  private getNotificationReferenceId;
127
129
  init(): void;
128
130
  registerType(type: NotificationDefinition): this;
@@ -56,16 +56,23 @@ class NotificationServiceFacade {
56
56
  set registy(registry) {
57
57
  this.registry = registry;
58
58
  }
59
- getNotificationReferenceId(notificationRef) {
60
- const notificationId = typeof notificationRef === "string"
61
- ? notificationRef
62
- : notificationRef && typeof notificationRef.toString === "function"
63
- ? notificationRef.toString()
59
+ getObjectIdString(value) {
60
+ const objectIdString = typeof value === "string"
61
+ ? value
62
+ : value && typeof value.toString === "function"
63
+ ? value.toString()
64
64
  : null;
65
- return notificationId && notificationId.length === 24 && mongodb_1.ObjectId.isValid(notificationId)
66
- ? notificationId
65
+ return objectIdString && objectIdString.length === 24 && mongodb_1.ObjectId.isValid(objectIdString)
66
+ ? objectIdString
67
67
  : null;
68
68
  }
69
+ normalizeObjectId(value) {
70
+ const objectIdString = this.getObjectIdString(value);
71
+ return objectIdString ? new mongodb_1.ObjectId(objectIdString) : null;
72
+ }
73
+ getNotificationReferenceId(notificationRef) {
74
+ return this.getObjectIdString(notificationRef);
75
+ }
69
76
  init() {
70
77
  this.registry = {};
71
78
  this.notificationsConfig = Config_1.Config.get("notifications") || {};
@@ -168,14 +175,11 @@ class NotificationServiceFacade {
168
175
  return this.targetRegistry[target] || null;
169
176
  }
170
177
  normalizeTargetId(targetId) {
171
- var _a;
172
- if (targetId instanceof mongodb_1.ObjectId)
173
- return targetId;
174
- const value = typeof targetId === "string" ? targetId : (_a = targetId === null || targetId === void 0 ? void 0 : targetId.toString) === null || _a === void 0 ? void 0 : _a.call(targetId);
175
- if (typeof value !== "string" || value.length !== 24 || !mongodb_1.ObjectId.isValid(value)) {
178
+ const normalized = this.normalizeObjectId(targetId);
179
+ if (!normalized) {
176
180
  throw new NotificationTargetValidationError("Invalid notification target_id.");
177
181
  }
178
- return new mongodb_1.ObjectId(value);
182
+ return normalized;
179
183
  }
180
184
  normalizeTargetContext(context) {
181
185
  if (!context || typeof context.target !== "string" || context.target.trim() === "") {
@@ -243,15 +247,8 @@ class NotificationServiceFacade {
243
247
  return notification;
244
248
  }
245
249
  getModelId(model) {
246
- var _a, _b;
247
- const value = (_a = model === null || model === void 0 ? void 0 : model._id) !== null && _a !== void 0 ? _a : model === null || model === void 0 ? void 0 : model.id;
248
- if (value instanceof mongodb_1.ObjectId)
249
- return value;
250
- const stringValue = typeof value === "string" ? value : (_b = value === null || value === void 0 ? void 0 : value.toString) === null || _b === void 0 ? void 0 : _b.call(value);
251
- if (typeof stringValue === "string" && stringValue.length === 24 && mongodb_1.ObjectId.isValid(stringValue)) {
252
- return new mongodb_1.ObjectId(stringValue);
253
- }
254
- return null;
250
+ var _a;
251
+ return this.normalizeObjectId((_a = model === null || model === void 0 ? void 0 : model._id) !== null && _a !== void 0 ? _a : model === null || model === void 0 ? void 0 : model.id);
255
252
  }
256
253
  getPreferencesField(target) {
257
254
  var _a;
@@ -746,18 +743,9 @@ class NotificationServiceFacade {
746
743
  getNotificationForTarget(notificationRef, context) {
747
744
  return __awaiter(this, void 0, void 0, function* () {
748
745
  const notificationId = notificationRef instanceof Notification_1.Notification ? notificationRef._id : notificationRef;
749
- if (!notificationId)
746
+ const objectId = this.normalizeObjectId(notificationId);
747
+ if (!objectId)
750
748
  return null;
751
- let objectId;
752
- if (notificationId instanceof mongodb_1.ObjectId) {
753
- objectId = notificationId;
754
- }
755
- else if (typeof notificationId === "string" && mongodb_1.ObjectId.isValid(notificationId)) {
756
- objectId = new mongodb_1.ObjectId(notificationId);
757
- }
758
- else {
759
- return null;
760
- }
761
749
  const notifications = yield Notification_1.Notification.aggregate([
762
750
  {
763
751
  $match: Object.assign(Object.assign({}, (yield this.getLoadMatch(context))), { _id: objectId }),
@@ -219,9 +219,6 @@ class NotificationsOutputChannelsJob extends BaseQueueJob_1.BaseQueueJob {
219
219
  target: notification.target,
220
220
  target_id: notification.target_id,
221
221
  });
222
- if (targetContext === null || targetContext === void 0 ? void 0 : targetContext.targetModel) {
223
- NotificationService_1.NotificationService.attachTargetModel(notification, targetContext.targetModel);
224
- }
225
222
  if (targetContext) {
226
223
  const loadedNotification = yield NotificationService_1.NotificationService.getNotificationForTarget(notification._id, targetContext);
227
224
  if (!loadedNotification) {
@@ -229,6 +226,9 @@ class NotificationsOutputChannelsJob extends BaseQueueJob_1.BaseQueueJob {
229
226
  }
230
227
  notification = loadedNotification;
231
228
  }
229
+ if (targetContext === null || targetContext === void 0 ? void 0 : targetContext.targetModel) {
230
+ NotificationService_1.NotificationService.attachTargetModel(notification, targetContext.targetModel);
231
+ }
232
232
  effectivePreference = targetContext
233
233
  ? yield NotificationService_1.NotificationService.getEffectiveTargetPreference(notType.key, targetContext)
234
234
  : { enabled: false, output_channels: [], owner_exists: false };
@@ -134,6 +134,12 @@ declare class RouterFacade {
134
134
  };
135
135
  } | undefined>;
136
136
  handleMiddleware(route: RouteObject, request: Request, response: Response): Promise<void>;
137
+ /**
138
+ * Runs registered kernel middleware outside a regular route definition.
139
+ * Package-provided multiplexing endpoints can use this while preserving
140
+ * the router's existing next/reject behavior.
141
+ */
142
+ runMiddleware(middlewareKeys: string[], request: Request, response: Response): Promise<void>;
137
143
  mapRequest(req: null | IncomingMessage, options?: any): Promise<Request>;
138
144
  parseRequestBody(req: IncomingMessage): Promise<unknown>;
139
145
  handleReturn(request: Request, response: Response, body: any): {
@@ -676,6 +676,20 @@ class RouterFacade {
676
676
  }
677
677
  });
678
678
  }
679
+ /**
680
+ * Runs registered kernel middleware outside a regular route definition.
681
+ * Package-provided multiplexing endpoints can use this while preserving
682
+ * the router's existing next/reject behavior.
683
+ */
684
+ runMiddleware(middlewareKeys, request, response) {
685
+ return __awaiter(this, void 0, void 0, function* () {
686
+ const middleware = Array.from(new Set((middlewareKeys || []).filter((key) => typeof key === "string" && key.trim() !== "")));
687
+ yield this.handleMiddleware({
688
+ path: request.pathname || request.url || "",
689
+ options: { middleware },
690
+ }, request, response);
691
+ });
692
+ }
679
693
  mapRequest(req, options) {
680
694
  return __awaiter(this, void 0, void 0, function* () {
681
695
  const request = new Request_1.Request();
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from "./BuildApplication";
15
15
  export * from "./LambdaApplication";
16
16
  export * from "./WebApplication";
17
17
  export * from "./Router/Route";
18
+ export * from "./Router/Router";
18
19
  export * from "./Router/Request";
19
20
  export * from "./Router/Response";
20
21
  export * from "./Database/BaseDBDriver";
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ __exportStar(require("./BuildApplication"), exports);
31
31
  __exportStar(require("./LambdaApplication"), exports);
32
32
  __exportStar(require("./WebApplication"), exports);
33
33
  __exportStar(require("./Router/Route"), exports);
34
+ __exportStar(require("./Router/Router"), exports);
34
35
  __exportStar(require("./Router/Request"), exports);
35
36
  __exportStar(require("./Router/Response"), exports);
36
37
  __exportStar(require("./Database/BaseDBDriver"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.3.62",
3
+ "version": "0.3.64",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",