@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
@@ -137,7 +137,15 @@ var VENDOR_STORE_RBAC_ENTITIES = /* @__PURE__ */ new Set([
137
137
  ...VENDOR_SCOPED_STORE_ENTITIES,
138
138
  "order_discounts",
139
139
  "order_addresses",
140
- "event_products"
140
+ "event_products",
141
+ "attendees",
142
+ "order-attendees",
143
+ "order_attendees",
144
+ "scan",
145
+ "verify-attendee-qr",
146
+ "verify_attendee_qr",
147
+ "forms",
148
+ "cms-forms"
141
149
  ]);
142
150
  var VENDOR_GROUP_NAME = "Vendor";
143
151
  var VENDOR_OWNER_GROUP_NAME = VENDOR_GROUP_NAME;
@@ -606,7 +614,7 @@ async function logEntityAccessDecision(dataSource, context, user, entity, action
606
614
  const id = Number(user.id);
607
615
  if (Number.isFinite(id)) {
608
616
  try {
609
- const { loadDbPermissionsForUser } = await import('./rbac-debug-db-6PWTLBEL.cjs');
617
+ const { loadDbPermissionsForUser } = await import('./rbac-debug-db-JKK2MCWF.cjs');
610
618
  dbPermissions = await loadDbPermissionsForUser(dataSource, id);
611
619
  } catch (e) {
612
620
  dbPermissions = {
@@ -1,15 +1,15 @@
1
1
  import { JOB_RUNNER_QUEUE } from './chunk-GO7PPYNU.js';
2
2
  import { validateInventoryForConfirmedOrderLines, orderStatusHoldsStock, reconcileOrderInventoryBetweenSnapshots, orderInventorySnapshotFromRow, validateInventoryForOrderBecomingConfirmed } from './chunk-3K5AIEIZ.js';
3
- import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool, validateFcmCredentials, sendFcmPushNotification, parseEmailRecipientsFromConfig, isWhatsAppPluginEnabled, mergeWhatsAppConfigLayers, whatsAppConfigured, WhatsAppService, registerWhatsAppQueueProcessor, emailPlugin, initWhatsappTriggerDispatcher } from './chunk-HYW3MUXT.js';
3
+ import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool, validateFcmCredentials, sendFcmPushNotification, parseEmailRecipientsFromConfig, isWhatsAppPluginEnabled, mergeWhatsAppConfigLayers, whatsAppConfigured, WhatsAppService, registerWhatsAppQueueProcessor, emailPlugin, initWhatsappTriggerDispatcher } from './chunk-URN7GS23.js';
4
4
  import { inviteStatusForActivation } from './chunk-JXF23MPG.js';
5
5
  import { queueEmail, queueVendorOnboardEmails, registerEmailQueueProcessor } from './chunk-L3525VXI.js';
6
6
  import { mergeEmailLayoutCompanyDetails, unwrapErpReadData, mapErpPayloadToFulfillment, extractChildOrderRefsFromSalePayload, mapErpPayloadToInvoiceNumber, streamOrderInvoicePdf } from './chunk-2KUCQVAQ.js';
7
7
  import { isErpIntegrationEnabled } from './chunk-JC6DLWTE.js';
8
8
  import { getSmsTemplateDefault, SMS_MESSAGE_TEMPLATE_DEFAULTS } from './chunk-MQBT33IV.js';
9
9
  import { EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS, EVENT_ORDER_TEMPLATE_KEY, EVENT_ORDER_TEMPLATE_VARIABLES } from './chunk-AYERBA7I.js';
10
- import { ensureCustomerRecord, linkUnclaimedContactToUser, ensureCustomerForUser, canManageRoles, sessionHasEntityAccess } from './chunk-RK5ETF2I.js';
10
+ import { ensureCustomerRecord, linkUnclaimedContactToUser, ensureCustomerForUser, canManageRoles, sessionHasEntityAccess } from './chunk-NR44CK5E.js';
11
11
  import { retireSoftDeletedUniqueValue, activeUniqueValueExists } from './chunk-DBPSJYLZ.js';
12
- import { permissionRowsToRecord, logRbac, isSuperAdmin, vendorPortalFlagsFromUser, VENDOR_SCOPED_STORE_ENTITIES, isVendorPortalUser, getPermissionableEntityKeys, VENDOR_STORE_RBAC_ENTITIES, isSuperAdminGroupName, VENDOR_RBAC_ENTITIES, VENDOR_VIEWER_ROLE_NAME, DEFAULT_VENDOR_ROLE_DEFS, VENDOR_GROUP_NAME, resolveVendorScopeFromSessionUser, canManageVendorRoles, isPlatformAdministrator, canManageVendorTeam, resolveDisabledMultiVendorScope, logEntityAccessDecision, explainSessionEntityAccess } from './chunk-JIWUVQ6B.js';
12
+ import { permissionRowsToRecord, logRbac, isSuperAdmin, vendorPortalFlagsFromUser, VENDOR_SCOPED_STORE_ENTITIES, isVendorPortalUser, getPermissionableEntityKeys, VENDOR_STORE_RBAC_ENTITIES, isSuperAdminGroupName, VENDOR_RBAC_ENTITIES, VENDOR_VIEWER_ROLE_NAME, DEFAULT_VENDOR_ROLE_DEFS, VENDOR_GROUP_NAME, resolveVendorScopeFromSessionUser, canManageVendorRoles, isPlatformAdministrator, canManageVendorTeam, resolveDisabledMultiVendorScope, logEntityAccessDecision, explainSessionEntityAccess } from './chunk-MVHDC3XF.js';
13
13
  import { queueErp } from './chunk-SYBOCAWB.js';
14
14
  import { __name } from './chunk-SHUYVCID.js';
15
15
  import { PrimaryGeneratedColumn, Column, Entity, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn, Unique, OneToMany, Index, ManyToMany, JoinTable, In, ILike, Between, MoreThanOrEqual, LessThanOrEqual, Not, MoreThan, IsNull } from 'typeorm';
@@ -2444,13 +2444,46 @@ function discountCompare(cartValue, op, ruleValue) {
2444
2444
  }
2445
2445
  }
2446
2446
  __name(discountCompare, "discountCompare");
2447
- function discountEvaluateRule(rule, cartLines, cartTotal) {
2448
- if (rule.conditionType === "group") return discountEvaluateGroup(rule, cartLines, cartTotal);
2447
+ async function getExchangeRate(dataSource, entityMap, fromCurrency, toCurrency) {
2448
+ const from = (fromCurrency || "INR").trim().toUpperCase();
2449
+ const to = (toCurrency || "INR").trim().toUpperCase();
2450
+ if (from === to) return 1;
2451
+ if (entityMap["currency_exchange"]) {
2452
+ try {
2453
+ const exchangeRepo = dataSource.getRepository(entityMap["currency_exchange"]);
2454
+ const direct = await exchangeRepo.findOne({
2455
+ where: {
2456
+ fromCurrency: from,
2457
+ toCurrency: to
2458
+ }
2459
+ });
2460
+ if (direct && Number(direct.rate) > 0) {
2461
+ return Number(direct.rate);
2462
+ }
2463
+ const inverse = await exchangeRepo.findOne({
2464
+ where: {
2465
+ fromCurrency: to,
2466
+ toCurrency: from
2467
+ }
2468
+ });
2469
+ if (inverse && Number(inverse.rate) > 0) {
2470
+ return 1 / Number(inverse.rate);
2471
+ }
2472
+ } catch {
2473
+ }
2474
+ }
2475
+ return 1;
2476
+ }
2477
+ __name(getExchangeRate, "getExchangeRate");
2478
+ function discountEvaluateRule(rule, cartLines, cartTotal, exchangeRate = 1) {
2479
+ if (rule.conditionType === "group") return discountEvaluateGroup(rule, cartLines, cartTotal, exchangeRate);
2449
2480
  if (rule.type === "reward") return true;
2450
- const ruleValue = discountExtractValue(rule.value);
2481
+ const rawRuleValue = discountExtractValue(rule.value);
2451
2482
  switch (rule.type) {
2452
- case "minAmount":
2453
- return discountCompare(cartTotal, rule.comparisonOperator, ruleValue);
2483
+ case "minAmount": {
2484
+ const convertedValue = typeof rawRuleValue === "number" ? rawRuleValue * exchangeRate : !isNaN(Number(rawRuleValue)) ? Number(rawRuleValue) * exchangeRate : rawRuleValue;
2485
+ return discountCompare(cartTotal, rule.comparisonOperator, convertedValue);
2486
+ }
2454
2487
  case "quantity": {
2455
2488
  if (rule.subType === "productId" && rule.value?.productId) {
2456
2489
  const targetProductId = Number(rule.value.productId);
@@ -2459,11 +2492,11 @@ function discountEvaluateRule(rule, cartLines, cartTotal) {
2459
2492
  return discountCompare(productQty, rule.comparisonOperator, requiredQty);
2460
2493
  }
2461
2494
  const totalQty = cartLines.reduce((s, l) => s + l.quantity, 0);
2462
- return discountCompare(totalQty, rule.comparisonOperator, ruleValue);
2495
+ return discountCompare(totalQty, rule.comparisonOperator, rawRuleValue);
2463
2496
  }
2464
2497
  case "product":
2465
2498
  if (rule.subType === "productId") {
2466
- return cartLines.some((l) => discountCompare(l.productId, rule.comparisonOperator, ruleValue));
2499
+ return cartLines.some((l) => discountCompare(l.productId, rule.comparisonOperator, rawRuleValue));
2467
2500
  }
2468
2501
  return false;
2469
2502
  // These require external context (user session, payment method, time) —
@@ -2487,11 +2520,11 @@ function discountEvaluateRule(rule, cartLines, cartTotal) {
2487
2520
  }
2488
2521
  }
2489
2522
  __name(discountEvaluateRule, "discountEvaluateRule");
2490
- function discountEvaluateGroup(group, cartLines, cartTotal) {
2523
+ function discountEvaluateGroup(group, cartLines, cartTotal, exchangeRate = 1) {
2491
2524
  if (!group.children?.length) return true;
2492
2525
  const op = (group.conditionOperator ?? "and").toLowerCase();
2493
- if (op === "and") return group.children.every((child) => discountEvaluateRule(child, cartLines, cartTotal));
2494
- if (op === "or") return group.children.some((child) => discountEvaluateRule(child, cartLines, cartTotal));
2526
+ if (op === "and") return group.children.every((child) => discountEvaluateRule(child, cartLines, cartTotal, exchangeRate));
2527
+ if (op === "or") return group.children.some((child) => discountEvaluateRule(child, cartLines, cartTotal, exchangeRate));
2495
2528
  return true;
2496
2529
  }
2497
2530
  __name(discountEvaluateGroup, "discountEvaluateGroup");
@@ -2538,19 +2571,19 @@ function discountExtractBuyProductId(nodes) {
2538
2571
  return null;
2539
2572
  }
2540
2573
  __name(discountExtractBuyProductId, "discountExtractBuyProductId");
2541
- function discountBuildUniversalResult(discount, cartLines) {
2574
+ function discountBuildUniversalResult(discount, cartLines, effectiveValue) {
2542
2575
  return {
2543
2576
  rewardLines: cartLines.map((l) => ({
2544
2577
  productId: l.productId,
2545
2578
  quantity: l.quantity,
2546
- discountRate: Number(discount.value),
2579
+ discountRate: effectiveValue,
2547
2580
  discountType: discount.discountType
2548
2581
  })),
2549
2582
  conditionsMet: true
2550
2583
  };
2551
2584
  }
2552
2585
  __name(discountBuildUniversalResult, "discountBuildUniversalResult");
2553
- function evaluateDiscount(discount, cartLines) {
2586
+ function evaluateDiscount(discount, cartLines, exchangeRate = 1) {
2554
2587
  const empty = {
2555
2588
  rewardLines: [],
2556
2589
  conditionsMet: false
@@ -2574,16 +2607,17 @@ function evaluateDiscount(discount, cartLines) {
2574
2607
  reason: "discount usage limit reached"
2575
2608
  };
2576
2609
  }
2610
+ const effectiveValue = discount.discountType === "FLAT" ? Number(discount.value) * exchangeRate : Number(discount.value);
2577
2611
  const cartTotal = cartLines.reduce((s, l) => s + l.subtotal, 0);
2578
2612
  const tree = discountBuildTree(discount.rules ?? []);
2579
- if (tree.length === 0) return discountBuildUniversalResult(discount, cartLines);
2580
- const conditionsMet = tree.every((node) => discountEvaluateRule(node, cartLines, cartTotal));
2613
+ if (tree.length === 0) return discountBuildUniversalResult(discount, cartLines, effectiveValue);
2614
+ const conditionsMet = tree.every((node) => discountEvaluateRule(node, cartLines, cartTotal, exchangeRate));
2581
2615
  if (!conditionsMet) return {
2582
2616
  ...empty,
2583
2617
  reason: "conditions not met"
2584
2618
  };
2585
2619
  const rewardRules = discountCollectRewardRules(tree);
2586
- if (rewardRules.length === 0) return discountBuildUniversalResult(discount, cartLines);
2620
+ if (rewardRules.length === 0) return discountBuildUniversalResult(discount, cartLines, effectiveValue);
2587
2621
  const requiredBuyQty = discountExtractRequiredBuyQty(tree);
2588
2622
  const buyProductId = discountExtractBuyProductId(tree);
2589
2623
  let dealMultiplier = 1;
@@ -2601,7 +2635,7 @@ function evaluateDiscount(discount, cartLines) {
2601
2635
  rewardLines.push({
2602
2636
  productId: rewardProductId,
2603
2637
  quantity: dealMultiplier,
2604
- discountRate: Number(discount.value),
2638
+ discountRate: effectiveValue,
2605
2639
  discountType: discount.discountType
2606
2640
  });
2607
2641
  } else {
@@ -2610,7 +2644,7 @@ function evaluateDiscount(discount, cartLines) {
2610
2644
  rewardLines.push({
2611
2645
  productId: rewardProductId,
2612
2646
  quantity: rewardQty,
2613
- discountRate: Number(discount.value),
2647
+ discountRate: effectiveValue,
2614
2648
  discountType: discount.discountType
2615
2649
  });
2616
2650
  }
@@ -2621,8 +2655,9 @@ function evaluateDiscount(discount, cartLines) {
2621
2655
  };
2622
2656
  }
2623
2657
  __name(evaluateDiscount, "evaluateDiscount");
2624
- function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount) {
2658
+ function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount, exchangeRate = 1) {
2625
2659
  if (!evalResult.conditionsMet || evalResult.rewardLines.length === 0) return 0;
2660
+ const effectiveMaxDiscountAmount = maxDiscountAmount != null ? Number(maxDiscountAmount) * exchangeRate : null;
2626
2661
  let totalDiscountApplied = 0;
2627
2662
  for (const reward of evalResult.rewardLines) {
2628
2663
  const line = lines.find((l) => l.productId === reward.productId);
@@ -2639,8 +2674,8 @@ function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount) {
2639
2674
  line.subtotal = line.unitPrice * line.quantity;
2640
2675
  line.total = Math.max(0, line.subtotal - (line.discount ?? 0));
2641
2676
  }
2642
- if (maxDiscountAmount != null && totalDiscountApplied > maxDiscountAmount) {
2643
- const excess = totalDiscountApplied - maxDiscountAmount;
2677
+ if (effectiveMaxDiscountAmount != null && totalDiscountApplied > effectiveMaxDiscountAmount) {
2678
+ const excess = totalDiscountApplied - effectiveMaxDiscountAmount;
2644
2679
  for (let i = evalResult.rewardLines.length - 1; i >= 0; i--) {
2645
2680
  const reward = evalResult.rewardLines[i];
2646
2681
  const line = lines.find((l) => l.productId === reward.productId);
@@ -2650,7 +2685,7 @@ function applyDiscountToOrderLines(lines, evalResult, maxDiscountAmount) {
2650
2685
  line.total = Math.max(0, line.total + rollback);
2651
2686
  if (rollback > 0) break;
2652
2687
  }
2653
- totalDiscountApplied = maxDiscountAmount;
2688
+ totalDiscountApplied = effectiveMaxDiscountAmount;
2654
2689
  }
2655
2690
  return totalDiscountApplied;
2656
2691
  }
@@ -2756,7 +2791,9 @@ async function validateCoupon(dataSource, entityMap, couponCode, orderLines, cur
2756
2791
  unitPrice: l.unitPrice,
2757
2792
  subtotal: l.subtotal
2758
2793
  }));
2759
- const evalResult = evaluateDiscount(discountForEval, cartLines);
2794
+ const dCurrency = d.currency || "INR";
2795
+ const exchangeRate = await getExchangeRate(dataSource, entityMap, dCurrency, currency);
2796
+ const evalResult = evaluateDiscount(discountForEval, cartLines, exchangeRate);
2760
2797
  if (!evalResult.conditionsMet) {
2761
2798
  return {
2762
2799
  valid: false,
@@ -2766,7 +2803,7 @@ async function validateCoupon(dataSource, entityMap, couponCode, orderLines, cur
2766
2803
  const clonedLines = lines.map((l) => ({
2767
2804
  ...l
2768
2805
  }));
2769
- const calculatedDiscount = applyDiscountToOrderLines(clonedLines, evalResult, d.maxDiscountAmount);
2806
+ const calculatedDiscount = applyDiscountToOrderLines(clonedLines, evalResult, d.maxDiscountAmount, exchangeRate);
2770
2807
  const rewardProductIds = evalResult.rewardLines.map((r) => r.productId);
2771
2808
  return {
2772
2809
  valid: true,
@@ -3051,9 +3088,11 @@ async function calculateOrderTotalsFromLines(dataSource, entityMap, lineInputs,
3051
3088
  unitPrice: l.unitPrice,
3052
3089
  subtotal: l.subtotal
3053
3090
  }));
3054
- const evalResult = evaluateDiscount(discountForEval, cartLines);
3091
+ const dCurrency = discountRow.currency || "INR";
3092
+ const exchangeRate2 = await getExchangeRate(dataSource, entityMap, dCurrency, currency);
3093
+ const evalResult = evaluateDiscount(discountForEval, cartLines, exchangeRate2);
3055
3094
  if (evalResult.conditionsMet) {
3056
- const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount);
3095
+ const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount, exchangeRate2);
3057
3096
  orderDiscount += totalDiscountApplied;
3058
3097
  }
3059
3098
  }
@@ -3166,9 +3205,25 @@ async function calculateOrderTotals(dataSource, entityMap, itemsSummary, discoun
3166
3205
  unitPrice: l.unitPrice,
3167
3206
  subtotal: l.subtotal
3168
3207
  }));
3169
- const evalResult = evaluateDiscount(discountForEval, cartLines);
3208
+ const dCurrency = discountRow.currency || "INR";
3209
+ let storeCurrency = "INR";
3210
+ if (entityMap["configs"]) {
3211
+ try {
3212
+ const configRepo = dataSource.getRepository(entityMap["configs"]);
3213
+ const curr = await configRepo.findOne({
3214
+ where: {
3215
+ settings: "store",
3216
+ key: "currency"
3217
+ }
3218
+ });
3219
+ storeCurrency = curr?.value?.toUpperCase() ?? "INR";
3220
+ } catch {
3221
+ }
3222
+ }
3223
+ const exchangeRate = await getExchangeRate(dataSource, entityMap, dCurrency, storeCurrency);
3224
+ const evalResult = evaluateDiscount(discountForEval, cartLines, exchangeRate);
3170
3225
  if (evalResult.conditionsMet) {
3171
- const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount);
3226
+ const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount, exchangeRate);
3172
3227
  for (const line of lines) {
3173
3228
  if (!line.found || line.taxRate === 0) continue;
3174
3229
  const discountedAmount = line.subtotal - (line.discount ?? 0);
@@ -5117,11 +5172,18 @@ function createCrudHandler(dataSource, entityMap, options) {
5117
5172
  await recordDiscountUsage2(dataSource, entityMap, created.id, orderDiscountId, persistBody.contactId, discount);
5118
5173
  }
5119
5174
  const orderIdForNotify = created.id;
5120
- void import('./emit-order-notification-trigger-HZQPPSFB.js').then(({ fireOrderNotificationTrigger }) => {
5175
+ const initialPayStatus = String(persistBody.paymentStatus ?? "unpaid").toLowerCase();
5176
+ void import('./emit-order-notification-trigger-CZU3V2WE.js').then(({ fireOrderNotificationTrigger }) => {
5121
5177
  fireOrderNotificationTrigger("order_placed", orderIdForNotify, {
5122
5178
  dataSource,
5123
5179
  entityMap
5124
5180
  });
5181
+ if (initialPayStatus === "paid" || initialPayStatus === "captured") {
5182
+ fireOrderNotificationTrigger("payment_success", orderIdForNotify, {
5183
+ dataSource,
5184
+ entityMap
5185
+ });
5186
+ }
5125
5187
  });
5126
5188
  }
5127
5189
  } catch (err) {
@@ -6588,6 +6650,43 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6588
6650
  await retireSoftDeletedUniquesFromBody(repo, updatePayload);
6589
6651
  try {
6590
6652
  await repo.update(numericId, updatePayload);
6653
+ if (resource === "payments" && updatePayload.status) {
6654
+ const updatedPay = await repo.findOne({
6655
+ where: {
6656
+ id: numericId
6657
+ }
6658
+ });
6659
+ const pOrder = updatedPay?.orderId;
6660
+ const newPayStatus = String(updatePayload.status).toLowerCase();
6661
+ if (pOrder && Number.isFinite(pOrder)) {
6662
+ if (newPayStatus === "paid" || newPayStatus === "captured") {
6663
+ if (entityMap.orders) {
6664
+ await dataSource.getRepository(entityMap.orders).update(pOrder, {
6665
+ status: "confirmed"
6666
+ });
6667
+ }
6668
+ void import('./emit-order-notification-trigger-CZU3V2WE.js').then(({ fireOrderNotificationTrigger }) => {
6669
+ fireOrderNotificationTrigger("order_placed", pOrder, {
6670
+ dataSource,
6671
+ entityMap
6672
+ });
6673
+ fireOrderNotificationTrigger("payment_success", pOrder, {
6674
+ dataSource,
6675
+ entityMap
6676
+ });
6677
+ }).catch(() => {
6678
+ });
6679
+ } else if (newPayStatus === "failed") {
6680
+ void import('./emit-order-notification-trigger-CZU3V2WE.js').then(({ fireOrderNotificationTrigger }) => {
6681
+ fireOrderNotificationTrigger("payment_failed", pOrder, {
6682
+ dataSource,
6683
+ entityMap
6684
+ });
6685
+ }).catch(() => {
6686
+ });
6687
+ }
6688
+ }
6689
+ }
6591
6690
  } catch (err) {
6592
6691
  if (resource === "events" && isSlugUniqueViolation(err)) {
6593
6692
  return json({
@@ -9142,7 +9241,9 @@ function createFormSaveHandlers(config) {
9142
9241
  "description",
9143
9242
  "campaign",
9144
9243
  "slug",
9145
- "published"
9244
+ "published",
9245
+ "enableTurnstile",
9246
+ "enable_turnstile"
9146
9247
  ]) {
9147
9248
  if (body[key] !== void 0) formRow[key] = body[key];
9148
9249
  }
@@ -17038,6 +17139,7 @@ var Form = class {
17038
17139
  campaign;
17039
17140
  slug;
17040
17141
  published;
17142
+ enableTurnstile;
17041
17143
  createdAt;
17042
17144
  updatedAt;
17043
17145
  deletedAt;
@@ -17080,6 +17182,14 @@ _ts_decorate14([
17080
17182
  }),
17081
17183
  _ts_metadata14("design:type", Boolean)
17082
17184
  ], Form.prototype, "published", void 0);
17185
+ _ts_decorate14([
17186
+ Column("boolean", {
17187
+ default: false,
17188
+ name: "enable_turnstile",
17189
+ nullable: true
17190
+ }),
17191
+ _ts_metadata14("design:type", Boolean)
17192
+ ], Form.prototype, "enableTurnstile", void 0);
17083
17193
  _ts_decorate14([
17084
17194
  Column({
17085
17195
  type: "timestamp",
@@ -29217,7 +29327,7 @@ function createCmsApiHandler(config) {
29217
29327
  }
29218
29328
  if (path2[0] === "settings" && path2.length === 2 && settingsHandlers) {
29219
29329
  const group = path2[1];
29220
- const isPublic = group === "multi_vendor" || settingsConfig?.publicGetGroups?.includes(group);
29330
+ const isPublic = group === "multi_vendor" || group === "turnstile" || group === "auth_providers" || settingsConfig?.publicGetGroups?.includes(group);
29221
29331
  if (m === "GET") {
29222
29332
  if (!isPublic) {
29223
29333
  const a = await config.requireAuth(req);
@@ -29875,14 +29985,21 @@ function createCmsApiHandler(config) {
29875
29985
  body = {};
29876
29986
  }
29877
29987
  const triggerKey = String(body.triggerKey ?? "order_placed").trim() || "order_placed";
29878
- if (triggerKey !== "order_placed" && triggerKey !== "order_cancelled") {
29988
+ const validTriggers = [
29989
+ "order_placed",
29990
+ "order_cancelled",
29991
+ "payment_success",
29992
+ "payment_failed",
29993
+ "payment_refund_initiated"
29994
+ ];
29995
+ if (!validTriggers.includes(triggerKey)) {
29879
29996
  return config.json({
29880
- error: "Invalid triggerKey; use order_placed or order_cancelled"
29997
+ error: `Invalid triggerKey; use one of: ${validTriggers.join(", ")}`
29881
29998
  }, {
29882
29999
  status: 400
29883
30000
  });
29884
30001
  }
29885
- const { resendOrderNotification } = await import('./order-notification-dispatcher-64WDCHHG.js');
30002
+ const { resendOrderNotification } = await import('./order-notification-dispatcher-ZSFKEYMP.js');
29886
30003
  const result = await resendOrderNotification(triggerKey, orderId, {
29887
30004
  dataSource,
29888
30005
  entityMap,
@@ -29904,11 +30021,9 @@ function createCmsApiHandler(config) {
29904
30021
  if (path2[0] === "orders" && path2.length === 3 && path2[2] === "cancel" && m === "POST") {
29905
30022
  const a = await config.requireAuth(req);
29906
30023
  if (a) return a;
29907
- const pe = await requireEntityPermissionEffective(req, "orders", "update");
29908
- if (pe) return pe;
29909
- const orderId = Number(path2[1]);
29910
- if (!Number.isFinite(orderId)) return config.json({
29911
- error: "Invalid id"
30024
+ const orderId = parseInt(path2[1], 10);
30025
+ if (Number.isNaN(orderId)) return config.json({
30026
+ error: "Invalid order ID"
29912
30027
  }, {
29913
30028
  status: 400
29914
30029
  });
@@ -29925,9 +30040,10 @@ function createCmsApiHandler(config) {
29925
30040
  status: 404
29926
30041
  });
29927
30042
  const o = order;
29928
- if (o.status !== "confirmed" && o.status !== "completed") {
30043
+ const currentStatus = (o.status || "").toLowerCase();
30044
+ if (currentStatus === "cancelled") {
29929
30045
  return config.json({
29930
- error: "Only confirmed or completed orders can be cancelled"
30046
+ error: "Order is already cancelled"
29931
30047
  }, {
29932
30048
  status: 400
29933
30049
  });
@@ -29950,7 +30066,7 @@ function createCmsApiHandler(config) {
29950
30066
  }
29951
30067
  });
29952
30068
  if (payment) {
29953
- paymentStatus = String(payment.status ?? "unpaid");
30069
+ paymentStatus = String(payment.status ?? "unpaid").toLowerCase();
29954
30070
  paymentId = Number(payment.id);
29955
30071
  }
29956
30072
  }
@@ -29982,13 +30098,26 @@ function createCmsApiHandler(config) {
29982
30098
  status: "cancelled"
29983
30099
  });
29984
30100
  const fireOrderCancelledNotification = /* @__PURE__ */ __name((refundAmount) => {
29985
- void import('./emit-order-notification-trigger-HZQPPSFB.js').then(({ fireOrderNotificationTrigger }) => {
30101
+ void import('./emit-order-notification-trigger-CZU3V2WE.js').then(({ fireOrderNotificationTrigger }) => {
29986
30102
  fireOrderNotificationTrigger("order_cancelled", orderId, {
29987
30103
  dataSource,
29988
30104
  entityMap
29989
30105
  }, refundAmount != null && refundAmount > 0 ? {
29990
30106
  refundAmount
29991
30107
  } : void 0);
30108
+ if (paymentStatus === "paid" || paymentStatus === "captured") {
30109
+ fireOrderNotificationTrigger("payment_refund_initiated", orderId, {
30110
+ dataSource,
30111
+ entityMap
30112
+ }, refundAmount != null && refundAmount > 0 ? {
30113
+ refundAmount
30114
+ } : void 0);
30115
+ } else {
30116
+ fireOrderNotificationTrigger("payment_failed", orderId, {
30117
+ dataSource,
30118
+ entityMap
30119
+ });
30120
+ }
29992
30121
  });
29993
30122
  }, "fireOrderCancelledNotification");
29994
30123
  if (paymentStatus === "paid" && entityMap.payments && paymentId) {
@@ -31014,12 +31143,23 @@ function createStorefrontApiHandler(config) {
31014
31143
  const otpFlags = config.otpFlags;
31015
31144
  const otpPepper = config.otpPepper;
31016
31145
  const defaultPhoneCc = config.defaultPhoneCountryCode;
31017
- function fireOrderPlacedNotification(orderId) {
31018
- void import('./emit-order-notification-trigger-HZQPPSFB.js').then(({ fireOrderNotificationTrigger }) => {
31146
+ function fireOrderPlacedNotification(orderId, isPaid) {
31147
+ void import('./emit-order-notification-trigger-CZU3V2WE.js').then(({ fireOrderNotificationTrigger }) => {
31019
31148
  fireOrderNotificationTrigger("order_placed", orderId, {
31020
31149
  dataSource,
31021
31150
  entityMap
31022
31151
  });
31152
+ if (isPaid) {
31153
+ fireOrderNotificationTrigger("payment_success", orderId, {
31154
+ dataSource,
31155
+ entityMap
31156
+ });
31157
+ } else {
31158
+ fireOrderNotificationTrigger("payment_failed", orderId, {
31159
+ dataSource,
31160
+ entityMap
31161
+ });
31162
+ }
31023
31163
  }).catch((err) => console.error("[notification-triggers] import failed", err));
31024
31164
  }
31025
31165
  __name(fireOrderPlacedNotification, "fireOrderPlacedNotification");
@@ -33904,6 +34044,20 @@ function createStorefrontApiHandler(config) {
33904
34044
  }
33905
34045
  } catch {
33906
34046
  }
34047
+ try {
34048
+ void import('./emit-order-notification-trigger-CZU3V2WE.js').then(({ fireOrderNotificationTrigger }) => {
34049
+ fireOrderNotificationTrigger("order_cancelled", orderId, {
34050
+ dataSource,
34051
+ entityMap
34052
+ });
34053
+ fireOrderNotificationTrigger("payment_failed", orderId, {
34054
+ dataSource,
34055
+ entityMap
34056
+ });
34057
+ }).catch(() => {
34058
+ });
34059
+ } catch {
34060
+ }
33907
34061
  }
33908
34062
  return json({
33909
34063
  ok: true,
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunk3EOM4V2M_cjs = require('./chunk-3EOM4V2M.cjs');
3
+ var chunk4U6DATGZ_cjs = require('./chunk-4U6DATGZ.cjs');
4
4
  var chunkOY2YTBMP_cjs = require('./chunk-OY2YTBMP.cjs');
5
- var chunk77NUXO6A_cjs = require('./chunk-77NUXO6A.cjs');
5
+ var chunkJ7FMZK66_cjs = require('./chunk-J7FMZK66.cjs');
6
6
  var chunk7L6KWI7S_cjs = require('./chunk-7L6KWI7S.cjs');
7
7
  var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
8
8
  var _CredentialsProvider = require('next-auth/providers/credentials');
@@ -15,12 +15,12 @@ var _GoogleProvider__default = /*#__PURE__*/_interopDefault(_GoogleProvider);
15
15
 
16
16
  // src/auth/seed-permissions.ts
17
17
  async function seedAdministratorPermissions(dataSource, entityMap) {
18
- const entities = chunk77NUXO6A_cjs.getPermissionableEntityKeys(entityMap);
18
+ const entities = chunkJ7FMZK66_cjs.getPermissionableEntityKeys(entityMap);
19
19
  const groupRepo = dataSource.getRepository(entityMap.user_groups);
20
20
  const permRepo = dataSource.getRepository(entityMap.permissions);
21
21
  const adminGroup = await groupRepo.findOne({
22
22
  where: {
23
- name: chunk77NUXO6A_cjs.ADMIN_GROUP_NAME,
23
+ name: chunkJ7FMZK66_cjs.ADMIN_GROUP_NAME,
24
24
  deleted: false
25
25
  }
26
26
  });
@@ -260,13 +260,13 @@ async function createCustomerUserFromGoogleOAuth(input) {
260
260
  }
261
261
  if (input.entityMap.contacts) {
262
262
  try {
263
- await chunk3EOM4V2M_cjs.linkUnclaimedContactToUser(input.dataSource, input.entityMap.contacts, userId, email);
263
+ await chunk4U6DATGZ_cjs.linkUnclaimedContactToUser(input.dataSource, input.entityMap.contacts, userId, email);
264
264
  } catch {
265
265
  }
266
266
  }
267
267
  if (input.entityMap.customer) {
268
268
  try {
269
- await chunk3EOM4V2M_cjs.ensureCustomerForUser(input.dataSource, input.entityMap.customer, {
269
+ await chunk4U6DATGZ_cjs.ensureCustomerForUser(input.dataSource, input.entityMap.customer, {
270
270
  id: userId,
271
271
  name: displayName,
272
272
  email,
@@ -387,18 +387,18 @@ async function checkMultiVendorEnabledViaSettingsApi() {
387
387
  chunkUSNT2KNT_cjs.__name(checkMultiVendorEnabledViaSettingsApi, "checkMultiVendorEnabledViaSettingsApi");
388
388
  function sessionUserFromNextAuthUser(user) {
389
389
  const g = user.group;
390
- const isRBACAdmin = chunk77NUXO6A_cjs.isSuperAdmin({
390
+ const isRBACAdmin = chunkJ7FMZK66_cjs.isSuperAdmin({
391
391
  groupId: user.groupId ?? void 0,
392
392
  groupName: g?.name,
393
393
  isRBACAdmin: false
394
394
  });
395
- const entityPerms = chunk77NUXO6A_cjs.permissionRowsToRecord(g?.permissions);
395
+ const entityPerms = chunkJ7FMZK66_cjs.permissionRowsToRecord(g?.permissions);
396
396
  const rawAdminAccess = user.adminAccess;
397
397
  const adminAccess = rawAdminAccess === true ? true : rawAdminAccess === false ? false : void 0;
398
398
  const vendorIds = user.vendorIds ?? [];
399
399
  const vendorRole = user.vendorRole ?? null;
400
400
  const isVendorRoleOwner = user.isVendorRoleOwner ?? false;
401
- const { isVendorPortal, isVendorOwner: isVendorOwner2 } = chunk77NUXO6A_cjs.vendorPortalFlagsFromUser({
401
+ const { isVendorPortal, isVendorOwner: isVendorOwner2 } = chunkJ7FMZK66_cjs.vendorPortalFlagsFromUser({
402
402
  email: user.email,
403
403
  isRBACAdmin,
404
404
  groupName: g?.name,
@@ -135,7 +135,15 @@ var VENDOR_STORE_RBAC_ENTITIES = /* @__PURE__ */ new Set([
135
135
  ...VENDOR_SCOPED_STORE_ENTITIES,
136
136
  "order_discounts",
137
137
  "order_addresses",
138
- "event_products"
138
+ "event_products",
139
+ "attendees",
140
+ "order-attendees",
141
+ "order_attendees",
142
+ "scan",
143
+ "verify-attendee-qr",
144
+ "verify_attendee_qr",
145
+ "forms",
146
+ "cms-forms"
139
147
  ]);
140
148
  var VENDOR_GROUP_NAME = "Vendor";
141
149
  var VENDOR_OWNER_GROUP_NAME = VENDOR_GROUP_NAME;
@@ -604,7 +612,7 @@ async function logEntityAccessDecision(dataSource, context, user, entity, action
604
612
  const id = Number(user.id);
605
613
  if (Number.isFinite(id)) {
606
614
  try {
607
- const { loadDbPermissionsForUser } = await import('./rbac-debug-db-6EMIVMGF.js');
615
+ const { loadDbPermissionsForUser } = await import('./rbac-debug-db-5R6XFPSV.js');
608
616
  dbPermissions = await loadDbPermissionsForUser(dataSource, id);
609
617
  } catch (e) {
610
618
  dbPermissions = {
@@ -1,4 +1,4 @@
1
- import { explainSessionEntityAccess, isVendorPortalUser, logRbac } from './chunk-JIWUVQ6B.js';
1
+ import { explainSessionEntityAccess, isVendorPortalUser, logRbac } from './chunk-MVHDC3XF.js';
2
2
  import { __name } from './chunk-SHUYVCID.js';
3
3
  import { IsNull } from 'typeorm';
4
4
 
@@ -1,4 +1,4 @@
1
- import { notificationTriggerEmitter } from './chunk-HCIRL37O.js';
1
+ import { notificationTriggerEmitter } from './chunk-T3HPSF7K.js';
2
2
  import { __name } from './chunk-SHUYVCID.js';
3
3
 
4
4
  // src/lib/emit-order-notification-trigger.ts
@@ -51,6 +51,32 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
51
51
  orderId
52
52
  });
53
53
  }
54
+ let resolvedRefundAmount = extra?.refundAmount ?? null;
55
+ if (resolvedRefundAmount == null) {
56
+ const meta = typeof fullOrder.metadata === "object" && fullOrder.metadata ? fullOrder.metadata : {};
57
+ const metaRefund = Number(meta.finalRefund ?? meta.approvedRefundAmount ?? meta.expectedRefundAmount);
58
+ if (Number.isFinite(metaRefund) && metaRefund > 0) {
59
+ resolvedRefundAmount = metaRefund;
60
+ } else if (deps.entityMap.refund_requests) {
61
+ try {
62
+ const rrRepo = deps.dataSource.getRepository(deps.entityMap.refund_requests);
63
+ const rr = await rrRepo.findOne({
64
+ where: {
65
+ orderId
66
+ },
67
+ order: {
68
+ id: "DESC"
69
+ }
70
+ });
71
+ if (rr) {
72
+ const rrObj = rr;
73
+ const amt = Number(rrObj.approvedRefundAmount ?? rrObj.expectedRefundAmount);
74
+ if (Number.isFinite(amt) && amt > 0) resolvedRefundAmount = amt;
75
+ }
76
+ } catch {
77
+ }
78
+ }
79
+ }
54
80
  notificationTriggerEmitter.emitTrigger(triggerKey, {
55
81
  orderId,
56
82
  orderNumber: String(fo.orderNumber ?? ""),
@@ -60,9 +86,7 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
60
86
  currency: String(fo.currency ?? "INR"),
61
87
  vendorId: fo.vendorId ?? null,
62
88
  extraVariables: extra?.extraVariables,
63
- ...extra?.refundAmount != null ? {
64
- refundAmount: extra.refundAmount
65
- } : {}
89
+ refundAmount: resolvedRefundAmount
66
90
  });
67
91
  }
68
92
  __name(emitOrderNotificationTrigger, "emitOrderNotificationTrigger");