xmemory 3.8.2 → 3.8.3

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.
@@ -62,6 +62,16 @@ export declare class XmemoryClient {
62
62
  checkHealth(): Promise<void>;
63
63
  private _fetch;
64
64
  private _headers;
65
+ /**
66
+ * The request URL for `path`, honouring whatever the configured base carries.
67
+ *
68
+ * Composed through `URL` rather than concatenated. Concatenation put the API path
69
+ * inside the query of a base that had one (`https://host?tenant=x` requested `/`),
70
+ * and appended a second `?` for request parameters. A plain `new URL(path, base)`
71
+ * is not the fix either: it drops a base path prefix, so a gateway base like
72
+ * `https://gw.example/xmemory` would lose `/xmemory`.
73
+ */
74
+ private _requestUrl;
65
75
  /** Core request — returns the raw API wrapper `{ids, items, errors}`. */
66
76
  private _request;
67
77
  private _requestOne;
@@ -158,24 +158,32 @@ class XmemoryClient {
158
158
  h["Authorization"] = `Bearer ${this._apiKey}`;
159
159
  return h;
160
160
  }
161
- /** Core request — returns the raw API wrapper `{ids, items, errors}`. */
162
- async _request(method, path, options) {
163
- let url = `${this._baseUrl}${path}`;
164
- if (options?.params) {
165
- const sp = new URLSearchParams();
166
- for (const [key, val] of Object.entries(options.params)) {
167
- if (Array.isArray(val)) {
168
- for (const v of val)
169
- sp.append(key, v);
170
- }
171
- else {
172
- sp.append(key, val);
173
- }
161
+ /**
162
+ * The request URL for `path`, honouring whatever the configured base carries.
163
+ *
164
+ * Composed through `URL` rather than concatenated. Concatenation put the API path
165
+ * inside the query of a base that had one (`https://host?tenant=x` requested `/`),
166
+ * and appended a second `?` for request parameters. A plain `new URL(path, base)`
167
+ * is not the fix either: it drops a base path prefix, so a gateway base like
168
+ * `https://gw.example/xmemory` would lose `/xmemory`.
169
+ */
170
+ _requestUrl(path, params) {
171
+ const url = new URL(this._baseUrl);
172
+ url.pathname = `${url.pathname.replace(/\/+$/, "")}${path}`;
173
+ for (const [key, val] of Object.entries(params ?? {})) {
174
+ if (Array.isArray(val)) {
175
+ for (const v of val)
176
+ url.searchParams.append(key, v);
177
+ }
178
+ else {
179
+ url.searchParams.append(key, val);
174
180
  }
175
- const qs = sp.toString();
176
- if (qs)
177
- url += `?${qs}`;
178
181
  }
182
+ return url.toString();
183
+ }
184
+ /** Core request — returns the raw API wrapper `{ids, items, errors}`. */
185
+ async _request(method, path, options) {
186
+ const url = this._requestUrl(path, options?.params);
179
187
  const timeoutMs = options?.timeoutMs ?? this._timeoutMs;
180
188
  const hasBody = !!(options?.body && method !== "GET");
181
189
  const init = { method, headers: this._headers(hasBody) };
@@ -62,6 +62,16 @@ export declare class XmemoryClient {
62
62
  checkHealth(): Promise<void>;
63
63
  private _fetch;
64
64
  private _headers;
65
+ /**
66
+ * The request URL for `path`, honouring whatever the configured base carries.
67
+ *
68
+ * Composed through `URL` rather than concatenated. Concatenation put the API path
69
+ * inside the query of a base that had one (`https://host?tenant=x` requested `/`),
70
+ * and appended a second `?` for request parameters. A plain `new URL(path, base)`
71
+ * is not the fix either: it drops a base path prefix, so a gateway base like
72
+ * `https://gw.example/xmemory` would lose `/xmemory`.
73
+ */
74
+ private _requestUrl;
65
75
  /** Core request — returns the raw API wrapper `{ids, items, errors}`. */
66
76
  private _request;
67
77
  private _requestOne;
@@ -154,24 +154,32 @@ export class XmemoryClient {
154
154
  h["Authorization"] = `Bearer ${this._apiKey}`;
155
155
  return h;
156
156
  }
157
- /** Core request — returns the raw API wrapper `{ids, items, errors}`. */
158
- async _request(method, path, options) {
159
- let url = `${this._baseUrl}${path}`;
160
- if (options?.params) {
161
- const sp = new URLSearchParams();
162
- for (const [key, val] of Object.entries(options.params)) {
163
- if (Array.isArray(val)) {
164
- for (const v of val)
165
- sp.append(key, v);
166
- }
167
- else {
168
- sp.append(key, val);
169
- }
157
+ /**
158
+ * The request URL for `path`, honouring whatever the configured base carries.
159
+ *
160
+ * Composed through `URL` rather than concatenated. Concatenation put the API path
161
+ * inside the query of a base that had one (`https://host?tenant=x` requested `/`),
162
+ * and appended a second `?` for request parameters. A plain `new URL(path, base)`
163
+ * is not the fix either: it drops a base path prefix, so a gateway base like
164
+ * `https://gw.example/xmemory` would lose `/xmemory`.
165
+ */
166
+ _requestUrl(path, params) {
167
+ const url = new URL(this._baseUrl);
168
+ url.pathname = `${url.pathname.replace(/\/+$/, "")}${path}`;
169
+ for (const [key, val] of Object.entries(params ?? {})) {
170
+ if (Array.isArray(val)) {
171
+ for (const v of val)
172
+ url.searchParams.append(key, v);
173
+ }
174
+ else {
175
+ url.searchParams.append(key, val);
170
176
  }
171
- const qs = sp.toString();
172
- if (qs)
173
- url += `?${qs}`;
174
177
  }
178
+ return url.toString();
179
+ }
180
+ /** Core request — returns the raw API wrapper `{ids, items, errors}`. */
181
+ async _request(method, path, options) {
182
+ const url = this._requestUrl(path, options?.params);
175
183
  const timeoutMs = options?.timeoutMs ?? this._timeoutMs;
176
184
  const hasBody = !!(options?.body && method !== "GET");
177
185
  const init = { method, headers: this._headers(hasBody) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmemory",
3
- "version": "3.8.2",
3
+ "version": "3.8.3",
4
4
  "description": "xmemory",
5
5
  "keywords": [
6
6
  "xmemory"