@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,195 +1,159 @@
1
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 { getRedis } from '../upstash-config.mjs';
2
+ import { withRedis } from '../upstash-config.mjs';
3
3
 
4
4
  /**
5
5
  * Set a plain string value with optional TTL (seconds).
6
6
  */
7
7
  const setString = (key, value, ttlSec) => __awaiter(void 0, void 0, void 0, function* () {
8
- const redis = getRedis();
9
- if (!redis) {
10
- return false;
11
- }
12
- if (ttlSec && ttlSec > 0) {
13
- yield redis.set(key, value, { ex: ttlSec });
8
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
9
+ if (ttlSec && ttlSec > 0) {
10
+ yield redis.set(key, value, { ex: ttlSec });
11
+ return true;
12
+ }
13
+ yield redis.set(key, value);
14
14
  return true;
15
- }
16
- yield redis.set(key, value);
17
- return true;
15
+ })).then((result) => result !== null && result !== void 0 ? result : false);
18
16
  });
19
17
  /**
20
18
  * Get a plain string value. Returns null if Redis is unavailable or key missing.
21
19
  */
22
20
  const getString = (key) => __awaiter(void 0, void 0, void 0, function* () {
23
- const redis = getRedis();
24
- if (!redis) {
25
- return null;
26
- }
27
- return redis.get(key);
21
+ return withRedis((redis) => redis.get(key));
28
22
  });
29
23
  /**
30
24
  * Store an object as JSON string with optional TTL (seconds).
31
25
  */
32
26
  const setJson = (key, value, ttlSec) => __awaiter(void 0, void 0, void 0, function* () {
33
- const redis = getRedis();
34
- if (!redis) {
35
- return false;
36
- }
37
- const payload = JSON.stringify(value);
38
- if (ttlSec && ttlSec > 0) {
39
- yield redis.set(key, payload, { ex: ttlSec });
27
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const payload = JSON.stringify(value);
29
+ if (ttlSec && ttlSec > 0) {
30
+ yield redis.set(key, payload, { ex: ttlSec });
31
+ return true;
32
+ }
33
+ yield redis.set(key, payload);
40
34
  return true;
41
- }
42
- yield redis.set(key, payload);
43
- return true;
35
+ })).then((result) => result !== null && result !== void 0 ? result : false);
44
36
  });
45
37
  /**
46
38
  * Get an object stored as JSON string. Returns null if missing or invalid JSON.
47
39
  */
48
40
  const getJson = (key) => __awaiter(void 0, void 0, void 0, function* () {
49
- const redis = getRedis();
50
- if (!redis) {
51
- return null;
52
- }
53
- const payload = yield redis.get(key);
54
- if (!payload) {
55
- return null;
56
- }
57
- try {
58
- return JSON.parse(payload);
59
- }
60
- catch (_a) {
61
- return null;
62
- }
41
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
42
+ const payload = yield redis.get(key);
43
+ if (!payload) {
44
+ return null;
45
+ }
46
+ try {
47
+ return JSON.parse(payload);
48
+ }
49
+ catch (_a) {
50
+ return null;
51
+ }
52
+ }));
63
53
  });
64
54
  /**
65
55
  * Delete a key. Returns false if Redis is unavailable.
66
56
  */
67
57
  const deleteKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
68
- const redis = getRedis();
69
- if (!redis) {
70
- return false;
71
- }
72
- const deleted = yield redis.del(key);
73
- return deleted > 0;
58
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
59
+ const deleted = yield redis.del(key);
60
+ return deleted > 0;
61
+ }));
62
+ return result !== null && result !== void 0 ? result : false;
74
63
  });
75
64
  /**
76
65
  * Set a hash field value.
77
66
  */
78
67
  const setHashField = (key, field, value) => __awaiter(void 0, void 0, void 0, function* () {
79
- const redis = getRedis();
80
- if (!redis) {
81
- return false;
82
- }
83
- const result = yield redis.hset(key, { [field]: value });
84
- return result > 0;
68
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
69
+ const changed = yield redis.hset(key, { [field]: value });
70
+ return changed > 0;
71
+ }));
72
+ return result !== null && result !== void 0 ? result : false;
85
73
  });
86
74
  /**
87
75
  * Get a hash field value.
88
76
  */
89
77
  const getHashField = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
90
- const redis = getRedis();
91
- if (!redis) {
92
- return null;
93
- }
94
- return redis.hget(key, field);
78
+ return withRedis((redis) => redis.hget(key, field));
95
79
  });
96
80
  /**
97
81
  * Store a hash field as JSON string.
98
82
  */
99
83
  const setHashJson = (key, field, value) => __awaiter(void 0, void 0, void 0, function* () {
100
- const redis = getRedis();
101
- if (!redis) {
102
- return false;
103
- }
104
- const payload = JSON.stringify(value);
105
- const result = yield redis.hset(key, { [field]: payload });
106
- return result > 0;
84
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
85
+ const payload = JSON.stringify(value);
86
+ const changed = yield redis.hset(key, { [field]: payload });
87
+ return changed > 0;
88
+ }));
89
+ return result !== null && result !== void 0 ? result : false;
107
90
  });
108
91
  /**
109
92
  * Get a hash field stored as JSON string.
110
93
  */
111
94
  const getHashJson = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
112
- const redis = getRedis();
113
- if (!redis) {
114
- return null;
115
- }
116
- const payload = yield redis.hget(key, field);
117
- if (!payload) {
118
- return null;
119
- }
120
- try {
121
- return JSON.parse(payload);
122
- }
123
- catch (_a) {
124
- return null;
125
- }
95
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
96
+ const payload = yield redis.hget(key, field);
97
+ if (!payload) {
98
+ return null;
99
+ }
100
+ try {
101
+ return JSON.parse(payload);
102
+ }
103
+ catch (_a) {
104
+ return null;
105
+ }
106
+ }));
126
107
  });
127
108
  /**
128
109
  * Get all hash fields.
129
110
  */
130
111
  const getHashAll = (key) => __awaiter(void 0, void 0, void 0, function* () {
131
- const redis = getRedis();
132
- if (!redis) {
133
- return null;
134
- }
135
- const result = yield redis.hgetall(key);
136
- return result !== null && result !== void 0 ? result : {};
112
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
113
+ const result = yield redis.hgetall(key);
114
+ return result !== null && result !== void 0 ? result : {};
115
+ }));
137
116
  });
138
117
  /**
139
118
  * Remove a hash field.
140
119
  */
141
120
  const deleteHashField = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
142
- const redis = getRedis();
143
- if (!redis) {
144
- return false;
145
- }
146
- const removed = yield redis.hdel(key, field);
147
- return removed > 0;
121
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
122
+ const removed = yield redis.hdel(key, field);
123
+ return removed > 0;
124
+ }));
125
+ return result !== null && result !== void 0 ? result : false;
148
126
  });
149
127
  /**
150
128
  * Push values to a list. Returns list length or null if Redis is unavailable.
151
129
  */
152
130
  const pushList = (key_1, values_1, ...args_1) => __awaiter(void 0, [key_1, values_1, ...args_1], void 0, function* (key, values, direction = 'right') {
153
- const redis = getRedis();
154
- if (!redis) {
155
- return null;
156
- }
157
- if (values.length === 0) {
158
- return redis.llen(key);
159
- }
160
- return direction === 'left'
161
- ? redis.lpush(key, ...values)
162
- : redis.rpush(key, ...values);
131
+ return withRedis((redis) => {
132
+ if (values.length === 0) {
133
+ return redis.llen(key);
134
+ }
135
+ return direction === 'left'
136
+ ? redis.lpush(key, ...values)
137
+ : redis.rpush(key, ...values);
138
+ });
163
139
  });
164
140
  /**
165
141
  * Pop a value from a list.
166
142
  */
167
143
  const popList = (key_1, ...args_1) => __awaiter(void 0, [key_1, ...args_1], void 0, function* (key, direction = 'right') {
168
- const redis = getRedis();
169
- if (!redis) {
170
- return null;
171
- }
172
- return direction === 'left' ? redis.lpop(key) : redis.rpop(key);
144
+ return withRedis((redis) => direction === 'left' ? redis.lpop(key) : redis.rpop(key));
173
145
  });
174
146
  /**
175
147
  * Get a range from a list.
176
148
  */
177
149
  const rangeList = (key_1, ...args_1) => __awaiter(void 0, [key_1, ...args_1], void 0, function* (key, start = 0, stop = -1) {
178
- const redis = getRedis();
179
- if (!redis) {
180
- return null;
181
- }
182
- return redis.lrange(key, start, stop);
150
+ return withRedis((redis) => redis.lrange(key, start, stop));
183
151
  });
184
152
  /**
185
153
  * Get list length.
186
154
  */
187
155
  const listLength = (key) => __awaiter(void 0, void 0, void 0, function* () {
188
- const redis = getRedis();
189
- if (!redis) {
190
- return null;
191
- }
192
- return redis.llen(key);
156
+ return withRedis((redis) => redis.llen(key));
193
157
  });
194
158
 
195
159
  export { deleteHashField, deleteKey, getHashAll, getHashField, getHashJson, getJson, getString, listLength, popList, pushList, rangeList, setHashField, setHashJson, setJson, setString };
@@ -1,11 +1,19 @@
1
1
  import { Redis } from '@upstash/redis';
2
2
  import { Client as QstashClient } from '@upstash/qstash';
3
3
  /**
4
- * Get the Upstash Redis client. Returns null when required env vars are missing.
4
+ * Get the Upstash Redis client. Returns null when required env vars are missing/invalid.
5
+ *
6
+ * Singleton semantics:
7
+ * - read-through cached instance only
5
8
  */
6
9
  export declare const getRedis: () => Redis | null;
7
10
  /**
8
11
  * Get the Upstash QStash client. Returns null when required env vars are missing.
12
+ *
13
+ * Singleton semantics:
14
+ * - read-through cached instance only
9
15
  */
10
16
  export declare const getQstash: () => QstashClient | null;
17
+ export declare const withRedis: <T>(fn: (redis: Redis) => Promise<T> | T) => Promise<T | null>;
18
+ export declare const withQstash: <T>(fn: (qstash: QstashClient) => Promise<T> | T) => Promise<T | null>;
11
19
  //# sourceMappingURL=upstash-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upstash-config.d.ts","sourceRoot":"","sources":["../../src/lib/upstash-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAOzD;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAO,KAAK,GAAG,IAoBnC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,QAAO,YAAY,GAAG,IAiB3C,CAAC"}
1
+ {"version":3,"file":"upstash-config.d.ts","sourceRoot":"","sources":["../../src/lib/upstash-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAoIzD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,QAAO,KAAK,GAAG,IAEnC,CAAC;AAsDF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,QAAO,YAAY,GAAG,IAE3C,CAAC;AAyCF,eAAO,MAAM,SAAS,GAAU,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAMzF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,CAAC,EAChC,IAAI,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAC3C,OAAO,CAAC,CAAC,GAAG,IAAI,CAMlB,CAAC"}
@@ -1,53 +1,247 @@
1
1
  'use strict';
2
2
 
3
- var nodejs = require('../node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.js');
4
- var chunkRQPZUJXG = require('../node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.js');
3
+ var tslib_es6 = require('../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.js');
4
+ var nodejs = require('../node_modules/.pnpm/@upstash_redis@1.37.0/node_modules/@upstash/redis/nodejs.js');
5
+ var chunk35B33QW3 = require('../node_modules/.pnpm/@upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.js');
5
6
 
6
7
  let cachedRedis = null;
7
8
  let cachedQstash = null;
8
- let redisInitAttempted = false;
9
- let qstashInitAttempted = false;
9
+ let redisInitPromise = null;
10
+ let qstashInitPromise = null;
11
+ let redisWarnedMissingEnv = false;
12
+ let redisWarnedInvalidEnv = false;
13
+ let redisWarnedInitError = false;
14
+ let redisWarnedHealthCheck = false;
15
+ let redisWarnedHealthSchedule = false;
16
+ let qstashWarnedMissingEnv = false;
17
+ let qstashWarnedInitError = false;
18
+ let qstashWarnedHealthCheck = false;
19
+ let qstashWarnedHealthSchedule = false;
20
+ let redisHealthTimer = null;
21
+ let qstashHealthTimer = null;
22
+ const isNonEmpty = (value) => typeof value === 'string' && value.trim().length > 0;
23
+ const isValidUrl = (value) => {
24
+ try {
25
+ const parsed = new URL(value);
26
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:';
27
+ }
28
+ catch (_a) {
29
+ return false;
30
+ }
31
+ };
32
+ const parseMinutes = (value, fallback) => {
33
+ if (!isNonEmpty(value)) {
34
+ return fallback;
35
+ }
36
+ const minutes = Number(value);
37
+ if (!Number.isFinite(minutes) || minutes <= 0) {
38
+ return fallback;
39
+ }
40
+ return minutes;
41
+ };
42
+ const getRedisHealthIntervalMinutes = () => parseMinutes(process.env.UPSTASH_REDIS_HEALTHCHECK_INTERVAL_MINUTES, 10);
43
+ const getQstashHealthIntervalMinutes = () => parseMinutes(process.env.UPSTASH_QSTASH_HEALTHCHECK_INTERVAL_MINUTES, 10);
44
+ const getQstashHealthcheckUrl = () => { var _a; return (_a = process.env.UPSTASH_QSTASH_HEALTHCHECK_URL) !== null && _a !== void 0 ? _a : 'https://qstash.upstash.io/v2/topics'; };
45
+ const scheduleRedisHealthCheck = () => {
46
+ if (redisHealthTimer || !cachedRedis) {
47
+ return;
48
+ }
49
+ const delayMs = getRedisHealthIntervalMinutes() * 60000;
50
+ redisHealthTimer = setTimeout(() => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
51
+ redisHealthTimer = null;
52
+ if (!cachedRedis) {
53
+ return;
54
+ }
55
+ try {
56
+ yield cachedRedis.ping();
57
+ }
58
+ catch (error) {
59
+ cachedRedis = null;
60
+ if (!redisWarnedHealthCheck) {
61
+ redisWarnedHealthCheck = true;
62
+ const message = error instanceof Error ? error.message : String(error);
63
+ console.warn(`[Upstash Config] Redis health check failed: ${message}`);
64
+ }
65
+ }
66
+ finally {
67
+ try {
68
+ scheduleRedisHealthCheck();
69
+ }
70
+ catch (error) {
71
+ if (!redisWarnedHealthSchedule) {
72
+ redisWarnedHealthSchedule = true;
73
+ const message = error instanceof Error ? error.message : String(error);
74
+ console.warn(`[Upstash Config] Redis health check schedule failed: ${message}`);
75
+ }
76
+ }
77
+ }
78
+ }), delayMs);
79
+ };
80
+ const checkQstashHealth = (token) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
81
+ const response = yield fetch(getQstashHealthcheckUrl(), {
82
+ method: 'GET',
83
+ headers: {
84
+ Authorization: `Bearer ${token}`,
85
+ },
86
+ cache: 'no-store',
87
+ });
88
+ if (!response.ok) {
89
+ throw new Error(`HTTP ${response.status}`);
90
+ }
91
+ });
92
+ const scheduleQstashHealthCheck = (token) => {
93
+ if (qstashHealthTimer || !cachedQstash) {
94
+ return;
95
+ }
96
+ const delayMs = getQstashHealthIntervalMinutes() * 60000;
97
+ qstashHealthTimer = setTimeout(() => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
98
+ qstashHealthTimer = null;
99
+ if (!cachedQstash) {
100
+ return;
101
+ }
102
+ try {
103
+ yield checkQstashHealth(token);
104
+ }
105
+ catch (error) {
106
+ cachedQstash = null;
107
+ if (!qstashWarnedHealthCheck) {
108
+ qstashWarnedHealthCheck = true;
109
+ const message = error instanceof Error ? error.message : String(error);
110
+ console.warn(`[Upstash Config] QStash health check failed: ${message}`);
111
+ }
112
+ }
113
+ finally {
114
+ try {
115
+ scheduleQstashHealthCheck(token);
116
+ }
117
+ catch (error) {
118
+ if (!qstashWarnedHealthSchedule) {
119
+ qstashWarnedHealthSchedule = true;
120
+ const message = error instanceof Error ? error.message : String(error);
121
+ console.warn(`[Upstash Config] QStash health check schedule failed: ${message}`);
122
+ }
123
+ }
124
+ }
125
+ }), delayMs);
126
+ };
10
127
  /**
11
- * Get the Upstash Redis client. Returns null when required env vars are missing.
128
+ * Get the Upstash Redis client. Returns null when required env vars are missing/invalid.
129
+ *
130
+ * Singleton semantics:
131
+ * - read-through cached instance only
12
132
  */
13
133
  const getRedis = () => {
134
+ return cachedRedis;
135
+ };
136
+ const ensureRedis = () => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
14
137
  if (cachedRedis) {
15
138
  return cachedRedis;
16
139
  }
17
- if (redisInitAttempted) {
18
- return null;
19
- }
20
- redisInitAttempted = true;
21
- const { UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN } = process.env;
22
- if (!UPSTASH_REDIS_REST_URL || !UPSTASH_REDIS_REST_TOKEN) {
23
- console.warn('[Upstash Config] Redis Missed configration UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN, then disabled');
24
- return null;
140
+ if (redisInitPromise) {
141
+ return redisInitPromise;
25
142
  }
26
- cachedRedis = new nodejs.Redis({
27
- url: UPSTASH_REDIS_REST_URL,
28
- token: UPSTASH_REDIS_REST_TOKEN,
29
- });
30
- return cachedRedis;
31
- };
143
+ redisInitPromise = (() => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
144
+ const { UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN } = process.env;
145
+ if (!isNonEmpty(UPSTASH_REDIS_REST_URL) || !isNonEmpty(UPSTASH_REDIS_REST_TOKEN)) {
146
+ if (!redisWarnedMissingEnv) {
147
+ redisWarnedMissingEnv = true;
148
+ console.warn('[Upstash Config] Redis disabled: missing UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN');
149
+ }
150
+ return null;
151
+ }
152
+ if (!isValidUrl(UPSTASH_REDIS_REST_URL)) {
153
+ if (!redisWarnedInvalidEnv) {
154
+ redisWarnedInvalidEnv = true;
155
+ console.warn('[Upstash Config] Redis disabled: UPSTASH_REDIS_REST_URL is not a valid URL');
156
+ }
157
+ return null;
158
+ }
159
+ try {
160
+ const client = new nodejs.Redis({
161
+ url: UPSTASH_REDIS_REST_URL,
162
+ token: UPSTASH_REDIS_REST_TOKEN,
163
+ });
164
+ yield client.ping();
165
+ cachedRedis = client;
166
+ scheduleRedisHealthCheck();
167
+ return cachedRedis;
168
+ }
169
+ catch (error) {
170
+ if (!redisWarnedInitError) {
171
+ redisWarnedInitError = true;
172
+ const message = error instanceof Error ? error.message : String(error);
173
+ console.warn(`[Upstash Config] Redis init failed: ${message}`);
174
+ }
175
+ return null;
176
+ }
177
+ finally {
178
+ redisInitPromise = null;
179
+ }
180
+ }))();
181
+ return redisInitPromise;
182
+ });
32
183
  /**
33
184
  * Get the Upstash QStash client. Returns null when required env vars are missing.
185
+ *
186
+ * Singleton semantics:
187
+ * - read-through cached instance only
34
188
  */
35
189
  const getQstash = () => {
190
+ return cachedQstash;
191
+ };
192
+ const ensureQstash = () => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
36
193
  if (cachedQstash) {
37
194
  return cachedQstash;
38
195
  }
39
- if (qstashInitAttempted) {
196
+ if (qstashInitPromise) {
197
+ return qstashInitPromise;
198
+ }
199
+ qstashInitPromise = (() => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
200
+ const { QSTASH_TOKEN } = process.env;
201
+ if (!isNonEmpty(QSTASH_TOKEN)) {
202
+ if (!qstashWarnedMissingEnv) {
203
+ qstashWarnedMissingEnv = true;
204
+ console.warn('[Upstash Config] QStash disabled: missing QSTASH_TOKEN');
205
+ }
206
+ return null;
207
+ }
208
+ try {
209
+ const client = new chunk35B33QW3.Client({ token: QSTASH_TOKEN });
210
+ yield checkQstashHealth(QSTASH_TOKEN);
211
+ cachedQstash = client;
212
+ scheduleQstashHealthCheck(QSTASH_TOKEN);
213
+ return cachedQstash;
214
+ }
215
+ catch (error) {
216
+ if (!qstashWarnedInitError) {
217
+ qstashWarnedInitError = true;
218
+ const message = error instanceof Error ? error.message : String(error);
219
+ console.warn(`[Upstash Config] QStash init failed: ${message}`);
220
+ }
221
+ return null;
222
+ }
223
+ finally {
224
+ qstashInitPromise = null;
225
+ }
226
+ }))();
227
+ return qstashInitPromise;
228
+ });
229
+ const withRedis = (fn) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
230
+ const redis = yield ensureRedis();
231
+ if (!redis) {
40
232
  return null;
41
233
  }
42
- qstashInitAttempted = true;
43
- const { QSTASH_TOKEN } = process.env;
44
- if (!QSTASH_TOKEN) {
45
- console.warn('[Upstash Config] QStash Missed configration QSTASH_TOKEN, then disabled');
234
+ return fn(redis);
235
+ });
236
+ const withQstash = (fn) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
237
+ const qstash = yield ensureQstash();
238
+ if (!qstash) {
46
239
  return null;
47
240
  }
48
- cachedQstash = new chunkRQPZUJXG.Client({ token: QSTASH_TOKEN });
49
- return cachedQstash;
50
- };
241
+ return fn(qstash);
242
+ });
51
243
 
52
244
  exports.getQstash = getQstash;
53
245
  exports.getRedis = getRedis;
246
+ exports.withQstash = withQstash;
247
+ exports.withRedis = withRedis;