@infuro/cms-core 1.0.65 → 1.0.67

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.
Files changed (36) hide show
  1. package/dist/admin.cjs +97 -24
  2. package/dist/admin.js +97 -24
  3. package/dist/api.cjs +38 -38
  4. package/dist/api.js +5 -5
  5. package/dist/auth.cjs +51 -51
  6. package/dist/auth.js +3 -3
  7. package/dist/{chunk-6DBDJ4VD.js → chunk-2ISSXYBZ.js} +2 -2
  8. package/dist/{chunk-NIRYYJIJ.cjs → chunk-5MZFQRDW.cjs} +73 -55
  9. package/dist/{chunk-MVHDC3XF.js → chunk-5NOZSG6J.js} +22 -11
  10. package/dist/{chunk-YHEITFHR.cjs → chunk-BVLN75LP.cjs} +540 -143
  11. package/dist/{chunk-YEAXE4U2.js → chunk-FLUF2GZH.js} +5 -11
  12. package/dist/{chunk-SANKKGB3.js → chunk-GLLCLRCQ.js} +464 -67
  13. package/dist/{chunk-ACBN6UWZ.js → chunk-NV5IRHI3.js} +26 -8
  14. package/dist/{chunk-J7FMZK66.cjs → chunk-O4AFPDQ4.cjs} +22 -11
  15. package/dist/{chunk-4U6DATGZ.cjs → chunk-OV5TRZET.cjs} +7 -7
  16. package/dist/{chunk-BXAKL2TF.cjs → chunk-PA6YDMFZ.cjs} +5 -11
  17. package/dist/{chunk-RDEVZMO5.js → chunk-RCE5SJBA.js} +2 -2
  18. package/dist/{chunk-KM2I6AFP.cjs → chunk-SS3K7OIM.cjs} +9 -9
  19. package/dist/{chunk-V6EYAC7X.cjs → chunk-WMMZZRDJ.cjs} +15 -15
  20. package/dist/{chunk-NR44CK5E.js → chunk-ZY64VJMS.js} +1 -1
  21. package/dist/{emit-order-notification-trigger-UCKJHDQK.js → emit-order-notification-trigger-EJJZ6XTS.js} +2 -2
  22. package/dist/{emit-order-notification-trigger-DR74TQXN.cjs → emit-order-notification-trigger-ZD5YN3JM.cjs} +4 -4
  23. package/dist/index.cjs +284 -280
  24. package/dist/index.d.cts +14 -1
  25. package/dist/index.d.ts +14 -1
  26. package/dist/index.js +10 -10
  27. package/dist/migrations/1783300000000-CreateOrderAssigneesTable.ts +43 -0
  28. package/dist/{order-assignees-handlers-NPKD64P6.cjs → order-assignees-handlers-KF7RMTV5.cjs} +77 -8
  29. package/dist/{order-assignees-handlers-LKMAGLG6.js → order-assignees-handlers-L3RVKUBS.js} +77 -8
  30. package/dist/{order-completion-otp-handlers-RW5RSXH3.cjs → order-completion-otp-handlers-DZAXK4GQ.cjs} +70 -16
  31. package/dist/{order-completion-otp-handlers-CH22ZRAI.js → order-completion-otp-handlers-HFGCPC4O.js} +69 -15
  32. package/dist/{order-notification-dispatcher-3TXUAJ7L.js → order-notification-dispatcher-ECPFI7CD.js} +2 -2
  33. package/dist/{order-notification-dispatcher-Y7NZAALH.cjs → order-notification-dispatcher-LL7ETKLU.cjs} +7 -7
  34. package/dist/{rbac-debug-db-5R6XFPSV.js → rbac-debug-db-DFZWZ6GV.js} +1 -1
  35. package/dist/{rbac-debug-db-JKK2MCWF.cjs → rbac-debug-db-KWV7D5PQ.cjs} +2 -2
  36. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkV6EYAC7X_cjs = require('./chunk-V6EYAC7X.cjs');
3
+ var chunkWMMZZRDJ_cjs = require('./chunk-WMMZZRDJ.cjs');
4
4
  var chunkWFMVD567_cjs = require('./chunk-WFMVD567.cjs');
5
5
  var chunkH3IVLIPR_cjs = require('./chunk-H3IVLIPR.cjs');
6
- require('./chunk-BXAKL2TF.cjs');
6
+ require('./chunk-PA6YDMFZ.cjs');
7
7
  var chunkXFDIIVZB_cjs = require('./chunk-XFDIIVZB.cjs');
8
8
  require('./chunk-GLD263KW.cjs');
9
9
  require('./chunk-UPLVMVRX.cjs');
@@ -65,7 +65,55 @@ async function getOtpChannelsConfig(dataSource, entityMap) {
65
65
  };
66
66
  }
67
67
  chunkUSNT2KNT_cjs.__name(getOtpChannelsConfig, "getOtpChannelsConfig");
68
- function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
68
+ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser) {
69
+ async function verifyOrderAccess(order) {
70
+ const session = await getHydratedSessionUser?.() ?? null;
71
+ if (!session) return null;
72
+ const isPlatformAdmin = Boolean(session.isRBACAdmin && !session.isVendorPortal);
73
+ if (isPlatformAdmin) return null;
74
+ const userVendorIds = session.vendorIds ?? [];
75
+ const orderVendorId = Number(order.vendorId);
76
+ let hasVendorOrderAccess = Boolean(orderVendorId && userVendorIds.includes(orderVendorId));
77
+ if (!hasVendorOrderAccess) {
78
+ const aId = Number(order.assignedUserId);
79
+ if (Number.isFinite(aId) && aId > 0 && entityMap.vendor_users) {
80
+ const vuRepo = dataSource.getRepository(entityMap.vendor_users);
81
+ for (const vId of userVendorIds) {
82
+ const count = await vuRepo.count({
83
+ where: {
84
+ vendorId: vId,
85
+ userId: aId
86
+ }
87
+ });
88
+ if (count > 0) {
89
+ hasVendorOrderAccess = true;
90
+ break;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ if (!hasVendorOrderAccess) {
96
+ return json({
97
+ error: "Forbidden: Access denied to vendor order"
98
+ }, {
99
+ status: 403
100
+ });
101
+ }
102
+ const isVendorOwner = Boolean(session.isVendorOwner || session.isVendorRoleOwner);
103
+ if (!isVendorOwner) {
104
+ const sessionUserId = Number(session.id);
105
+ const assignedUserId = Number(order.assignedUserId);
106
+ if (!Number.isFinite(assignedUserId) || assignedUserId !== sessionUserId) {
107
+ return json({
108
+ error: "Forbidden: You can only process orders assigned directly to you"
109
+ }, {
110
+ status: 403
111
+ });
112
+ }
113
+ }
114
+ return null;
115
+ }
116
+ chunkUSNT2KNT_cjs.__name(verifyOrderAccess, "verifyOrderAccess");
69
117
  return {
70
118
  /** GET /api/orders/:id/completion-otp/channels */
71
119
  async getChannels(req, orderId) {
@@ -93,6 +141,8 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
93
141
  status: 404
94
142
  });
95
143
  }
144
+ const accessError = await verifyOrderAccess(order);
145
+ if (accessError) return accessError;
96
146
  const o = order;
97
147
  const cfg = await getOtpChannelsConfig(dataSource, entityMap);
98
148
  const customerEmail = o.contact?.email?.trim();
@@ -147,6 +197,8 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
147
197
  status: 404
148
198
  });
149
199
  }
200
+ const accessError = await verifyOrderAccess(order);
201
+ if (accessError) return accessError;
150
202
  const o = order;
151
203
  if (o.status === "completed") {
152
204
  return json({
@@ -304,18 +356,6 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
304
356
  status: 400
305
357
  });
306
358
  }
307
- const verifyResult = await chunkWFMVD567_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
308
- purpose: "order_completion",
309
- identifier: `order:${orderId}`,
310
- code
311
- });
312
- if (!verifyResult.ok) {
313
- return json({
314
- error: verifyResult.error
315
- }, {
316
- status: verifyResult.status
317
- });
318
- }
319
359
  const orderRepo = dataSource.getRepository(entityMap.orders);
320
360
  const order = await orderRepo.findOne({
321
361
  where: {
@@ -333,13 +373,27 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
333
373
  status: 404
334
374
  });
335
375
  }
376
+ const accessError = await verifyOrderAccess(order);
377
+ if (accessError) return accessError;
378
+ const verifyResult = await chunkWFMVD567_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
379
+ purpose: "order_completion",
380
+ identifier: `order:${orderId}`,
381
+ code
382
+ });
383
+ if (!verifyResult.ok) {
384
+ return json({
385
+ error: verifyResult.error
386
+ }, {
387
+ status: verifyResult.status
388
+ });
389
+ }
336
390
  const now = /* @__PURE__ */ new Date();
337
391
  order.status = "completed";
338
392
  order.completedAt = now;
339
393
  order.updatedAt = now;
340
394
  await orderRepo.save(order);
341
395
  try {
342
- await chunkV6EYAC7X_cjs.fireOrderNotificationTrigger("order_completed", orderId, {
396
+ await chunkWMMZZRDJ_cjs.fireOrderNotificationTrigger("order_completed", orderId, {
343
397
  dataSource,
344
398
  entityMap
345
399
  });
@@ -1,7 +1,7 @@
1
- import { fireOrderNotificationTrigger } from './chunk-RDEVZMO5.js';
1
+ import { fireOrderNotificationTrigger } from './chunk-RCE5SJBA.js';
2
2
  import { verifyAndConsumeOtpChallenge, generateNumericOtp, createOtpChallenge, queueSms } from './chunk-OVTOP42W.js';
3
3
  import { queueWhatsApp } from './chunk-GWDI752Q.js';
4
- import './chunk-YEAXE4U2.js';
4
+ import './chunk-FLUF2GZH.js';
5
5
  import { queueEmail } from './chunk-TU23GJPJ.js';
6
6
  import './chunk-OPJEV44S.js';
7
7
  import './chunk-JC6DLWTE.js';
@@ -63,7 +63,55 @@ async function getOtpChannelsConfig(dataSource, entityMap) {
63
63
  };
64
64
  }
65
65
  __name(getOtpChannelsConfig, "getOtpChannelsConfig");
66
- function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
66
+ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser) {
67
+ async function verifyOrderAccess(order) {
68
+ const session = await getHydratedSessionUser?.() ?? null;
69
+ if (!session) return null;
70
+ const isPlatformAdmin = Boolean(session.isRBACAdmin && !session.isVendorPortal);
71
+ if (isPlatformAdmin) return null;
72
+ const userVendorIds = session.vendorIds ?? [];
73
+ const orderVendorId = Number(order.vendorId);
74
+ let hasVendorOrderAccess = Boolean(orderVendorId && userVendorIds.includes(orderVendorId));
75
+ if (!hasVendorOrderAccess) {
76
+ const aId = Number(order.assignedUserId);
77
+ if (Number.isFinite(aId) && aId > 0 && entityMap.vendor_users) {
78
+ const vuRepo = dataSource.getRepository(entityMap.vendor_users);
79
+ for (const vId of userVendorIds) {
80
+ const count = await vuRepo.count({
81
+ where: {
82
+ vendorId: vId,
83
+ userId: aId
84
+ }
85
+ });
86
+ if (count > 0) {
87
+ hasVendorOrderAccess = true;
88
+ break;
89
+ }
90
+ }
91
+ }
92
+ }
93
+ if (!hasVendorOrderAccess) {
94
+ return json({
95
+ error: "Forbidden: Access denied to vendor order"
96
+ }, {
97
+ status: 403
98
+ });
99
+ }
100
+ const isVendorOwner = Boolean(session.isVendorOwner || session.isVendorRoleOwner);
101
+ if (!isVendorOwner) {
102
+ const sessionUserId = Number(session.id);
103
+ const assignedUserId = Number(order.assignedUserId);
104
+ if (!Number.isFinite(assignedUserId) || assignedUserId !== sessionUserId) {
105
+ return json({
106
+ error: "Forbidden: You can only process orders assigned directly to you"
107
+ }, {
108
+ status: 403
109
+ });
110
+ }
111
+ }
112
+ return null;
113
+ }
114
+ __name(verifyOrderAccess, "verifyOrderAccess");
67
115
  return {
68
116
  /** GET /api/orders/:id/completion-otp/channels */
69
117
  async getChannels(req, orderId) {
@@ -91,6 +139,8 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
91
139
  status: 404
92
140
  });
93
141
  }
142
+ const accessError = await verifyOrderAccess(order);
143
+ if (accessError) return accessError;
94
144
  const o = order;
95
145
  const cfg = await getOtpChannelsConfig(dataSource, entityMap);
96
146
  const customerEmail = o.contact?.email?.trim();
@@ -145,6 +195,8 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
145
195
  status: 404
146
196
  });
147
197
  }
198
+ const accessError = await verifyOrderAccess(order);
199
+ if (accessError) return accessError;
148
200
  const o = order;
149
201
  if (o.status === "completed") {
150
202
  return json({
@@ -302,18 +354,6 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
302
354
  status: 400
303
355
  });
304
356
  }
305
- const verifyResult = await verifyAndConsumeOtpChallenge(dataSource, entityMap, {
306
- purpose: "order_completion",
307
- identifier: `order:${orderId}`,
308
- code
309
- });
310
- if (!verifyResult.ok) {
311
- return json({
312
- error: verifyResult.error
313
- }, {
314
- status: verifyResult.status
315
- });
316
- }
317
357
  const orderRepo = dataSource.getRepository(entityMap.orders);
318
358
  const order = await orderRepo.findOne({
319
359
  where: {
@@ -331,6 +371,20 @@ function createOrderCompletionOtpHandlers(dataSource, entityMap, getCms) {
331
371
  status: 404
332
372
  });
333
373
  }
374
+ const accessError = await verifyOrderAccess(order);
375
+ if (accessError) return accessError;
376
+ const verifyResult = await verifyAndConsumeOtpChallenge(dataSource, entityMap, {
377
+ purpose: "order_completion",
378
+ identifier: `order:${orderId}`,
379
+ code
380
+ });
381
+ if (!verifyResult.ok) {
382
+ return json({
383
+ error: verifyResult.error
384
+ }, {
385
+ status: verifyResult.status
386
+ });
387
+ }
334
388
  const now = /* @__PURE__ */ new Date();
335
389
  order.status = "completed";
336
390
  order.completedAt = now;
@@ -1,6 +1,6 @@
1
- export { dispatchOrderNotificationDirectly, emitOrderNotificationTrigger, getSettingsGroup, initWhatsappTriggerDispatcher, resendOrderNotification } from './chunk-ACBN6UWZ.js';
1
+ export { dispatchOrderNotificationDirectly, emitOrderNotificationTrigger, getSettingsGroup, initWhatsappTriggerDispatcher, resendOrderNotification } from './chunk-NV5IRHI3.js';
2
2
  import './chunk-GWDI752Q.js';
3
- import './chunk-YEAXE4U2.js';
3
+ import './chunk-FLUF2GZH.js';
4
4
  import './chunk-6YOQ7G5O.js';
5
5
  import './chunk-TU23GJPJ.js';
6
6
  import './chunk-OPJEV44S.js';
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkNIRYYJIJ_cjs = require('./chunk-NIRYYJIJ.cjs');
3
+ var chunk5MZFQRDW_cjs = require('./chunk-5MZFQRDW.cjs');
4
4
  require('./chunk-H3IVLIPR.cjs');
5
- require('./chunk-BXAKL2TF.cjs');
5
+ require('./chunk-PA6YDMFZ.cjs');
6
6
  require('./chunk-VM6OVUUM.cjs');
7
7
  require('./chunk-XFDIIVZB.cjs');
8
8
  require('./chunk-GLD263KW.cjs');
@@ -15,21 +15,21 @@ require('./chunk-USNT2KNT.cjs');
15
15
 
16
16
  Object.defineProperty(exports, "dispatchOrderNotificationDirectly", {
17
17
  enumerable: true,
18
- get: function () { return chunkNIRYYJIJ_cjs.dispatchOrderNotificationDirectly; }
18
+ get: function () { return chunk5MZFQRDW_cjs.dispatchOrderNotificationDirectly; }
19
19
  });
20
20
  Object.defineProperty(exports, "emitOrderNotificationTrigger", {
21
21
  enumerable: true,
22
- get: function () { return chunkNIRYYJIJ_cjs.emitOrderNotificationTrigger; }
22
+ get: function () { return chunk5MZFQRDW_cjs.emitOrderNotificationTrigger; }
23
23
  });
24
24
  Object.defineProperty(exports, "getSettingsGroup", {
25
25
  enumerable: true,
26
- get: function () { return chunkNIRYYJIJ_cjs.getSettingsGroup; }
26
+ get: function () { return chunk5MZFQRDW_cjs.getSettingsGroup; }
27
27
  });
28
28
  Object.defineProperty(exports, "initWhatsappTriggerDispatcher", {
29
29
  enumerable: true,
30
- get: function () { return chunkNIRYYJIJ_cjs.initWhatsappTriggerDispatcher; }
30
+ get: function () { return chunk5MZFQRDW_cjs.initWhatsappTriggerDispatcher; }
31
31
  });
32
32
  Object.defineProperty(exports, "resendOrderNotification", {
33
33
  enumerable: true,
34
- get: function () { return chunkNIRYYJIJ_cjs.resendOrderNotification; }
34
+ get: function () { return chunk5MZFQRDW_cjs.resendOrderNotification; }
35
35
  });
@@ -1,4 +1,4 @@
1
- import { summarizeEntityPerms, permissionRowsToRecord } from './chunk-MVHDC3XF.js';
1
+ import { summarizeEntityPerms, permissionRowsToRecord } from './chunk-5NOZSG6J.js';
2
2
  import { __name } from './chunk-SHUYVCID.js';
3
3
 
4
4
  // src/auth/rbac-debug-db.ts
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkJ7FMZK66_cjs = require('./chunk-J7FMZK66.cjs');
3
+ var chunkO4AFPDQ4_cjs = require('./chunk-O4AFPDQ4.cjs');
4
4
  var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
5
5
 
6
6
  // src/auth/rbac-debug-db.ts
@@ -27,7 +27,7 @@ async function loadDbPermissionsForUser(dataSource, userId) {
27
27
  return {
28
28
  groupId,
29
29
  groupName,
30
- dbEntityPerms: chunkJ7FMZK66_cjs.summarizeEntityPerms(chunkJ7FMZK66_cjs.permissionRowsToRecord(permRows))
30
+ dbEntityPerms: chunkO4AFPDQ4_cjs.summarizeEntityPerms(chunkO4AFPDQ4_cjs.permissionRowsToRecord(permRows))
31
31
  };
32
32
  }
33
33
  chunkUSNT2KNT_cjs.__name(loadDbPermissionsForUser, "loadDbPermissionsForUser");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infuro/cms-core",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",