@infuro/cms-core 1.0.59 → 1.0.60

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 (33) hide show
  1. package/dist/admin.cjs +442 -37
  2. package/dist/admin.js +443 -38
  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-3EOM4V2M.cjs → chunk-4U6DATGZ.cjs} +7 -7
  8. package/dist/{chunk-BNKZNLEX.js → chunk-6DBDJ4VD.js} +2 -2
  9. package/dist/{chunk-UQWZUZ5X.cjs → chunk-73WVHINE.cjs} +30 -6
  10. package/dist/{chunk-UCKN4BBY.cjs → chunk-77I3KS7V.cjs} +4 -1
  11. package/dist/{chunk-MCCA7WLQ.cjs → chunk-BSLNXKV2.cjs} +282 -128
  12. package/dist/{chunk-77NUXO6A.cjs → chunk-J7FMZK66.cjs} +10 -2
  13. package/dist/{chunk-BTUEUA5H.js → chunk-JAEUYYGA.js} +202 -48
  14. package/dist/{chunk-BC22I7C7.cjs → chunk-KM2I6AFP.cjs} +9 -9
  15. package/dist/{chunk-JIWUVQ6B.js → chunk-MVHDC3XF.js} +10 -2
  16. package/dist/{chunk-RK5ETF2I.js → chunk-NR44CK5E.js} +1 -1
  17. package/dist/{chunk-MXIWUFBP.js → chunk-O2642WVS.js} +28 -4
  18. package/dist/{chunk-HCIRL37O.js → chunk-T3HPSF7K.js} +4 -1
  19. package/dist/{chunk-HYW3MUXT.js → chunk-URN7GS23.js} +30 -16
  20. package/dist/{chunk-HXLC56ZK.cjs → chunk-YSYX4GUD.cjs} +32 -18
  21. package/dist/{emit-order-notification-trigger-HZQPPSFB.js → emit-order-notification-trigger-CZU3V2WE.js} +2 -2
  22. package/dist/{emit-order-notification-trigger-NR3VN6C6.cjs → emit-order-notification-trigger-TNEZOYEE.cjs} +4 -4
  23. package/dist/index.cjs +339 -301
  24. package/dist/index.d.cts +31 -0
  25. package/dist/index.d.ts +31 -0
  26. package/dist/index.js +54 -16
  27. package/dist/migrations/1782800000000-AddPaymentSuccessFailedRefundTriggers.ts +32 -0
  28. package/dist/migrations/1782900000000-AddEnableTurnstileToForms.ts +29 -0
  29. package/dist/{order-notification-dispatcher-2FCZFZUD.cjs → order-notification-dispatcher-KJVGLK5E.cjs} +5 -5
  30. package/dist/{order-notification-dispatcher-64WDCHHG.js → order-notification-dispatcher-ZSFKEYMP.js} +2 -2
  31. package/dist/{rbac-debug-db-6EMIVMGF.js → rbac-debug-db-5R6XFPSV.js} +1 -1
  32. package/dist/{rbac-debug-db-6PWTLBEL.cjs → rbac-debug-db-JKK2MCWF.cjs} +2 -2
  33. package/package.json +1 -1
@@ -2,16 +2,16 @@
2
2
 
3
3
  var chunkXQ3QUHWR_cjs = require('./chunk-XQ3QUHWR.cjs');
4
4
  var chunkHY3AXLOI_cjs = require('./chunk-HY3AXLOI.cjs');
5
- var chunkHXLC56ZK_cjs = require('./chunk-HXLC56ZK.cjs');
5
+ var chunkYSYX4GUD_cjs = require('./chunk-YSYX4GUD.cjs');
6
6
  var chunk7NMT3GBR_cjs = require('./chunk-7NMT3GBR.cjs');
7
7
  var chunkV25RDUOU_cjs = require('./chunk-V25RDUOU.cjs');
8
8
  var chunkBXYZDMTZ_cjs = require('./chunk-BXYZDMTZ.cjs');
9
9
  var chunkUPLVMVRX_cjs = require('./chunk-UPLVMVRX.cjs');
10
10
  var chunk3DZRIZOD_cjs = require('./chunk-3DZRIZOD.cjs');
11
11
  var chunkTJ2MIQUT_cjs = require('./chunk-TJ2MIQUT.cjs');
12
- var chunk3EOM4V2M_cjs = require('./chunk-3EOM4V2M.cjs');
12
+ var chunk4U6DATGZ_cjs = require('./chunk-4U6DATGZ.cjs');
13
13
  var chunkOY2YTBMP_cjs = require('./chunk-OY2YTBMP.cjs');
14
- var chunk77NUXO6A_cjs = require('./chunk-77NUXO6A.cjs');
14
+ var chunkJ7FMZK66_cjs = require('./chunk-J7FMZK66.cjs');
15
15
  var chunkD5FBNKQM_cjs = require('./chunk-D5FBNKQM.cjs');
16
16
  var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
17
17
  var typeorm = require('typeorm');
@@ -120,7 +120,7 @@ async function loadUserVendorContext(dataSource, userId, preferredVendorId) {
120
120
  `, [
121
121
  primary.vendorRoleId
122
122
  ]);
123
- vendorEntityPerms = chunk77NUXO6A_cjs.permissionRowsToRecord(permRows);
123
+ vendorEntityPerms = chunkJ7FMZK66_cjs.permissionRowsToRecord(permRows);
124
124
  } catch (err) {
125
125
  if (!isMissingVendorRoleSchemaError(err)) throw err;
126
126
  }
@@ -227,7 +227,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
227
227
  ]);
228
228
  const resolvedId = Number(byEmailRows[0]?.id);
229
229
  if (!Number.isFinite(resolvedId)) {
230
- chunk77NUXO6A_cjs.logRbac("hydrateVendorSessionUser: unable to resolve numeric user id", {
230
+ chunkJ7FMZK66_cjs.logRbac("hydrateVendorSessionUser: unable to resolve numeric user id", {
231
231
  email: user.email,
232
232
  rawSessionId: user.id ?? null
233
233
  });
@@ -247,7 +247,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
247
247
  const groupName = rows[0]?.groupName ?? user.groupName ?? null;
248
248
  const groupId = rows[0]?.groupId ?? user.groupId ?? void 0;
249
249
  const adminAccess = rows[0]?.adminAccess ?? user.adminAccess;
250
- const isRBACAdmin = user.isRBACAdmin ?? chunk77NUXO6A_cjs.isSuperAdmin({
250
+ const isRBACAdmin = user.isRBACAdmin ?? chunkJ7FMZK66_cjs.isSuperAdmin({
251
251
  groupId,
252
252
  groupName,
253
253
  isRBACAdmin: user.isRBACAdmin
@@ -260,7 +260,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
260
260
  };
261
261
  if (multiVendorEnabled) {
262
262
  ctx = await loadUserVendorContext(dataSource, id, user.activeVendorId);
263
- flags = chunk77NUXO6A_cjs.vendorPortalFlagsFromUser({
263
+ flags = chunkJ7FMZK66_cjs.vendorPortalFlagsFromUser({
264
264
  email: user.email,
265
265
  isRBACAdmin,
266
266
  groupName,
@@ -295,7 +295,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
295
295
  isVendorPortal: flags.isVendorPortal,
296
296
  isVendorOwner: flags.isVendorOwner
297
297
  };
298
- chunk77NUXO6A_cjs.logRbac("hydrateVendorSessionUser", {
298
+ chunkJ7FMZK66_cjs.logRbac("hydrateVendorSessionUser", {
299
299
  email: user.email,
300
300
  userId: id,
301
301
  groupName,
@@ -908,7 +908,7 @@ function repoHasVendorIdColumn(repo) {
908
908
  }
909
909
  chunkUSNT2KNT_cjs.__name(repoHasVendorIdColumn, "repoHasVendorIdColumn");
910
910
  function resourceUsesVendorScope(resource) {
911
- return resource === "vendors" || chunk77NUXO6A_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
911
+ return resource === "vendors" || chunkJ7FMZK66_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
912
912
  }
913
913
  chunkUSNT2KNT_cjs.__name(resourceUsesVendorScope, "resourceUsesVendorScope");
914
914
  function mergeWhereClause(where, extra) {
@@ -1398,7 +1398,7 @@ async function ensureVendorCustomersForOrder(dataSource, entityMap, vendorIds, c
1398
1398
  }
1399
1399
  let customerId = null;
1400
1400
  if (entityMap.customer) {
1401
- const ensured = await chunk3EOM4V2M_cjs.ensureCustomerRecord(dataSource, entityMap.customer, {
1401
+ const ensured = await chunk4U6DATGZ_cjs.ensureCustomerRecord(dataSource, entityMap.customer, {
1402
1402
  name,
1403
1403
  email,
1404
1404
  phone,
@@ -2454,13 +2454,46 @@ function discountCompare(cartValue, op, ruleValue) {
2454
2454
  }
2455
2455
  }
2456
2456
  chunkUSNT2KNT_cjs.__name(discountCompare, "discountCompare");
2457
- function discountEvaluateRule(rule, cartLines, cartTotal) {
2458
- if (rule.conditionType === "group") return discountEvaluateGroup(rule, cartLines, cartTotal);
2457
+ async function getExchangeRate(dataSource, entityMap, fromCurrency, toCurrency) {
2458
+ const from = (fromCurrency || "INR").trim().toUpperCase();
2459
+ const to = (toCurrency || "INR").trim().toUpperCase();
2460
+ if (from === to) return 1;
2461
+ if (entityMap["currency_exchange"]) {
2462
+ try {
2463
+ const exchangeRepo = dataSource.getRepository(entityMap["currency_exchange"]);
2464
+ const direct = await exchangeRepo.findOne({
2465
+ where: {
2466
+ fromCurrency: from,
2467
+ toCurrency: to
2468
+ }
2469
+ });
2470
+ if (direct && Number(direct.rate) > 0) {
2471
+ return Number(direct.rate);
2472
+ }
2473
+ const inverse = await exchangeRepo.findOne({
2474
+ where: {
2475
+ fromCurrency: to,
2476
+ toCurrency: from
2477
+ }
2478
+ });
2479
+ if (inverse && Number(inverse.rate) > 0) {
2480
+ return 1 / Number(inverse.rate);
2481
+ }
2482
+ } catch {
2483
+ }
2484
+ }
2485
+ return 1;
2486
+ }
2487
+ chunkUSNT2KNT_cjs.__name(getExchangeRate, "getExchangeRate");
2488
+ function discountEvaluateRule(rule, cartLines, cartTotal, exchangeRate = 1) {
2489
+ if (rule.conditionType === "group") return discountEvaluateGroup(rule, cartLines, cartTotal, exchangeRate);
2459
2490
  if (rule.type === "reward") return true;
2460
- const ruleValue = discountExtractValue(rule.value);
2491
+ const rawRuleValue = discountExtractValue(rule.value);
2461
2492
  switch (rule.type) {
2462
- case "minAmount":
2463
- return discountCompare(cartTotal, rule.comparisonOperator, ruleValue);
2493
+ case "minAmount": {
2494
+ const convertedValue = typeof rawRuleValue === "number" ? rawRuleValue * exchangeRate : !isNaN(Number(rawRuleValue)) ? Number(rawRuleValue) * exchangeRate : rawRuleValue;
2495
+ return discountCompare(cartTotal, rule.comparisonOperator, convertedValue);
2496
+ }
2464
2497
  case "quantity": {
2465
2498
  if (rule.subType === "productId" && rule.value?.productId) {
2466
2499
  const targetProductId = Number(rule.value.productId);
@@ -2469,11 +2502,11 @@ function discountEvaluateRule(rule, cartLines, cartTotal) {
2469
2502
  return discountCompare(productQty, rule.comparisonOperator, requiredQty);
2470
2503
  }
2471
2504
  const totalQty = cartLines.reduce((s, l) => s + l.quantity, 0);
2472
- return discountCompare(totalQty, rule.comparisonOperator, ruleValue);
2505
+ return discountCompare(totalQty, rule.comparisonOperator, rawRuleValue);
2473
2506
  }
2474
2507
  case "product":
2475
2508
  if (rule.subType === "productId") {
2476
- return cartLines.some((l) => discountCompare(l.productId, rule.comparisonOperator, ruleValue));
2509
+ return cartLines.some((l) => discountCompare(l.productId, rule.comparisonOperator, rawRuleValue));
2477
2510
  }
2478
2511
  return false;
2479
2512
  // These require external context (user session, payment method, time) —
@@ -2497,11 +2530,11 @@ function discountEvaluateRule(rule, cartLines, cartTotal) {
2497
2530
  }
2498
2531
  }
2499
2532
  chunkUSNT2KNT_cjs.__name(discountEvaluateRule, "discountEvaluateRule");
2500
- function discountEvaluateGroup(group, cartLines, cartTotal) {
2533
+ function discountEvaluateGroup(group, cartLines, cartTotal, exchangeRate = 1) {
2501
2534
  if (!group.children?.length) return true;
2502
2535
  const op = (group.conditionOperator ?? "and").toLowerCase();
2503
- if (op === "and") return group.children.every((child) => discountEvaluateRule(child, cartLines, cartTotal));
2504
- if (op === "or") return group.children.some((child) => discountEvaluateRule(child, cartLines, cartTotal));
2536
+ if (op === "and") return group.children.every((child) => discountEvaluateRule(child, cartLines, cartTotal, exchangeRate));
2537
+ if (op === "or") return group.children.some((child) => discountEvaluateRule(child, cartLines, cartTotal, exchangeRate));
2505
2538
  return true;
2506
2539
  }
2507
2540
  chunkUSNT2KNT_cjs.__name(discountEvaluateGroup, "discountEvaluateGroup");
@@ -2548,19 +2581,19 @@ function discountExtractBuyProductId(nodes) {
2548
2581
  return null;
2549
2582
  }
2550
2583
  chunkUSNT2KNT_cjs.__name(discountExtractBuyProductId, "discountExtractBuyProductId");
2551
- function discountBuildUniversalResult(discount, cartLines) {
2584
+ function discountBuildUniversalResult(discount, cartLines, effectiveValue) {
2552
2585
  return {
2553
2586
  rewardLines: cartLines.map((l) => ({
2554
2587
  productId: l.productId,
2555
2588
  quantity: l.quantity,
2556
- discountRate: Number(discount.value),
2589
+ discountRate: effectiveValue,
2557
2590
  discountType: discount.discountType
2558
2591
  })),
2559
2592
  conditionsMet: true
2560
2593
  };
2561
2594
  }
2562
2595
  chunkUSNT2KNT_cjs.__name(discountBuildUniversalResult, "discountBuildUniversalResult");
2563
- function evaluateDiscount(discount, cartLines) {
2596
+ function evaluateDiscount(discount, cartLines, exchangeRate = 1) {
2564
2597
  const empty = {
2565
2598
  rewardLines: [],
2566
2599
  conditionsMet: false
@@ -2584,16 +2617,17 @@ function evaluateDiscount(discount, cartLines) {
2584
2617
  reason: "discount usage limit reached"
2585
2618
  };
2586
2619
  }
2620
+ const effectiveValue = discount.discountType === "FLAT" ? Number(discount.value) * exchangeRate : Number(discount.value);
2587
2621
  const cartTotal = cartLines.reduce((s, l) => s + l.subtotal, 0);
2588
2622
  const tree = discountBuildTree(discount.rules ?? []);
2589
- if (tree.length === 0) return discountBuildUniversalResult(discount, cartLines);
2590
- const conditionsMet = tree.every((node) => discountEvaluateRule(node, cartLines, cartTotal));
2623
+ if (tree.length === 0) return discountBuildUniversalResult(discount, cartLines, effectiveValue);
2624
+ const conditionsMet = tree.every((node) => discountEvaluateRule(node, cartLines, cartTotal, exchangeRate));
2591
2625
  if (!conditionsMet) return {
2592
2626
  ...empty,
2593
2627
  reason: "conditions not met"
2594
2628
  };
2595
2629
  const rewardRules = discountCollectRewardRules(tree);
2596
- if (rewardRules.length === 0) return discountBuildUniversalResult(discount, cartLines);
2630
+ if (rewardRules.length === 0) return discountBuildUniversalResult(discount, cartLines, effectiveValue);
2597
2631
  const requiredBuyQty = discountExtractRequiredBuyQty(tree);
2598
2632
  const buyProductId = discountExtractBuyProductId(tree);
2599
2633
  let dealMultiplier = 1;
@@ -2611,7 +2645,7 @@ function evaluateDiscount(discount, cartLines) {
2611
2645
  rewardLines.push({
2612
2646
  productId: rewardProductId,
2613
2647
  quantity: dealMultiplier,
2614
- discountRate: Number(discount.value),
2648
+ discountRate: effectiveValue,
2615
2649
  discountType: discount.discountType
2616
2650
  });
2617
2651
  } else {
@@ -2620,7 +2654,7 @@ function evaluateDiscount(discount, cartLines) {
2620
2654
  rewardLines.push({
2621
2655
  productId: rewardProductId,
2622
2656
  quantity: rewardQty,
2623
- discountRate: Number(discount.value),
2657
+ discountRate: effectiveValue,
2624
2658
  discountType: discount.discountType
2625
2659
  });
2626
2660
  }
@@ -2631,8 +2665,9 @@ function evaluateDiscount(discount, cartLines) {
2631
2665
  };
2632
2666
  }
2633
2667
  chunkUSNT2KNT_cjs.__name(evaluateDiscount, "evaluateDiscount");
2634
- function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount) {
2668
+ function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount, exchangeRate = 1) {
2635
2669
  if (!evalResult.conditionsMet || evalResult.rewardLines.length === 0) return 0;
2670
+ const effectiveMaxDiscountAmount = maxDiscountAmount != null ? Number(maxDiscountAmount) * exchangeRate : null;
2636
2671
  let totalDiscountApplied = 0;
2637
2672
  for (const reward of evalResult.rewardLines) {
2638
2673
  const line = lines.find((l) => l.productId === reward.productId);
@@ -2649,8 +2684,8 @@ function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount) {
2649
2684
  line.subtotal = line.unitPrice * line.quantity;
2650
2685
  line.total = Math.max(0, line.subtotal - (line.discount ?? 0));
2651
2686
  }
2652
- if (maxDiscountAmount != null && totalDiscountApplied > maxDiscountAmount) {
2653
- const excess = totalDiscountApplied - maxDiscountAmount;
2687
+ if (effectiveMaxDiscountAmount != null && totalDiscountApplied > effectiveMaxDiscountAmount) {
2688
+ const excess = totalDiscountApplied - effectiveMaxDiscountAmount;
2654
2689
  for (let i = evalResult.rewardLines.length - 1; i >= 0; i--) {
2655
2690
  const reward = evalResult.rewardLines[i];
2656
2691
  const line = lines.find((l) => l.productId === reward.productId);
@@ -2660,7 +2695,7 @@ function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount) {
2660
2695
  line.total = Math.max(0, line.total + rollback);
2661
2696
  if (rollback > 0) break;
2662
2697
  }
2663
- totalDiscountApplied = maxDiscountAmount;
2698
+ totalDiscountApplied = effectiveMaxDiscountAmount;
2664
2699
  }
2665
2700
  return totalDiscountApplied;
2666
2701
  }
@@ -2766,7 +2801,9 @@ async function validateCoupon(dataSource, entityMap, couponCode, orderLines, cur
2766
2801
  unitPrice: l.unitPrice,
2767
2802
  subtotal: l.subtotal
2768
2803
  }));
2769
- const evalResult = evaluateDiscount(discountForEval, cartLines);
2804
+ const dCurrency = d.currency || "INR";
2805
+ const exchangeRate = await getExchangeRate(dataSource, entityMap, dCurrency, currency);
2806
+ const evalResult = evaluateDiscount(discountForEval, cartLines, exchangeRate);
2770
2807
  if (!evalResult.conditionsMet) {
2771
2808
  return {
2772
2809
  valid: false,
@@ -2776,7 +2813,7 @@ async function validateCoupon(dataSource, entityMap, couponCode, orderLines, cur
2776
2813
  const clonedLines = lines.map((l) => ({
2777
2814
  ...l
2778
2815
  }));
2779
- const calculatedDiscount = applyDiscountToOrderLines(clonedLines, evalResult, d.maxDiscountAmount);
2816
+ const calculatedDiscount = applyDiscountToOrderLines(clonedLines, evalResult, d.maxDiscountAmount, exchangeRate);
2780
2817
  const rewardProductIds = evalResult.rewardLines.map((r) => r.productId);
2781
2818
  return {
2782
2819
  valid: true,
@@ -3061,9 +3098,11 @@ async function calculateOrderTotalsFromLines(dataSource, entityMap, lineInputs,
3061
3098
  unitPrice: l.unitPrice,
3062
3099
  subtotal: l.subtotal
3063
3100
  }));
3064
- const evalResult = evaluateDiscount(discountForEval, cartLines);
3101
+ const dCurrency = discountRow.currency || "INR";
3102
+ const exchangeRate2 = await getExchangeRate(dataSource, entityMap, dCurrency, currency);
3103
+ const evalResult = evaluateDiscount(discountForEval, cartLines, exchangeRate2);
3065
3104
  if (evalResult.conditionsMet) {
3066
- const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount);
3105
+ const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount, exchangeRate2);
3067
3106
  orderDiscount += totalDiscountApplied;
3068
3107
  }
3069
3108
  }
@@ -3176,9 +3215,25 @@ async function calculateOrderTotals(dataSource, entityMap, itemsSummary, discoun
3176
3215
  unitPrice: l.unitPrice,
3177
3216
  subtotal: l.subtotal
3178
3217
  }));
3179
- const evalResult = evaluateDiscount(discountForEval, cartLines);
3218
+ const dCurrency = discountRow.currency || "INR";
3219
+ let storeCurrency = "INR";
3220
+ if (entityMap["configs"]) {
3221
+ try {
3222
+ const configRepo = dataSource.getRepository(entityMap["configs"]);
3223
+ const curr = await configRepo.findOne({
3224
+ where: {
3225
+ settings: "store",
3226
+ key: "currency"
3227
+ }
3228
+ });
3229
+ storeCurrency = curr?.value?.toUpperCase() ?? "INR";
3230
+ } catch {
3231
+ }
3232
+ }
3233
+ const exchangeRate = await getExchangeRate(dataSource, entityMap, dCurrency, storeCurrency);
3234
+ const evalResult = evaluateDiscount(discountForEval, cartLines, exchangeRate);
3180
3235
  if (evalResult.conditionsMet) {
3181
- const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount);
3236
+ const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount, exchangeRate);
3182
3237
  for (const line of lines) {
3183
3238
  if (!line.found || line.taxRate === 0) continue;
3184
3239
  const discountedAmount = line.subtotal - (line.discount ?? 0);
@@ -4348,7 +4403,7 @@ function createCrudHandler(dataSource, entityMap, options) {
4348
4403
  });
4349
4404
  }
4350
4405
  }
4351
- const savedCustomer = await chunk3EOM4V2M_cjs.ensureCustomerRecord(dataSource, entityMap["customer"], {
4406
+ const savedCustomer = await chunk4U6DATGZ_cjs.ensureCustomerRecord(dataSource, entityMap["customer"], {
4352
4407
  name,
4353
4408
  email,
4354
4409
  phone,
@@ -5127,11 +5182,18 @@ function createCrudHandler(dataSource, entityMap, options) {
5127
5182
  await recordDiscountUsage2(dataSource, entityMap, created.id, orderDiscountId, persistBody.contactId, discount);
5128
5183
  }
5129
5184
  const orderIdForNotify = created.id;
5130
- void import('./emit-order-notification-trigger-NR3VN6C6.cjs').then(({ fireOrderNotificationTrigger }) => {
5185
+ const initialPayStatus = String(persistBody.paymentStatus ?? "unpaid").toLowerCase();
5186
+ void import('./emit-order-notification-trigger-TNEZOYEE.cjs').then(({ fireOrderNotificationTrigger }) => {
5131
5187
  fireOrderNotificationTrigger("order_placed", orderIdForNotify, {
5132
5188
  dataSource,
5133
5189
  entityMap
5134
5190
  });
5191
+ if (initialPayStatus === "paid" || initialPayStatus === "captured") {
5192
+ fireOrderNotificationTrigger("payment_success", orderIdForNotify, {
5193
+ dataSource,
5194
+ entityMap
5195
+ });
5196
+ }
5135
5197
  });
5136
5198
  }
5137
5199
  } catch (err) {
@@ -6598,6 +6660,43 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6598
6660
  await retireSoftDeletedUniquesFromBody(repo, updatePayload);
6599
6661
  try {
6600
6662
  await repo.update(numericId, updatePayload);
6663
+ if (resource === "payments" && updatePayload.status) {
6664
+ const updatedPay = await repo.findOne({
6665
+ where: {
6666
+ id: numericId
6667
+ }
6668
+ });
6669
+ const pOrder = updatedPay?.orderId;
6670
+ const newPayStatus = String(updatePayload.status).toLowerCase();
6671
+ if (pOrder && Number.isFinite(pOrder)) {
6672
+ if (newPayStatus === "paid" || newPayStatus === "captured") {
6673
+ if (entityMap.orders) {
6674
+ await dataSource.getRepository(entityMap.orders).update(pOrder, {
6675
+ status: "confirmed"
6676
+ });
6677
+ }
6678
+ void import('./emit-order-notification-trigger-TNEZOYEE.cjs').then(({ fireOrderNotificationTrigger }) => {
6679
+ fireOrderNotificationTrigger("order_placed", pOrder, {
6680
+ dataSource,
6681
+ entityMap
6682
+ });
6683
+ fireOrderNotificationTrigger("payment_success", pOrder, {
6684
+ dataSource,
6685
+ entityMap
6686
+ });
6687
+ }).catch(() => {
6688
+ });
6689
+ } else if (newPayStatus === "failed") {
6690
+ void import('./emit-order-notification-trigger-TNEZOYEE.cjs').then(({ fireOrderNotificationTrigger }) => {
6691
+ fireOrderNotificationTrigger("payment_failed", pOrder, {
6692
+ dataSource,
6693
+ entityMap
6694
+ });
6695
+ }).catch(() => {
6696
+ });
6697
+ }
6698
+ }
6699
+ }
6601
6700
  } catch (err) {
6602
6701
  if (resource === "events" && isSlugUniqueViolation(err)) {
6603
6702
  return json({
@@ -7281,7 +7380,7 @@ function createInviteAcceptHandler(config) {
7281
7380
  }
7282
7381
  const { userId, email, vendorId } = validation.target;
7283
7382
  if (entityMap.contacts) {
7284
- await chunk3EOM4V2M_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
7383
+ await chunk4U6DATGZ_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
7285
7384
  }
7286
7385
  if (beforeActivate) await beforeActivate(email, userId);
7287
7386
  const hashedPassword = await hashPassword(password);
@@ -8374,7 +8473,7 @@ function createVendorDashboardHandler(config) {
8374
8473
  if (pe) return pe;
8375
8474
  }
8376
8475
  const user = await getSessionUser();
8377
- if (!user || !chunk77NUXO6A_cjs.isVendorPortalUser(user)) {
8476
+ if (!user || !chunkJ7FMZK66_cjs.isVendorPortalUser(user)) {
8378
8477
  return json({
8379
8478
  error: "Forbidden"
8380
8479
  }, {
@@ -9152,7 +9251,9 @@ function createFormSaveHandlers(config) {
9152
9251
  "description",
9153
9252
  "campaign",
9154
9253
  "slug",
9155
- "published"
9254
+ "published",
9255
+ "enableTurnstile",
9256
+ "enable_turnstile"
9156
9257
  ]) {
9157
9258
  if (body[key] !== void 0) formRow[key] = body[key];
9158
9259
  }
@@ -9743,11 +9844,11 @@ function createUsersApiHandlers(config) {
9743
9844
  adminAccess
9744
9845
  }));
9745
9846
  if (entityMap.contacts) {
9746
- await chunk3EOM4V2M_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, newUser.id, newUser.email);
9847
+ await chunk4U6DATGZ_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, newUser.id, newUser.email);
9747
9848
  }
9748
9849
  if (entityMap.customer) {
9749
9850
  const phone = typeof body.phone === "string" && body.phone.trim() ? body.phone.trim() : null;
9750
- await chunk3EOM4V2M_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
9851
+ await chunk4U6DATGZ_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
9751
9852
  id: newUser.id,
9752
9853
  name: String(newUser.name ?? body.name),
9753
9854
  email: String(newUser.email),
@@ -10837,7 +10938,7 @@ function createChatHandlers(config) {
10837
10938
  const notifyEmailAgent = await findLlmAgentByScope(dataSource, entityMap, LLM_AGENT_SCOPE_EMAIL_INTENT_CHATBOT, {
10838
10939
  enabledOnly: false
10839
10940
  });
10840
- const emailTool = chunkHXLC56ZK_cjs.resolveChatEmailToolSettings(llmSettings, {
10941
+ const emailTool = chunkYSYX4GUD_cjs.resolveChatEmailToolSettings(llmSettings, {
10841
10942
  chatbotValidationRules: agentRow?.validationRules ?? null,
10842
10943
  notifyAgent: notifyEmailAgent ? {
10843
10944
  systemInstruction: notifyEmailAgent.systemInstruction,
@@ -10847,7 +10948,7 @@ function createChatHandlers(config) {
10847
10948
  const emailPlugin2 = cms.getPlugin("email");
10848
10949
  const convLeadSent = conv.leadEmailSentAt;
10849
10950
  const chatAgentFn = llm.chatAgent?.bind(llm);
10850
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline check", {
10951
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline check", {
10851
10952
  conversationId,
10852
10953
  enabled: emailTool.enabled,
10853
10954
  intentCount: emailTool.intents.length,
@@ -10861,27 +10962,27 @@ function createChatHandlers(config) {
10861
10962
  mergedPromptIncludesNotify: Boolean(notifyEmailAgent?.systemInstruction?.trim())
10862
10963
  });
10863
10964
  if (!emailTool.enabled) {
10864
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10965
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10865
10966
  conversationId,
10866
10967
  reason: "email_tool_disabled"
10867
10968
  });
10868
10969
  } else if (emailTool.intents.length === 0) {
10869
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10970
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10870
10971
  conversationId,
10871
10972
  reason: "no_intents_configured"
10872
10973
  });
10873
10974
  } else if (!emailPlugin2) {
10874
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10975
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10875
10976
  conversationId,
10876
10977
  reason: "email_plugin_missing"
10877
10978
  });
10878
10979
  } else if (!chatAgentFn) {
10879
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10980
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10880
10981
  conversationId,
10881
10982
  reason: "llm_chat_agent_unavailable"
10882
10983
  });
10883
10984
  } else if (convLeadSent) {
10884
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10985
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10885
10986
  conversationId,
10886
10987
  reason: "lead_email_already_sent",
10887
10988
  leadEmailSentAt: convLeadSent
@@ -10894,7 +10995,7 @@ function createChatHandlers(config) {
10894
10995
  }
10895
10996
  });
10896
10997
  if (!contactRow) {
10897
- console.warn(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10998
+ console.warn(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10898
10999
  conversationId,
10899
11000
  reason: "contact_not_found",
10900
11001
  contactId
@@ -10902,7 +11003,7 @@ function createChatHandlers(config) {
10902
11003
  } else {
10903
11004
  const c = contactRow;
10904
11005
  try {
10905
- const intent = await chunkHXLC56ZK_cjs.detectChatLeadIntent({
11006
+ const intent = await chunkYSYX4GUD_cjs.detectChatLeadIntent({
10906
11007
  chatAgent: chatAgentFn
10907
11008
  }, {
10908
11009
  settings: emailTool,
@@ -10916,15 +11017,15 @@ function createChatHandlers(config) {
10916
11017
  model: agentRow?.model?.trim() || notifyEmailAgent?.model?.trim() || void 0
10917
11018
  });
10918
11019
  if (!intent.intent || !intent.emailTo) {
10919
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "no email sent", {
11020
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "no email sent", {
10920
11021
  conversationId,
10921
11022
  reason: intent.intent ? "missing_email_to" : "no_intent_match",
10922
11023
  intentLabel: intent.intentLabel,
10923
11024
  classifierReason: intent.reason
10924
11025
  });
10925
11026
  } else {
10926
- const intentRecipients = chunkHXLC56ZK_cjs.parseIntentRecipientEmails(intent.emailTo);
10927
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
11027
+ const intentRecipients = chunkYSYX4GUD_cjs.parseIntentRecipientEmails(intent.emailTo);
11028
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
10928
11029
  conversationId,
10929
11030
  intent: intent.intent,
10930
11031
  emailTo: intent.emailTo,
@@ -10934,7 +11035,7 @@ function createChatHandlers(config) {
10934
11035
  const emailSettings = await loadSettingsGroupMap(dataSource, entityMap, "email");
10935
11036
  const brandingSettings = await loadSettingsGroupMap(dataSource, entityMap, "branding");
10936
11037
  const companyDetails = chunkBXYZDMTZ_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings);
10937
- const leadResult = await chunkHXLC56ZK_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
11038
+ const leadResult = await chunkYSYX4GUD_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
10938
11039
  contactName: String(c.name ?? "").trim() || "Visitor",
10939
11040
  contactEmail: String(c.email ?? "").trim(),
10940
11041
  contactPhone: c.phone ?? null,
@@ -10942,7 +11043,7 @@ function createChatHandlers(config) {
10942
11043
  latestMessage: message,
10943
11044
  intentCode: intent.intent,
10944
11045
  intentReason: intent.intentLabel || intent.reason,
10945
- transcript: chunkHXLC56ZK_cjs.buildTranscriptForLeadEmail(history, message),
11046
+ transcript: chunkYSYX4GUD_cjs.buildTranscriptForLeadEmail(history, message),
10946
11047
  companyDetails,
10947
11048
  recipients: intentRecipients.length > 0 ? intentRecipients : void 0
10948
11049
  });
@@ -10950,13 +11051,13 @@ function createChatHandlers(config) {
10950
11051
  await convRepo().update(conversationId, {
10951
11052
  leadEmailSentAt: /* @__PURE__ */ new Date()
10952
11053
  });
10953
- console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
11054
+ console.info(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
10954
11055
  conversationId,
10955
11056
  sent: true,
10956
11057
  recipients: leadResult.recipients
10957
11058
  });
10958
11059
  } else {
10959
- console.warn(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
11060
+ console.warn(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
10960
11061
  conversationId,
10961
11062
  sent: false,
10962
11063
  error: leadResult.error ?? "unknown",
@@ -10965,7 +11066,7 @@ function createChatHandlers(config) {
10965
11066
  }
10966
11067
  }
10967
11068
  } catch (intentErr) {
10968
- console.warn(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline error", {
11069
+ console.warn(chunkYSYX4GUD_cjs.CHAT_EMAIL_LOG, "pipeline error", {
10969
11070
  conversationId,
10970
11071
  error: intentErr instanceof Error ? intentErr.message : String(intentErr)
10971
11072
  });
@@ -10982,7 +11083,7 @@ function createChatHandlers(config) {
10982
11083
  });
10983
11084
  if (agentRow && llm.chatAgent) {
10984
11085
  const fromAgent = llmAgentToChatAgentOptions(agentRow);
10985
- const systemPrompt = chunkHXLC56ZK_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
11086
+ const systemPrompt = chunkYSYX4GUD_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
10986
11087
  const res = await llm.chatAgent({
10987
11088
  ...fromAgent,
10988
11089
  systemPrompt: systemPrompt || void 0,
@@ -11003,7 +11104,7 @@ ${contextParts.join("\n\n")}` : "";
11003
11104
  agentRow.systemInstruction?.trim(),
11004
11105
  ragSystem
11005
11106
  ].filter(Boolean).join("\n\n");
11006
- systemContent = chunkHXLC56ZK_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
11107
+ systemContent = chunkYSYX4GUD_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
11007
11108
  } else {
11008
11109
  systemContent = ragSystem || defaultSystem;
11009
11110
  }
@@ -12258,7 +12359,7 @@ function createDeviceTokensHandlers(config) {
12258
12359
  const title = body.title?.trim() || "Test Push Notification";
12259
12360
  const msgBody = body.body?.trim() || "Firebase Push Notification setup is working!";
12260
12361
  if (!token || token === "validate" || token === "validate_only") {
12261
- const valRes = await chunkHXLC56ZK_cjs.validateFcmCredentials(dataSource, entityMap);
12362
+ const valRes = await chunkYSYX4GUD_cjs.validateFcmCredentials(dataSource, entityMap);
12262
12363
  if (!valRes.success) {
12263
12364
  return json({
12264
12365
  success: false,
@@ -12275,7 +12376,7 @@ function createDeviceTokensHandlers(config) {
12275
12376
  clientEmail: valRes.clientEmail
12276
12377
  });
12277
12378
  }
12278
- const res = await chunkHXLC56ZK_cjs.sendFcmPushNotification(dataSource, entityMap, {
12379
+ const res = await chunkYSYX4GUD_cjs.sendFcmPushNotification(dataSource, entityMap, {
12279
12380
  token,
12280
12381
  title,
12281
12382
  body: msgBody,
@@ -12829,7 +12930,7 @@ chunkUSNT2KNT_cjs.__name(findActiveRefundPolicyForVendor, "findActiveRefundPolic
12829
12930
  // src/api/admin-roles-handlers.ts
12830
12931
  function createAdminRolesHandlers(config) {
12831
12932
  const { dataSource, entityMap, json, getSessionUser } = config;
12832
- const baseEntities = chunk77NUXO6A_cjs.getPermissionableEntityKeys(entityMap);
12933
+ const baseEntities = chunkJ7FMZK66_cjs.getPermissionableEntityKeys(entityMap);
12833
12934
  const allowEntities = /* @__PURE__ */ new Set([
12834
12935
  ...baseEntities,
12835
12936
  "users"
@@ -12844,7 +12945,7 @@ function createAdminRolesHandlers(config) {
12844
12945
  }, {
12845
12946
  status: 401
12846
12947
  });
12847
- if (!chunk3EOM4V2M_cjs.canManageRoles(u) && !chunk77NUXO6A_cjs.canManageVendorRoles(u)) {
12948
+ if (!chunk4U6DATGZ_cjs.canManageRoles(u) && !chunkJ7FMZK66_cjs.canManageVendorRoles(u)) {
12848
12949
  return json({
12849
12950
  error: "Forbidden"
12850
12951
  }, {
@@ -12855,11 +12956,11 @@ function createAdminRolesHandlers(config) {
12855
12956
  }
12856
12957
  chunkUSNT2KNT_cjs.__name(gate, "gate");
12857
12958
  function isVendorRolesOnly(u) {
12858
- return chunk77NUXO6A_cjs.canManageVendorRoles(u) && !chunk3EOM4V2M_cjs.canManageRoles(u);
12959
+ return chunkJ7FMZK66_cjs.canManageVendorRoles(u) && !chunk4U6DATGZ_cjs.canManageRoles(u);
12859
12960
  }
12860
12961
  chunkUSNT2KNT_cjs.__name(isVendorRolesOnly, "isVendorRolesOnly");
12861
12962
  const vendorRoleEntities = [
12862
- ...chunk77NUXO6A_cjs.VENDOR_STORE_RBAC_ENTITIES,
12963
+ ...chunkJ7FMZK66_cjs.VENDOR_STORE_RBAC_ENTITIES,
12863
12964
  "dashboard",
12864
12965
  "settings"
12865
12966
  ].sort();
@@ -13016,7 +13117,7 @@ function createAdminRolesHandlers(config) {
13016
13117
  }, {
13017
13118
  status: 404
13018
13119
  });
13019
- if (chunk77NUXO6A_cjs.isSuperAdminGroupName(g.name) && !chunk77NUXO6A_cjs.isSuperAdminGroupName(name)) {
13120
+ if (chunkJ7FMZK66_cjs.isSuperAdminGroupName(g.name) && !chunkJ7FMZK66_cjs.isSuperAdminGroupName(name)) {
13020
13121
  return json({
13021
13122
  error: "Cannot rename the administrator group"
13022
13123
  }, {
@@ -13073,7 +13174,7 @@ function createAdminRolesHandlers(config) {
13073
13174
  }, {
13074
13175
  status: 404
13075
13176
  });
13076
- if (chunk77NUXO6A_cjs.isSuperAdminGroupName(g.name)) return json({
13177
+ if (chunkJ7FMZK66_cjs.isSuperAdminGroupName(g.name)) return json({
13077
13178
  error: "Cannot delete the administrator group"
13078
13179
  }, {
13079
13180
  status: 400
@@ -13270,7 +13371,7 @@ async function sendVendorOnboardEmails(input, deps) {
13270
13371
  getVendorEmails(deps)
13271
13372
  ]);
13272
13373
  const companyDetails = chunkBXYZDMTZ_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings);
13273
- const configuredNotify = chunkHXLC56ZK_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
13374
+ const configuredNotify = chunkYSYX4GUD_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
13274
13375
  const ownerEmail = input.ownerEmail?.trim() || "";
13275
13376
  const ownerEmailLower = ownerEmail.toLowerCase();
13276
13377
  const sendToOwner = input.sendToOwner !== false;
@@ -13304,7 +13405,7 @@ chunkUSNT2KNT_cjs.__name(sendVendorOnboardEmails, "sendVendorOnboardEmails");
13304
13405
 
13305
13406
  // src/lib/seed-vendor-roles.ts
13306
13407
  async function insertRolePermissions(exec, vendorRoleId, permissions) {
13307
- for (const entity of chunk77NUXO6A_cjs.VENDOR_RBAC_ENTITIES) {
13408
+ for (const entity of chunkJ7FMZK66_cjs.VENDOR_RBAC_ENTITIES) {
13308
13409
  const flags = permissions[entity];
13309
13410
  if (!flags) continue;
13310
13411
  await exec.query(`
@@ -13335,7 +13436,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
13335
13436
  for (const r of existing) {
13336
13437
  roleIdsByName2[r.name] = Number(r.id);
13337
13438
  if (r.isOwnerRole) ownerRoleId2 = Number(r.id);
13338
- if (r.name === chunk77NUXO6A_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
13439
+ if (r.name === chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
13339
13440
  }
13340
13441
  return {
13341
13442
  roleIdsByName: roleIdsByName2,
@@ -13346,7 +13447,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
13346
13447
  const roleIdsByName = {};
13347
13448
  let ownerRoleId = 0;
13348
13449
  let viewerRoleId = 0;
13349
- for (const def of chunk77NUXO6A_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
13450
+ for (const def of chunkJ7FMZK66_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
13350
13451
  const inserted = await exec.query(`
13351
13452
  INSERT INTO "vendor_roles"
13352
13453
  ("vendorId", "name", "description", "isSystem", "isOwnerRole")
@@ -13363,7 +13464,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
13363
13464
  if (!roleId) continue;
13364
13465
  roleIdsByName[def.name] = roleId;
13365
13466
  if (def.isOwnerRole) ownerRoleId = roleId;
13366
- if (def.name === chunk77NUXO6A_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
13467
+ if (def.name === chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
13367
13468
  await insertRolePermissions(exec, roleId, def.permissions);
13368
13469
  }
13369
13470
  return {
@@ -13393,7 +13494,7 @@ async function backfillVendorUserRoleIds(em, vendorId, seeded) {
13393
13494
  vendorId
13394
13495
  ]);
13395
13496
  }
13396
- const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunk77NUXO6A_cjs.VENDOR_VIEWER_ROLE_NAME];
13497
+ const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME];
13397
13498
  if (viewerId) {
13398
13499
  await em.query(`
13399
13500
  UPDATE "vendor_users"
@@ -13419,7 +13520,7 @@ async function getDefaultStaffRoleIdForVendor(em, vendorId) {
13419
13520
  LIMIT 1
13420
13521
  `, [
13421
13522
  vendorId,
13422
- chunk77NUXO6A_cjs.VENDOR_VIEWER_ROLE_NAME
13523
+ chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME
13423
13524
  ]);
13424
13525
  const id = rows[0]?.id;
13425
13526
  return id != null ? Number(id) : null;
@@ -13780,7 +13881,7 @@ function createVendorOnboardHandlers(config) {
13780
13881
  }, {
13781
13882
  status: 401
13782
13883
  });
13783
- if (!chunk77NUXO6A_cjs.isPlatformAdministrator(u)) return json({
13884
+ if (!chunkJ7FMZK66_cjs.isPlatformAdministrator(u)) return json({
13784
13885
  error: "Forbidden",
13785
13886
  reason: "admin_only"
13786
13887
  }, {
@@ -13790,7 +13891,7 @@ function createVendorOnboardHandlers(config) {
13790
13891
  }
13791
13892
  chunkUSNT2KNT_cjs.__name(gateAdmin, "gateAdmin");
13792
13893
  async function resolveActiveVendorId(u) {
13793
- const scope = chunk77NUXO6A_cjs.resolveVendorScopeFromSessionUser(u);
13894
+ const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u);
13794
13895
  const candidates = [];
13795
13896
  if (scope.type === "vendor") candidates.push(scope.vendorId);
13796
13897
  if (scope.type === "all" || scope.type === "vendor") {
@@ -13844,7 +13945,7 @@ function createVendorOnboardHandlers(config) {
13844
13945
  }, {
13845
13946
  status: 401
13846
13947
  });
13847
- if (!chunk77NUXO6A_cjs.isVendorPortalUser(u) && !chunk77NUXO6A_cjs.isPlatformAdministrator(u)) {
13948
+ if (!chunkJ7FMZK66_cjs.isVendorPortalUser(u) && !chunkJ7FMZK66_cjs.isPlatformAdministrator(u)) {
13848
13949
  return json({
13849
13950
  error: "Forbidden"
13850
13951
  }, {
@@ -13872,7 +13973,7 @@ function createVendorOnboardHandlers(config) {
13872
13973
  }, {
13873
13974
  status: 401
13874
13975
  });
13875
- if (!chunk77NUXO6A_cjs.canManageVendorTeam(u)) return json({
13976
+ if (!chunkJ7FMZK66_cjs.canManageVendorTeam(u)) return json({
13876
13977
  error: "Forbidden"
13877
13978
  }, {
13878
13979
  status: 403
@@ -14090,7 +14191,7 @@ function createVendorOnboardHandlers(config) {
14090
14191
  await chunkOY2YTBMP_cjs.retireSoftDeletedUniqueValue(vendorRepo, "slug", slug);
14091
14192
  let ownerGroup = await groupRepo.findOne({
14092
14193
  where: {
14093
- name: chunk77NUXO6A_cjs.VENDOR_GROUP_NAME,
14194
+ name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
14094
14195
  deleted: false
14095
14196
  }
14096
14197
  });
@@ -14105,12 +14206,12 @@ function createVendorOnboardHandlers(config) {
14105
14206
  if (!ownerGroup) {
14106
14207
  try {
14107
14208
  await groupRepo.save(groupRepo.create({
14108
- name: chunk77NUXO6A_cjs.VENDOR_GROUP_NAME,
14209
+ name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
14109
14210
  deleted: false
14110
14211
  }));
14111
14212
  ownerGroup = await groupRepo.findOne({
14112
14213
  where: {
14113
- name: chunk77NUXO6A_cjs.VENDOR_GROUP_NAME,
14214
+ name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
14114
14215
  deleted: false
14115
14216
  }
14116
14217
  });
@@ -14227,7 +14328,7 @@ function createVendorOnboardHandlers(config) {
14227
14328
  }
14228
14329
  if (entityMap.customer) {
14229
14330
  try {
14230
- await chunk3EOM4V2M_cjs.ensureCustomerForUser(em, entityMap.customer, {
14331
+ await chunk4U6DATGZ_cjs.ensureCustomerForUser(em, entityMap.customer, {
14231
14332
  id: newUser.id,
14232
14333
  name: userName,
14233
14334
  email: userEmail,
@@ -14727,7 +14828,7 @@ function createVendorOnboardHandlers(config) {
14727
14828
  if (!groupId) {
14728
14829
  const g = await groupRepo.findOne({
14729
14830
  where: {
14730
- name: chunk77NUXO6A_cjs.VENDOR_GROUP_NAME,
14831
+ name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
14731
14832
  deleted: false
14732
14833
  }
14733
14834
  }) ?? await groupRepo.findOne({
@@ -14827,7 +14928,7 @@ function createVendorOnboardHandlers(config) {
14827
14928
  }
14828
14929
  if (entityMap.customer) {
14829
14930
  try {
14830
- await chunk3EOM4V2M_cjs.ensureCustomerForUser(em, entityMap.customer, {
14931
+ await chunk4U6DATGZ_cjs.ensureCustomerForUser(em, entityMap.customer, {
14831
14932
  id: newUser.id,
14832
14933
  name: userName,
14833
14934
  email: userEmail,
@@ -15364,10 +15465,10 @@ chunkUSNT2KNT_cjs.__name(createVendorOnboardHandlers, "createVendorOnboardHandle
15364
15465
  function createVendorRolesHandlers(config) {
15365
15466
  const { dataSource, entityMap, json, getSessionUser } = config;
15366
15467
  const vendorRoleEntities = [
15367
- ...chunk77NUXO6A_cjs.VENDOR_RBAC_ENTITIES
15468
+ ...chunkJ7FMZK66_cjs.VENDOR_RBAC_ENTITIES
15368
15469
  ].sort();
15369
15470
  async function resolveActiveVendorId(u) {
15370
- const scope = chunk77NUXO6A_cjs.resolveVendorScopeFromSessionUser(u);
15471
+ const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u);
15371
15472
  if (scope.type === "vendor") return scope.vendorId;
15372
15473
  if (scope.type === "all") {
15373
15474
  const id = u.activeVendorId ?? u.vendorIds?.[0];
@@ -15383,7 +15484,7 @@ function createVendorRolesHandlers(config) {
15383
15484
  }, {
15384
15485
  status: 401
15385
15486
  });
15386
- if (!chunk77NUXO6A_cjs.canManageVendorRoles(u)) return json({
15487
+ if (!chunkJ7FMZK66_cjs.canManageVendorRoles(u)) return json({
15387
15488
  error: "Forbidden"
15388
15489
  }, {
15389
15490
  status: 403
@@ -17048,6 +17149,7 @@ exports.Form = class Form {
17048
17149
  campaign;
17049
17150
  slug;
17050
17151
  published;
17152
+ enableTurnstile;
17051
17153
  createdAt;
17052
17154
  updatedAt;
17053
17155
  deletedAt;
@@ -17090,6 +17192,14 @@ _ts_decorate14([
17090
17192
  }),
17091
17193
  _ts_metadata14("design:type", Boolean)
17092
17194
  ], exports.Form.prototype, "published", void 0);
17195
+ _ts_decorate14([
17196
+ typeorm.Column("boolean", {
17197
+ default: false,
17198
+ name: "enable_turnstile",
17199
+ nullable: true
17200
+ }),
17201
+ _ts_metadata14("design:type", Boolean)
17202
+ ], exports.Form.prototype, "enableTurnstile", void 0);
17093
17203
  _ts_decorate14([
17094
17204
  typeorm.Column({
17095
17205
  type: "timestamp",
@@ -27839,16 +27949,16 @@ function whatsappPlugin(config = {}) {
27839
27949
  db = await getWhatsAppSettings?.() ?? {};
27840
27950
  } catch {
27841
27951
  }
27842
- if (!chunkHXLC56ZK_cjs.isWhatsAppPluginEnabled(db)) {
27952
+ if (!chunkYSYX4GUD_cjs.isWhatsAppPluginEnabled(db)) {
27843
27953
  context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
27844
27954
  return null;
27845
27955
  }
27846
- const merged = chunkHXLC56ZK_cjs.mergeWhatsAppConfigLayers(env, db, staticRest);
27847
- if (!getWhatsAppSettings && !chunkHXLC56ZK_cjs.whatsAppConfigured(merged)) {
27956
+ const merged = chunkYSYX4GUD_cjs.mergeWhatsAppConfigLayers(env, db, staticRest);
27957
+ if (!getWhatsAppSettings && !chunkYSYX4GUD_cjs.whatsAppConfigured(merged)) {
27848
27958
  context.logger.warn("WhatsApp plugin skipped: set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID, or pass getWhatsAppSettings");
27849
27959
  return null;
27850
27960
  }
27851
- const svc = new chunkHXLC56ZK_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
27961
+ const svc = new chunkYSYX4GUD_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
27852
27962
  return {
27853
27963
  send: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((opts) => svc.send(opts), "send")
27854
27964
  };
@@ -27925,7 +28035,7 @@ function registerMessagingQueueProcessors(cms, entityMap) {
27925
28035
  getDataSource: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => cms.dataSource, "getDataSource"),
27926
28036
  entityMap
27927
28037
  });
27928
- chunkHXLC56ZK_cjs.registerWhatsAppQueueProcessor(cms);
28038
+ chunkYSYX4GUD_cjs.registerWhatsAppQueueProcessor(cms);
27929
28039
  }
27930
28040
  chunkUSNT2KNT_cjs.__name(registerMessagingQueueProcessors, "registerMessagingQueueProcessors");
27931
28041
  async function ensureMessagingPluginsOnCms(base, options) {
@@ -27954,7 +28064,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
27954
28064
  }
27955
28065
  if (!cms.getPlugin("email")) {
27956
28066
  try {
27957
- const instance = await chunkHXLC56ZK_cjs.emailPlugin({
28067
+ const instance = await chunkYSYX4GUD_cjs.emailPlugin({
27958
28068
  type: "SMTP",
27959
28069
  from: config.SMTP_FROM ?? "no-reply@localhost",
27960
28070
  to: config.SMTP_TO ?? ""
@@ -27995,7 +28105,7 @@ function messagingPlugins(options) {
27995
28105
  const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
27996
28106
  return [
27997
28107
  queuePlugin(),
27998
- chunkHXLC56ZK_cjs.emailPlugin({
28108
+ chunkYSYX4GUD_cjs.emailPlugin({
27999
28109
  type: "SMTP",
28000
28110
  from: config.SMTP_FROM ?? "no-reply@localhost",
28001
28111
  to: config.SMTP_TO ?? ""
@@ -28129,7 +28239,7 @@ function createCmsApiHandler(config) {
28129
28239
  } : void 0;
28130
28240
  const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
28131
28241
  if (getCms) {
28132
- chunkHXLC56ZK_cjs.initWhatsappTriggerDispatcher({
28242
+ chunkYSYX4GUD_cjs.initWhatsappTriggerDispatcher({
28133
28243
  dataSource,
28134
28244
  entityMap,
28135
28245
  getCms
@@ -28142,7 +28252,7 @@ function createCmsApiHandler(config) {
28142
28252
  ] : baseCrudResources;
28143
28253
  const requireEntityPermissionEffective = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async (_req, entity, action) => {
28144
28254
  if (!resolveSessionUser) {
28145
- chunk77NUXO6A_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
28255
+ chunkJ7FMZK66_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
28146
28256
  entity,
28147
28257
  action,
28148
28258
  hint: "Pass getSessionUser: auth.getAuthenticatedUser from createCmsAuthBundle()"
@@ -28152,7 +28262,7 @@ function createCmsApiHandler(config) {
28152
28262
  const raw = await resolveSessionUser();
28153
28263
  const u = await hydrateVendorSessionUser(dataSource, raw);
28154
28264
  if (!u?.email) {
28155
- chunk77NUXO6A_cjs.logRbac("requireEntityPermission: no session user", {
28265
+ chunkJ7FMZK66_cjs.logRbac("requireEntityPermission: no session user", {
28156
28266
  entity,
28157
28267
  action
28158
28268
  });
@@ -28162,13 +28272,13 @@ function createCmsApiHandler(config) {
28162
28272
  status: 401
28163
28273
  });
28164
28274
  }
28165
- const allowed = chunk3EOM4V2M_cjs.sessionHasEntityAccess(u, entity, action);
28166
- await chunk77NUXO6A_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
28275
+ const allowed = chunk4U6DATGZ_cjs.sessionHasEntityAccess(u, entity, action);
28276
+ await chunkJ7FMZK66_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
28167
28277
  allowed,
28168
28278
  resolvePath: "hydrated_session"
28169
28279
  });
28170
28280
  if (allowed) return null;
28171
- const { reason } = chunk77NUXO6A_cjs.explainSessionEntityAccess(u, entity, action);
28281
+ const { reason } = chunkJ7FMZK66_cjs.explainSessionEntityAccess(u, entity, action);
28172
28282
  return config.json({
28173
28283
  error: "Forbidden",
28174
28284
  entity,
@@ -28179,7 +28289,7 @@ function createCmsApiHandler(config) {
28179
28289
  });
28180
28290
  }
28181
28291
  if (userRequireEntityPermission) {
28182
- chunk77NUXO6A_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
28292
+ chunkJ7FMZK66_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
28183
28293
  entity,
28184
28294
  action
28185
28295
  });
@@ -28266,10 +28376,10 @@ function createCmsApiHandler(config) {
28266
28376
  getVendorScope: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
28267
28377
  const multiVendorEnabled = await checkMultiVendorEnabled(dataSource);
28268
28378
  if (!multiVendorEnabled) {
28269
- return chunk77NUXO6A_cjs.resolveDisabledMultiVendorScope(dataSource);
28379
+ return chunkJ7FMZK66_cjs.resolveDisabledMultiVendorScope(dataSource);
28270
28380
  }
28271
28381
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
28272
- return chunk77NUXO6A_cjs.resolveVendorScopeFromSessionUser(u ?? null);
28382
+ return chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
28273
28383
  }, "getVendorScope"),
28274
28384
  getHydratedSessionUser: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
28275
28385
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
@@ -29227,7 +29337,7 @@ function createCmsApiHandler(config) {
29227
29337
  }
29228
29338
  if (path2[0] === "settings" && path2.length === 2 && settingsHandlers) {
29229
29339
  const group = path2[1];
29230
- const isPublic = group === "multi_vendor" || settingsConfig?.publicGetGroups?.includes(group);
29340
+ const isPublic = group === "multi_vendor" || group === "turnstile" || group === "auth_providers" || settingsConfig?.publicGetGroups?.includes(group);
29231
29341
  if (m === "GET") {
29232
29342
  if (!isPublic) {
29233
29343
  const a = await config.requireAuth(req);
@@ -29603,7 +29713,7 @@ function createCmsApiHandler(config) {
29603
29713
  let vendorId = null;
29604
29714
  if (resolveSessionUser) {
29605
29715
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
29606
- const scope = chunk77NUXO6A_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29716
+ const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29607
29717
  if (scope.type === "vendor") vendorId = scope.vendorId;
29608
29718
  }
29609
29719
  const result = await validateCoupon(dataSource, entityMap, couponCode, orderLinesNorm, currency, contactId, isAutomatic, discountId ?? void 0, vendorId);
@@ -29686,7 +29796,7 @@ function createCmsApiHandler(config) {
29686
29796
  let vendorId = null;
29687
29797
  if (resolveSessionUser) {
29688
29798
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
29689
- const scope = chunk77NUXO6A_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29799
+ const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29690
29800
  if (scope.type === "vendor") vendorId = scope.vendorId;
29691
29801
  }
29692
29802
  const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
@@ -29885,14 +29995,21 @@ function createCmsApiHandler(config) {
29885
29995
  body = {};
29886
29996
  }
29887
29997
  const triggerKey = String(body.triggerKey ?? "order_placed").trim() || "order_placed";
29888
- if (triggerKey !== "order_placed" && triggerKey !== "order_cancelled") {
29998
+ const validTriggers = [
29999
+ "order_placed",
30000
+ "order_cancelled",
30001
+ "payment_success",
30002
+ "payment_failed",
30003
+ "payment_refund_initiated"
30004
+ ];
30005
+ if (!validTriggers.includes(triggerKey)) {
29889
30006
  return config.json({
29890
- error: "Invalid triggerKey; use order_placed or order_cancelled"
30007
+ error: `Invalid triggerKey; use one of: ${validTriggers.join(", ")}`
29891
30008
  }, {
29892
30009
  status: 400
29893
30010
  });
29894
30011
  }
29895
- const { resendOrderNotification } = await import('./order-notification-dispatcher-2FCZFZUD.cjs');
30012
+ const { resendOrderNotification } = await import('./order-notification-dispatcher-KJVGLK5E.cjs');
29896
30013
  const result = await resendOrderNotification(triggerKey, orderId, {
29897
30014
  dataSource,
29898
30015
  entityMap,
@@ -29914,11 +30031,9 @@ function createCmsApiHandler(config) {
29914
30031
  if (path2[0] === "orders" && path2.length === 3 && path2[2] === "cancel" && m === "POST") {
29915
30032
  const a = await config.requireAuth(req);
29916
30033
  if (a) return a;
29917
- const pe = await requireEntityPermissionEffective(req, "orders", "update");
29918
- if (pe) return pe;
29919
- const orderId = Number(path2[1]);
29920
- if (!Number.isFinite(orderId)) return config.json({
29921
- error: "Invalid id"
30034
+ const orderId = parseInt(path2[1], 10);
30035
+ if (Number.isNaN(orderId)) return config.json({
30036
+ error: "Invalid order ID"
29922
30037
  }, {
29923
30038
  status: 400
29924
30039
  });
@@ -29935,9 +30050,10 @@ function createCmsApiHandler(config) {
29935
30050
  status: 404
29936
30051
  });
29937
30052
  const o = order;
29938
- if (o.status !== "confirmed" && o.status !== "completed") {
30053
+ const currentStatus = (o.status || "").toLowerCase();
30054
+ if (currentStatus === "cancelled") {
29939
30055
  return config.json({
29940
- error: "Only confirmed or completed orders can be cancelled"
30056
+ error: "Order is already cancelled"
29941
30057
  }, {
29942
30058
  status: 400
29943
30059
  });
@@ -29960,7 +30076,7 @@ function createCmsApiHandler(config) {
29960
30076
  }
29961
30077
  });
29962
30078
  if (payment) {
29963
- paymentStatus = String(payment.status ?? "unpaid");
30079
+ paymentStatus = String(payment.status ?? "unpaid").toLowerCase();
29964
30080
  paymentId = Number(payment.id);
29965
30081
  }
29966
30082
  }
@@ -29992,13 +30108,26 @@ function createCmsApiHandler(config) {
29992
30108
  status: "cancelled"
29993
30109
  });
29994
30110
  const fireOrderCancelledNotification = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((refundAmount) => {
29995
- void import('./emit-order-notification-trigger-NR3VN6C6.cjs').then(({ fireOrderNotificationTrigger }) => {
30111
+ void import('./emit-order-notification-trigger-TNEZOYEE.cjs').then(({ fireOrderNotificationTrigger }) => {
29996
30112
  fireOrderNotificationTrigger("order_cancelled", orderId, {
29997
30113
  dataSource,
29998
30114
  entityMap
29999
30115
  }, refundAmount != null && refundAmount > 0 ? {
30000
30116
  refundAmount
30001
30117
  } : void 0);
30118
+ if (paymentStatus === "paid" || paymentStatus === "captured") {
30119
+ fireOrderNotificationTrigger("payment_refund_initiated", orderId, {
30120
+ dataSource,
30121
+ entityMap
30122
+ }, refundAmount != null && refundAmount > 0 ? {
30123
+ refundAmount
30124
+ } : void 0);
30125
+ } else {
30126
+ fireOrderNotificationTrigger("payment_failed", orderId, {
30127
+ dataSource,
30128
+ entityMap
30129
+ });
30130
+ }
30002
30131
  });
30003
30132
  }, "fireOrderCancelledNotification");
30004
30133
  if (paymentStatus === "paid" && entityMap.payments && paymentId) {
@@ -30324,7 +30453,7 @@ function createCmsApiHandler(config) {
30324
30453
  if (resolveSessionUser) {
30325
30454
  const raw = await resolveSessionUser();
30326
30455
  const u = await hydrateVendorSessionUser(dataSource, raw);
30327
- const scope = chunk77NUXO6A_cjs.resolveVendorScopeFromSessionUser(u ?? null);
30456
+ const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
30328
30457
  if (scope.type === "vendor") {
30329
30458
  scopedVendorIds = scope.vendorIds;
30330
30459
  }
@@ -31024,12 +31153,23 @@ function createStorefrontApiHandler(config) {
31024
31153
  const otpFlags = config.otpFlags;
31025
31154
  const otpPepper = config.otpPepper;
31026
31155
  const defaultPhoneCc = config.defaultPhoneCountryCode;
31027
- function fireOrderPlacedNotification(orderId) {
31028
- void import('./emit-order-notification-trigger-NR3VN6C6.cjs').then(({ fireOrderNotificationTrigger }) => {
31156
+ function fireOrderPlacedNotification(orderId, isPaid) {
31157
+ void import('./emit-order-notification-trigger-TNEZOYEE.cjs').then(({ fireOrderNotificationTrigger }) => {
31029
31158
  fireOrderNotificationTrigger("order_placed", orderId, {
31030
31159
  dataSource,
31031
31160
  entityMap
31032
31161
  });
31162
+ if (isPaid) {
31163
+ fireOrderNotificationTrigger("payment_success", orderId, {
31164
+ dataSource,
31165
+ entityMap
31166
+ });
31167
+ } else {
31168
+ fireOrderNotificationTrigger("payment_failed", orderId, {
31169
+ dataSource,
31170
+ entityMap
31171
+ });
31172
+ }
31033
31173
  }).catch((err) => console.error("[notification-triggers] import failed", err));
31034
31174
  }
31035
31175
  chunkUSNT2KNT_cjs.__name(fireOrderPlacedNotification, "fireOrderPlacedNotification");
@@ -32872,10 +33012,10 @@ function createStorefrontApiHandler(config) {
32872
33012
  adminAccess: false
32873
33013
  }));
32874
33014
  const userId = newUser.id;
32875
- await chunk3EOM4V2M_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
33015
+ await chunk4U6DATGZ_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
32876
33016
  if (entityMap.customer) {
32877
33017
  const phone = typeof b.phone === "string" && b.phone.trim() ? String(b.phone).trim() : null;
32878
- await chunk3EOM4V2M_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
33018
+ await chunk4U6DATGZ_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
32879
33019
  id: userId,
32880
33020
  name,
32881
33021
  email,
@@ -33914,6 +34054,20 @@ function createStorefrontApiHandler(config) {
33914
34054
  }
33915
34055
  } catch {
33916
34056
  }
34057
+ try {
34058
+ void import('./emit-order-notification-trigger-TNEZOYEE.cjs').then(({ fireOrderNotificationTrigger }) => {
34059
+ fireOrderNotificationTrigger("order_cancelled", orderId, {
34060
+ dataSource,
34061
+ entityMap
34062
+ });
34063
+ fireOrderNotificationTrigger("payment_failed", orderId, {
34064
+ dataSource,
34065
+ entityMap
34066
+ });
34067
+ }).catch(() => {
34068
+ });
34069
+ } catch {
34070
+ }
33917
34071
  }
33918
34072
  return json({
33919
34073
  ok: true,