@astratra/security 1.9.0 → 1.9.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astratra/security",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "Generic authentication and security middleware for Astratra workspaces.",
5
5
  "engines": {
6
6
  "node": ">=20"
@@ -121,10 +121,6 @@ const createRedisStore = (redisUrl, prefix) => {
121
121
  client.on('error', () => {});
122
122
  }
123
123
 
124
- const redisStore = new RedisStore({
125
- ...(prefix ? { prefix } : {}),
126
- sendCommand: (...args) => client.sendCommand(args)
127
- });
128
124
  const memoryStore = createMemoryStore();
129
125
  const connectPromise = Promise.resolve(client.connect()).catch(() => {
130
126
  if (client && client.isOpen && typeof client.disconnect === 'function') {
@@ -133,6 +129,29 @@ const createRedisStore = (redisUrl, prefix) => {
133
129
  throw new Error('Redis rate limit store unavailable');
134
130
  });
135
131
 
132
+ /* Une promesse qui se resout toujours : elle dit si la connexion a abouti,
133
+ elle n'echoue jamais. Sans elle, chaque commande en attente deviendrait
134
+ un second consommateur de connectPromise, et donc un second rejet. */
135
+ const connected = connectPromise.then(() => true, () => false);
136
+
137
+ /* rate-limit-redis charge son script d'increment DEPUIS son constructeur,
138
+ avant que la connexion soit ouverte, et n'attend pas la promesse qu'il
139
+ obtient. Envoyer directement rejetait donc contre un client ferme, et ce
140
+ rejet n'appartenait a personne : Node tuait le processus au demarrage,
141
+ meme avec un Redis parfaitement disponible.
142
+
143
+ Attendre ici transforme cette premiere commande en commande mise en file.
144
+ Et quand la connexion a echoue, le failover a deja bascule sur le store
145
+ memoire : ce store-ci ne sera jamais interroge, sa commande de demarrage
146
+ n'a plus rien a envoyer et se resout sans rien casser. */
147
+ const redisStore = new RedisStore({
148
+ ...(prefix ? { prefix } : {}),
149
+ sendCommand: async (...args) => {
150
+ if (!(await connected)) return undefined;
151
+ return client.sendCommand(args);
152
+ }
153
+ });
154
+
136
155
  return createFailoverStore(redisStore, memoryStore, connectPromise);
137
156
  } catch (_error) {
138
157
  return createMemoryStore() || undefined;