@windrun-huaiin/backend-core 13.0.0 → 14.1.0

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 (110) hide show
  1. package/dist/_virtual/index.js +7 -3
  2. package/dist/_virtual/index.mjs +5 -3
  3. package/dist/_virtual/index2.js +2 -6
  4. package/dist/_virtual/index2.mjs +2 -6
  5. package/dist/index.js +3 -1
  6. package/dist/index.mjs +2 -2
  7. package/dist/lib/index.js +3 -1
  8. package/dist/lib/index.mjs +2 -2
  9. package/dist/lib/stripe-config.d.ts +1 -1
  10. package/dist/lib/stripe-config.d.ts.map +1 -1
  11. package/dist/lib/stripe-config.js +25 -16
  12. package/dist/lib/stripe-config.mjs +25 -16
  13. package/dist/lib/upstash/qstash.d.ts.map +1 -1
  14. package/dist/lib/upstash/qstash.js +66 -62
  15. package/dist/lib/upstash/qstash.mjs +67 -63
  16. package/dist/lib/upstash/redis-counter.d.ts.map +1 -1
  17. package/dist/lib/upstash/redis-counter.js +9 -24
  18. package/dist/lib/upstash/redis-counter.mjs +10 -25
  19. package/dist/lib/upstash/redis-favorite.d.ts.map +1 -1
  20. package/dist/lib/upstash/redis-favorite.js +22 -36
  21. package/dist/lib/upstash/redis-favorite.mjs +23 -37
  22. package/dist/lib/upstash/redis-like.d.ts.map +1 -1
  23. package/dist/lib/upstash/redis-like.js +22 -36
  24. package/dist/lib/upstash/redis-like.mjs +23 -37
  25. package/dist/lib/upstash/redis-lock.d.ts.map +1 -1
  26. package/dist/lib/upstash/redis-lock.js +22 -38
  27. package/dist/lib/upstash/redis-lock.mjs +23 -39
  28. package/dist/lib/upstash/redis-structures.d.ts.map +1 -1
  29. package/dist/lib/upstash/redis-structures.js +77 -113
  30. package/dist/lib/upstash/redis-structures.mjs +78 -114
  31. package/dist/lib/upstash-config.d.ts +9 -1
  32. package/dist/lib/upstash-config.d.ts.map +1 -1
  33. package/dist/lib/upstash-config.js +221 -27
  34. package/dist/lib/upstash-config.mjs +220 -28
  35. package/dist/node_modules/.pnpm/{@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.js → @upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.js} +897 -468
  36. package/dist/node_modules/.pnpm/{@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.mjs → @upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.mjs} +895 -468
  37. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.js → @upstash_redis@1.37.0/node_modules/@upstash/redis/chunk-IH7W44G6.js} +657 -40
  38. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.mjs → @upstash_redis@1.37.0/node_modules/@upstash/redis/chunk-IH7W44G6.mjs} +657 -41
  39. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1 → @upstash_redis@1.37.0}/node_modules/@upstash/redis/nodejs.js +6 -5
  40. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1 → @upstash_redis@1.37.0}/node_modules/@upstash/redis/nodejs.mjs +2 -2
  41. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.js +1 -1
  42. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.mjs +1 -1
  43. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.js +6 -6
  44. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js +1 -1
  45. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.js +2 -2
  46. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.js +3 -1
  47. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.js +3 -1
  48. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.js +1 -1
  49. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.js +3 -1
  50. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.js +7 -5
  51. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.js +3 -1
  52. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.js +3 -1
  53. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.js +3 -1
  54. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.js +3 -1
  55. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.js +3 -1
  56. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js +4 -2
  57. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.js +3 -1
  58. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.js +3 -1
  59. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.js +1 -1
  60. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.js +3 -1
  61. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.js +3 -1
  62. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.js +6 -4
  63. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js +6 -4
  64. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js +7 -5
  65. package/dist/services/stripe/webhook-handler.js +4 -2
  66. package/dist/services/stripe/webhook-handler.mjs +3 -1
  67. package/package.json +5 -5
  68. package/src/lib/stripe-config.ts +27 -15
  69. package/src/lib/upstash/qstash.ts +64 -62
  70. package/src/lib/upstash/redis-counter.ts +10 -26
  71. package/src/lib/upstash/redis-favorite.ts +23 -42
  72. package/src/lib/upstash/redis-like.ts +23 -42
  73. package/src/lib/upstash/redis-lock.ts +23 -49
  74. package/src/lib/upstash/redis-structures.ts +82 -131
  75. package/src/lib/upstash-config.ts +231 -24
  76. package/src/services/stripe/webhook-handler.ts +3 -1
  77. package/dist/_virtual/index3.js +0 -5
  78. package/dist/_virtual/index3.mjs +0 -3
  79. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.js +0 -191
  80. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.mjs +0 -189
  81. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +0 -54
  82. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +0 -51
  83. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +0 -44
  84. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +0 -35
  85. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +0 -31
  86. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +0 -18
  87. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +0 -587
  88. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +0 -527
  89. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +0 -447
  90. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +0 -399
  91. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +0 -245
  92. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +0 -232
  93. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +0 -68
  94. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +0 -62
  95. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +0 -39
  96. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +0 -37
  97. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +0 -80
  98. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +0 -75
  99. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +0 -101
  100. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +0 -86
  101. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +0 -102
  102. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +0 -76
  103. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +0 -56
  104. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +0 -52
  105. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +0 -1205
  106. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +0 -1157
  107. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +0 -407
  108. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +0 -374
  109. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +0 -9
  110. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +0 -7
@@ -1,50 +1,242 @@
1
- import { Redis as Redis2 } from '../node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.mjs';
2
- import { Client } from '../node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.mjs';
1
+ import { __awaiter } from '../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
2
+ import { Redis as Redis2 } from '../node_modules/.pnpm/@upstash_redis@1.37.0/node_modules/@upstash/redis/nodejs.mjs';
3
+ import { Client } from '../node_modules/.pnpm/@upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.mjs';
3
4
 
4
5
  let cachedRedis = null;
5
6
  let cachedQstash = null;
6
- let redisInitAttempted = false;
7
- let qstashInitAttempted = false;
7
+ let redisInitPromise = null;
8
+ let qstashInitPromise = null;
9
+ let redisWarnedMissingEnv = false;
10
+ let redisWarnedInvalidEnv = false;
11
+ let redisWarnedInitError = false;
12
+ let redisWarnedHealthCheck = false;
13
+ let redisWarnedHealthSchedule = false;
14
+ let qstashWarnedMissingEnv = false;
15
+ let qstashWarnedInitError = false;
16
+ let qstashWarnedHealthCheck = false;
17
+ let qstashWarnedHealthSchedule = false;
18
+ let redisHealthTimer = null;
19
+ let qstashHealthTimer = null;
20
+ const isNonEmpty = (value) => typeof value === 'string' && value.trim().length > 0;
21
+ const isValidUrl = (value) => {
22
+ try {
23
+ const parsed = new URL(value);
24
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:';
25
+ }
26
+ catch (_a) {
27
+ return false;
28
+ }
29
+ };
30
+ const parseMinutes = (value, fallback) => {
31
+ if (!isNonEmpty(value)) {
32
+ return fallback;
33
+ }
34
+ const minutes = Number(value);
35
+ if (!Number.isFinite(minutes) || minutes <= 0) {
36
+ return fallback;
37
+ }
38
+ return minutes;
39
+ };
40
+ const getRedisHealthIntervalMinutes = () => parseMinutes(process.env.UPSTASH_REDIS_HEALTHCHECK_INTERVAL_MINUTES, 10);
41
+ const getQstashHealthIntervalMinutes = () => parseMinutes(process.env.UPSTASH_QSTASH_HEALTHCHECK_INTERVAL_MINUTES, 10);
42
+ const getQstashHealthcheckUrl = () => { var _a; return (_a = process.env.UPSTASH_QSTASH_HEALTHCHECK_URL) !== null && _a !== void 0 ? _a : 'https://qstash.upstash.io/v2/topics'; };
43
+ const scheduleRedisHealthCheck = () => {
44
+ if (redisHealthTimer || !cachedRedis) {
45
+ return;
46
+ }
47
+ const delayMs = getRedisHealthIntervalMinutes() * 60000;
48
+ redisHealthTimer = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
49
+ redisHealthTimer = null;
50
+ if (!cachedRedis) {
51
+ return;
52
+ }
53
+ try {
54
+ yield cachedRedis.ping();
55
+ }
56
+ catch (error) {
57
+ cachedRedis = null;
58
+ if (!redisWarnedHealthCheck) {
59
+ redisWarnedHealthCheck = true;
60
+ const message = error instanceof Error ? error.message : String(error);
61
+ console.warn(`[Upstash Config] Redis health check failed: ${message}`);
62
+ }
63
+ }
64
+ finally {
65
+ try {
66
+ scheduleRedisHealthCheck();
67
+ }
68
+ catch (error) {
69
+ if (!redisWarnedHealthSchedule) {
70
+ redisWarnedHealthSchedule = true;
71
+ const message = error instanceof Error ? error.message : String(error);
72
+ console.warn(`[Upstash Config] Redis health check schedule failed: ${message}`);
73
+ }
74
+ }
75
+ }
76
+ }), delayMs);
77
+ };
78
+ const checkQstashHealth = (token) => __awaiter(void 0, void 0, void 0, function* () {
79
+ const response = yield fetch(getQstashHealthcheckUrl(), {
80
+ method: 'GET',
81
+ headers: {
82
+ Authorization: `Bearer ${token}`,
83
+ },
84
+ cache: 'no-store',
85
+ });
86
+ if (!response.ok) {
87
+ throw new Error(`HTTP ${response.status}`);
88
+ }
89
+ });
90
+ const scheduleQstashHealthCheck = (token) => {
91
+ if (qstashHealthTimer || !cachedQstash) {
92
+ return;
93
+ }
94
+ const delayMs = getQstashHealthIntervalMinutes() * 60000;
95
+ qstashHealthTimer = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
96
+ qstashHealthTimer = null;
97
+ if (!cachedQstash) {
98
+ return;
99
+ }
100
+ try {
101
+ yield checkQstashHealth(token);
102
+ }
103
+ catch (error) {
104
+ cachedQstash = null;
105
+ if (!qstashWarnedHealthCheck) {
106
+ qstashWarnedHealthCheck = true;
107
+ const message = error instanceof Error ? error.message : String(error);
108
+ console.warn(`[Upstash Config] QStash health check failed: ${message}`);
109
+ }
110
+ }
111
+ finally {
112
+ try {
113
+ scheduleQstashHealthCheck(token);
114
+ }
115
+ catch (error) {
116
+ if (!qstashWarnedHealthSchedule) {
117
+ qstashWarnedHealthSchedule = true;
118
+ const message = error instanceof Error ? error.message : String(error);
119
+ console.warn(`[Upstash Config] QStash health check schedule failed: ${message}`);
120
+ }
121
+ }
122
+ }
123
+ }), delayMs);
124
+ };
8
125
  /**
9
- * Get the Upstash Redis client. Returns null when required env vars are missing.
126
+ * Get the Upstash Redis client. Returns null when required env vars are missing/invalid.
127
+ *
128
+ * Singleton semantics:
129
+ * - read-through cached instance only
10
130
  */
11
131
  const getRedis = () => {
132
+ return cachedRedis;
133
+ };
134
+ const ensureRedis = () => __awaiter(void 0, void 0, void 0, function* () {
12
135
  if (cachedRedis) {
13
136
  return cachedRedis;
14
137
  }
15
- if (redisInitAttempted) {
16
- return null;
17
- }
18
- redisInitAttempted = true;
19
- const { UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN } = process.env;
20
- if (!UPSTASH_REDIS_REST_URL || !UPSTASH_REDIS_REST_TOKEN) {
21
- console.warn('[Upstash Config] Redis Missed configration UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN, then disabled');
22
- return null;
138
+ if (redisInitPromise) {
139
+ return redisInitPromise;
23
140
  }
24
- cachedRedis = new Redis2({
25
- url: UPSTASH_REDIS_REST_URL,
26
- token: UPSTASH_REDIS_REST_TOKEN,
27
- });
28
- return cachedRedis;
29
- };
141
+ redisInitPromise = (() => __awaiter(void 0, void 0, void 0, function* () {
142
+ const { UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN } = process.env;
143
+ if (!isNonEmpty(UPSTASH_REDIS_REST_URL) || !isNonEmpty(UPSTASH_REDIS_REST_TOKEN)) {
144
+ if (!redisWarnedMissingEnv) {
145
+ redisWarnedMissingEnv = true;
146
+ console.warn('[Upstash Config] Redis disabled: missing UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN');
147
+ }
148
+ return null;
149
+ }
150
+ if (!isValidUrl(UPSTASH_REDIS_REST_URL)) {
151
+ if (!redisWarnedInvalidEnv) {
152
+ redisWarnedInvalidEnv = true;
153
+ console.warn('[Upstash Config] Redis disabled: UPSTASH_REDIS_REST_URL is not a valid URL');
154
+ }
155
+ return null;
156
+ }
157
+ try {
158
+ const client = new Redis2({
159
+ url: UPSTASH_REDIS_REST_URL,
160
+ token: UPSTASH_REDIS_REST_TOKEN,
161
+ });
162
+ yield client.ping();
163
+ cachedRedis = client;
164
+ scheduleRedisHealthCheck();
165
+ return cachedRedis;
166
+ }
167
+ catch (error) {
168
+ if (!redisWarnedInitError) {
169
+ redisWarnedInitError = true;
170
+ const message = error instanceof Error ? error.message : String(error);
171
+ console.warn(`[Upstash Config] Redis init failed: ${message}`);
172
+ }
173
+ return null;
174
+ }
175
+ finally {
176
+ redisInitPromise = null;
177
+ }
178
+ }))();
179
+ return redisInitPromise;
180
+ });
30
181
  /**
31
182
  * Get the Upstash QStash client. Returns null when required env vars are missing.
183
+ *
184
+ * Singleton semantics:
185
+ * - read-through cached instance only
32
186
  */
33
187
  const getQstash = () => {
188
+ return cachedQstash;
189
+ };
190
+ const ensureQstash = () => __awaiter(void 0, void 0, void 0, function* () {
34
191
  if (cachedQstash) {
35
192
  return cachedQstash;
36
193
  }
37
- if (qstashInitAttempted) {
194
+ if (qstashInitPromise) {
195
+ return qstashInitPromise;
196
+ }
197
+ qstashInitPromise = (() => __awaiter(void 0, void 0, void 0, function* () {
198
+ const { QSTASH_TOKEN } = process.env;
199
+ if (!isNonEmpty(QSTASH_TOKEN)) {
200
+ if (!qstashWarnedMissingEnv) {
201
+ qstashWarnedMissingEnv = true;
202
+ console.warn('[Upstash Config] QStash disabled: missing QSTASH_TOKEN');
203
+ }
204
+ return null;
205
+ }
206
+ try {
207
+ const client = new Client({ token: QSTASH_TOKEN });
208
+ yield checkQstashHealth(QSTASH_TOKEN);
209
+ cachedQstash = client;
210
+ scheduleQstashHealthCheck(QSTASH_TOKEN);
211
+ return cachedQstash;
212
+ }
213
+ catch (error) {
214
+ if (!qstashWarnedInitError) {
215
+ qstashWarnedInitError = true;
216
+ const message = error instanceof Error ? error.message : String(error);
217
+ console.warn(`[Upstash Config] QStash init failed: ${message}`);
218
+ }
219
+ return null;
220
+ }
221
+ finally {
222
+ qstashInitPromise = null;
223
+ }
224
+ }))();
225
+ return qstashInitPromise;
226
+ });
227
+ const withRedis = (fn) => __awaiter(void 0, void 0, void 0, function* () {
228
+ const redis = yield ensureRedis();
229
+ if (!redis) {
38
230
  return null;
39
231
  }
40
- qstashInitAttempted = true;
41
- const { QSTASH_TOKEN } = process.env;
42
- if (!QSTASH_TOKEN) {
43
- console.warn('[Upstash Config] QStash Missed configration QSTASH_TOKEN, then disabled');
232
+ return fn(redis);
233
+ });
234
+ const withQstash = (fn) => __awaiter(void 0, void 0, void 0, function* () {
235
+ const qstash = yield ensureQstash();
236
+ if (!qstash) {
44
237
  return null;
45
238
  }
46
- cachedQstash = new Client({ token: QSTASH_TOKEN });
47
- return cachedQstash;
48
- };
239
+ return fn(qstash);
240
+ });
49
241
 
50
- export { getQstash, getRedis };
242
+ export { getQstash, getRedis, withQstash, withRedis };