@juspay/neurolink 13.12.6 → 13.13.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/CHANGELOG.md CHANGED
@@ -1,8 +1,8 @@
1
- ## [13.12.6](https://github.com/juspay/neurolink/compare/v13.12.5...v13.12.6) (2026-11-18)
1
+ ## [13.13.1](https://github.com/juspay/neurolink/compare/v13.13.0...v13.13.1) (2026-11-18)
2
2
 
3
3
  ### Bug Fixes
4
4
 
5
- - **(openai-compat):** throw on truncated or errored SSE streams ([#2042](https://github.com/juspay/neurolink/issues/2042)) ([28cfaa1](https://github.com/juspay/neurolink/commit/28cfaa105ff4652592d724b88d3202198890ae3a))
5
+ - **(codex):** prevent login overwrite and key refresh single-flight by token ([#2046](https://github.com/juspay/neurolink/issues/2046)) ([93915a3](https://github.com/juspay/neurolink/commit/93915a3621b73e4ee651e939fc1c93ce57e082e0))
6
6
 
7
7
  ## [11.2.3](https://github.com/juspay/neurolink/compare/v11.2.2...v11.2.3) (2026-08-19)
8
8
 
@@ -1,6 +1,7 @@
1
1
  import WebSocket from "ws";
2
2
  import { EventEmitter } from "events";
3
3
  import { logger } from "../../utils/logger.js";
4
+ import { assertWebSocketProxyPolicy } from "../../proxy/proxyFetch.js";
4
5
  import { withTimeout } from "../../utils/async/withTimeout.js";
5
6
  export function getCartesiaWsUrl() {
6
7
  const baseUrl = process.env.CARTESIA_WS_BASE_URL ?? "wss://api.cartesia.ai/tts/websocket";
@@ -20,7 +21,9 @@ export class CartesiaStream extends EventEmitter {
20
21
  if (!apiKey) {
21
22
  throw new Error("CARTESIA_API_KEY is not set in environment");
22
23
  }
23
- this.ws = new WebSocket(getCartesiaWsUrl(), {
24
+ const wsUrl = getCartesiaWsUrl();
25
+ assertWebSocketProxyPolicy(wsUrl, "Cartesia TTS");
26
+ this.ws = new WebSocket(wsUrl, {
24
27
  headers: { "X-API-Key": apiKey },
25
28
  });
26
29
  this.ws.on("open", () => {
@@ -85,6 +85,16 @@ export declare class TokenStore {
85
85
  * @throws TokenStoreError if storage fails
86
86
  */
87
87
  saveTokens(provider: string, tokens: StoredOAuthTokens): Promise<void>;
88
+ /**
89
+ * Saves tokens only when `guard` approves the provider inventory read under
90
+ * the same cross-process lock as the write (compare-and-set). The guard may
91
+ * throw to refuse with a specific error. Returns false when it declines.
92
+ *
93
+ * @param options.enable - Also clear the disabled flag, as a fresh login does.
94
+ */
95
+ saveTokensIf(provider: string, tokens: StoredOAuthTokens, guard: (providers: TokenStorageData["providers"]) => boolean, options?: {
96
+ enable?: boolean;
97
+ }): Promise<boolean>;
88
98
  /**
89
99
  * Internal save without mutex — callers must already hold the mutex.
90
100
  */
@@ -142,6 +142,42 @@ export class TokenStore {
142
142
  await this._saveTokensInternal(provider, tokens);
143
143
  }));
144
144
  }
145
+ /**
146
+ * Saves tokens only when `guard` approves the provider inventory read under
147
+ * the same cross-process lock as the write (compare-and-set). The guard may
148
+ * throw to refuse with a specific error. Returns false when it declines.
149
+ *
150
+ * @param options.enable - Also clear the disabled flag, as a fresh login does.
151
+ */
152
+ async saveTokensIf(provider, tokens, guard, options = {}) {
153
+ return this.runExclusiveLocked(async () => {
154
+ let providers;
155
+ try {
156
+ providers = (await this.loadStorageData()).providers;
157
+ }
158
+ catch (error) {
159
+ if (!(error instanceof TokenStoreError && error.code === "NOT_FOUND")) {
160
+ throw error;
161
+ }
162
+ providers = {};
163
+ }
164
+ if (!guard(providers)) {
165
+ return false;
166
+ }
167
+ await this._saveTokensInternal(provider, tokens);
168
+ if (options.enable) {
169
+ const storageData = await this.loadStorageData();
170
+ const entry = storageData.providers[provider];
171
+ if (entry) {
172
+ entry.disabled = false;
173
+ delete entry.disabledAt;
174
+ delete entry.disabledReason;
175
+ await this.saveStorageData(storageData);
176
+ }
177
+ }
178
+ return true;
179
+ });
180
+ }
145
181
  /**
146
182
  * Internal save without mutex — callers must already hold the mutex.
147
183
  */