@reddb-io/client 1.10.0 → 1.11.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/url.js +21 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reddb-io/client",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Thin remote-only RedDB driver. Downloads the `red_client` binary on install. Speaks RedWire/gRPC/HTTP. Embedded URIs (memory://, file://, red:///path) are rejected — use @reddb-io/sdk for those.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/core/url.js CHANGED
@@ -189,17 +189,31 @@ export function parseLegacyUrl(uri) {
189
189
  || uri.startsWith('reds://')
190
190
  ) {
191
191
  const scheme = uri.split('://', 1)[0]
192
- const stripped = uri.slice(`${scheme}://`.length)
193
- const [hostPort] = stripped.split(/[/?]/, 1)
194
- const [host, portStr] = hostPort.split(':')
195
- if (!host) {
192
+ let parsed
193
+ try {
194
+ // Borrow the URL parser via an `https://` authority (same trick as
195
+ // parseRedWssUrl) so userinfo / host / port / query all decode with
196
+ // the standard rules — a naive `hostPort.split(':')` breaks on
197
+ // `reds://user:pass@host:5050` (host becomes `user`, port NaN).
198
+ parsed = new URL('https://' + uri.slice(`${scheme}://`.length))
199
+ } catch (err) {
200
+ throw new RedDBError('UNPARSEABLE_URI', `failed to parse '${uri}': ${err.message}`)
201
+ }
202
+ if (!parsed.hostname) {
196
203
  throw new TypeError(`invalid ${scheme}:// URI: missing host in '${uri}'`)
197
204
  }
198
- const legacyKind = scheme === 'reds' ? 'reds' : scheme === 'grpcs' ? 'grpcs' : scheme === 'grpc' ? 'grpc' : 'red'
205
+ const legacyKind = scheme === 'reds' ? 'reds' : scheme === 'grpcs' ? 'grpcs' : 'grpc'
206
+ const params = parsed.searchParams
199
207
  return {
200
208
  kind: legacyKind,
201
- host,
202
- port: portStr ? Number(portStr) : defaultPortFor(legacyKind),
209
+ host: parsed.hostname,
210
+ port: parsed.port ? Number(parsed.port) : defaultPortFor(legacyKind),
211
+ username: parsed.username ? decodeURIComponent(parsed.username) : undefined,
212
+ password: parsed.password ? decodeURIComponent(parsed.password) : undefined,
213
+ token: params.get('token') ?? undefined,
214
+ apiKey: params.get('apiKey') ?? params.get('api_key') ?? undefined,
215
+ loginUrl: params.get('loginUrl') ?? params.get('login_url') ?? undefined,
216
+ params,
203
217
  originalUri: uri,
204
218
  }
205
219
  }