@drakkar.software/starfish-client 3.0.0-alpha.4 → 3.0.0-alpha.5

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/dist/index.js CHANGED
@@ -39,6 +39,7 @@ function encodeCapAuth(cap) {
39
39
  }
40
40
  var StarfishClient = class {
41
41
  baseUrl;
42
+ namespace;
42
43
  capProvider;
43
44
  fetch;
44
45
  /**
@@ -48,6 +49,7 @@ var StarfishClient = class {
48
49
  plugins;
49
50
  constructor(options) {
50
51
  this.baseUrl = options.baseUrl.replace(/\/$/, "");
52
+ this.namespace = options.namespace || void 0;
51
53
  this.capProvider = options.capProvider;
52
54
  this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
53
55
  this.plugins = options.plugins ? [...options.plugins] : [];
@@ -71,6 +73,20 @@ var StarfishClient = class {
71
73
  return "";
72
74
  }
73
75
  }
76
+ /**
77
+ * Rewrite a request path for the configured namespace. A no-op when no
78
+ * namespace is set; otherwise `/{action}/…` becomes `/v1/{namespace}/{action}/…`
79
+ * (the `/v1` protocol-version segment is part of the namespaced route, matching
80
+ * the Python client and the server's namespace mount).
81
+ *
82
+ * Applied to the path used for BOTH the signature and the URL so the canonical
83
+ * path the client signs equals the path the server reconstructs from the URL.
84
+ * Covers SDK-helper-built paths too — that's the point: a namespace-unaware
85
+ * helper passing `/push/spaces/x/_keyring` reaches `/v1/{ns}/push/spaces/x/_keyring`.
86
+ */
87
+ applyNamespace(path) {
88
+ return this.namespace ? `/v1/${this.namespace}${path}` : path;
89
+ }
74
90
  /**
75
91
  * Build auth headers for a request. When a `capProvider` is set, signs the
76
92
  * request with the device's Ed25519 private key and returns the v3 header
@@ -107,7 +123,7 @@ var StarfishClient = class {
107
123
  return {};
108
124
  }
109
125
  async pull(path, checkpointOrOptions) {
110
- let pathAndQuery = path;
126
+ let pathAndQuery = this.applyNamespace(path);
111
127
  let appendField;
112
128
  if (typeof checkpointOrOptions === "number") {
113
129
  if (checkpointOrOptions) pathAndQuery += `?checkpoint=${checkpointOrOptions}`;
@@ -166,8 +182,9 @@ var StarfishClient = class {
166
182
  data,
167
183
  baseHash
168
184
  });
169
- const authHeaders = await this.buildAuthHeaders("POST", path, body);
170
- const res = await this.fetch(`${this.baseUrl}${path}`, {
185
+ const sendPath = this.applyNamespace(path);
186
+ const authHeaders = await this.buildAuthHeaders("POST", sendPath, body);
187
+ const res = await this.fetch(`${this.baseUrl}${sendPath}`, {
171
188
  method: "POST",
172
189
  headers: {
173
190
  "Content-Type": "application/json",
@@ -205,8 +222,9 @@ var StarfishClient = class {
205
222
  const bodyObj = { data };
206
223
  if (opts.ts !== void 0) bodyObj["ts"] = opts.ts;
207
224
  const body = JSON.stringify(bodyObj);
208
- const authHeaders = await this.buildAuthHeaders("POST", path, body);
209
- const res = await this.fetch(`${this.baseUrl}${path}`, {
225
+ const sendPath = this.applyNamespace(path);
226
+ const authHeaders = await this.buildAuthHeaders("POST", sendPath, body);
227
+ const res = await this.fetch(`${this.baseUrl}${sendPath}`, {
210
228
  method: "POST",
211
229
  headers: {
212
230
  "Content-Type": "application/json",
@@ -225,8 +243,9 @@ var StarfishClient = class {
225
243
  * Returns raw bytes with the content hash from the ETag header.
226
244
  */
227
245
  async pullBlob(path) {
228
- const authHeaders = await this.buildAuthHeaders("GET", path, void 0);
229
- const res = await this.fetch(`${this.baseUrl}${path}`, {
246
+ const sendPath = this.applyNamespace(path);
247
+ const authHeaders = await this.buildAuthHeaders("GET", sendPath, void 0);
248
+ const res = await this.fetch(`${this.baseUrl}${sendPath}`, {
230
249
  method: "GET",
231
250
  headers: { Accept: "*/*", ...authHeaders }
232
251
  });
@@ -243,8 +262,9 @@ var StarfishClient = class {
243
262
  * Binary collections use last-write-wins (no conflict detection).
244
263
  */
245
264
  async pushBlob(path, data, contentType) {
246
- const authHeaders = await this.buildAuthHeaders("POST", path, void 0);
247
- const res = await this.fetch(`${this.baseUrl}${path}`, {
265
+ const sendPath = this.applyNamespace(path);
266
+ const authHeaders = await this.buildAuthHeaders("POST", sendPath, void 0);
267
+ const res = await this.fetch(`${this.baseUrl}${sendPath}`, {
248
268
  method: "POST",
249
269
  headers: {
250
270
  "Content-Type": contentType,