payment-kit 1.24.3 → 1.24.4

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.
@@ -126,13 +126,22 @@ export class HealthReportTemplate implements BaseEmailTemplate<HealthReportConte
126
126
 
127
127
  // Preload all Meter configurations to reduce database queries
128
128
  const eventNames = [...new Set(events.map((e) => e.event_name))];
129
- const meters = await Meter.findAll({ where: { event_name: eventNames } });
129
+ const meters = await Meter.findAll({
130
+ where: {
131
+ event_name: eventNames,
132
+ status: 'active',
133
+ },
134
+ });
130
135
  const meterMap = new Map(meters.map((m) => [m.event_name, m]));
131
136
 
132
137
  for (const event of events) {
133
138
  const customerId = event.getCustomerId();
134
139
  if (customerId) {
135
140
  const meter = meterMap.get(event.event_name);
141
+ if (!meter) {
142
+ // eslint-disable-next-line no-continue
143
+ continue;
144
+ }
136
145
  const currencyId = meter?.currency_id;
137
146
  if (currencyId) {
138
147
  if (!userAggregates.has(customerId)) {
@@ -1,4 +1,5 @@
1
1
  import { Op } from 'sequelize';
2
+ import debounce from 'lodash/debounce';
2
3
  /* eslint-disable @typescript-eslint/indent */
3
4
  import { events } from '../libs/event';
4
5
  import logger from '../libs/logger';
@@ -337,6 +338,8 @@ interface NotificationItem<T = Record<string, any>> {
337
338
 
338
339
  // 内存缓存,记录最近发送的通知
339
340
  const notificationCache = new Map<string, number>();
341
+ // 去抖函数(按 key 去重)
342
+ const debounceHandlers = new Map<string, ReturnType<typeof debounce>>();
340
343
 
341
344
  // 清理过期缓存的定时器
342
345
  setInterval(
@@ -741,8 +744,26 @@ export async function startNotificationQueue() {
741
744
  // Clear credit notification cache when customer recharges
742
745
  // This allows customer to receive insufficient/low_balance notifications again
743
746
  events.on('customer.credit_grant.granted', (creditGrant: CreditGrant) => {
744
- clearNotificationCache(`customer.credit.insufficient.${creditGrant.customer_id}.${creditGrant.currency_id}`);
745
- clearNotificationCache(`customer.credit.low_balance.${creditGrant.customer_id}.${creditGrant.currency_id}`);
747
+ const cacheKeyBase = `${creditGrant.customer_id}.${creditGrant.currency_id}`;
748
+ const debounceKey = `credit_grant_clear.${cacheKeyBase}`;
749
+ const delayMs = 5 * 60 * 1000;
750
+
751
+ let handler = debounceHandlers.get(debounceKey);
752
+ if (!handler) {
753
+ handler = debounce(() => {
754
+ clearNotificationCache(`customer.credit.insufficient.${cacheKeyBase}`);
755
+ clearNotificationCache(`customer.credit.low_balance.${cacheKeyBase}`);
756
+ debounceHandlers.delete(debounceKey);
757
+ logger.info('Notification cache cleared after delay', {
758
+ customerId: creditGrant.customer_id,
759
+ currencyId: creditGrant.currency_id,
760
+ delayMs,
761
+ });
762
+ }, delayMs);
763
+ debounceHandlers.set(debounceKey, handler);
764
+ }
765
+
766
+ handler();
746
767
  });
747
768
  }
748
769
 
@@ -372,6 +372,7 @@ router.get('/overdue-summary', auth, async (req, res) => {
372
372
  JOIN meters m ON me.event_name = m.event_name
373
373
  WHERE me.livemode = :livemode
374
374
  AND me.status IN ('requires_capture', 'requires_action')
375
+ AND m.status = 'active'
375
376
  GROUP BY m.currency_id
376
377
  HAVING total_pending > 0
377
378
  ORDER BY total_pending DESC`,
@@ -465,6 +466,7 @@ router.get('/overdue-customers', auth, async (req, res) => {
465
466
  JOIN meters m ON me.event_name = m.event_name
466
467
  WHERE me.livemode = :livemode
467
468
  AND me.status IN ('requires_capture', 'requires_action')
469
+ AND m.status = 'active'
468
470
  ${currencyFilter}
469
471
  ${customerFilter}
470
472
  GROUP BY json_extract(me.payload, '$.customer_id'), m.currency_id
@@ -485,6 +487,7 @@ router.get('/overdue-customers', auth, async (req, res) => {
485
487
  JOIN meters m ON me.event_name = m.event_name
486
488
  WHERE me.livemode = :livemode
487
489
  AND me.status IN ('requires_capture', 'requires_action')
490
+ AND m.status = 'active'
488
491
  ${currencyFilter}
489
492
  ${customerFilter}
490
493
  GROUP BY json_extract(me.payload, '$.customer_id'), m.currency_id
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.24.3
17
+ version: 1.24.4
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.24.3",
3
+ "version": "1.24.4",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "prelint": "npm run types",
@@ -59,9 +59,9 @@
59
59
  "@blocklet/error": "^0.3.5",
60
60
  "@blocklet/js-sdk": "^1.17.8-beta-20260104-120132-cb5b1914",
61
61
  "@blocklet/logger": "^1.17.8-beta-20260104-120132-cb5b1914",
62
- "@blocklet/payment-broker-client": "1.24.3",
63
- "@blocklet/payment-react": "1.24.3",
64
- "@blocklet/payment-vendor": "1.24.3",
62
+ "@blocklet/payment-broker-client": "1.24.4",
63
+ "@blocklet/payment-react": "1.24.4",
64
+ "@blocklet/payment-vendor": "1.24.4",
65
65
  "@blocklet/sdk": "^1.17.8-beta-20260104-120132-cb5b1914",
66
66
  "@blocklet/ui-react": "^3.4.7",
67
67
  "@blocklet/uploader": "^0.3.19",
@@ -131,7 +131,7 @@
131
131
  "devDependencies": {
132
132
  "@abtnode/types": "^1.17.8-beta-20260104-120132-cb5b1914",
133
133
  "@arcblock/eslint-config-ts": "^0.3.3",
134
- "@blocklet/payment-types": "1.24.3",
134
+ "@blocklet/payment-types": "1.24.4",
135
135
  "@types/cookie-parser": "^1.4.9",
136
136
  "@types/cors": "^2.8.19",
137
137
  "@types/debug": "^4.1.12",
@@ -178,5 +178,5 @@
178
178
  "parser": "typescript"
179
179
  }
180
180
  },
181
- "gitHead": "6f2a963875ed4aced1db11f1c3a044c7f5deedd6"
181
+ "gitHead": "d4a5f67e657cafa8862912bb8de38a3d56a7919d"
182
182
  }