@treeseed/sdk 0.8.14 → 0.8.15

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.
@@ -120,6 +120,8 @@ export declare class MarketClient {
120
120
  private readonly userAgent?;
121
121
  constructor(options: MarketClientOptions);
122
122
  private request;
123
+ private localAuthPaths;
124
+ private requestFirst;
123
125
  startDeviceLogin(request: DeviceCodeStartRequest): Promise<DeviceCodeStartResponse>;
124
126
  pollDeviceLogin(request: DeviceCodePollRequest): Promise<DeviceCodePollResponse>;
125
127
  refreshToken(request: TokenRefreshRequest): Promise<TokenRefreshResponse>;
@@ -33,6 +33,17 @@ function defaultCentralMarket() {
33
33
  alwaysAvailable: true
34
34
  };
35
35
  }
36
+ function defaultLocalMarket(env = process.env) {
37
+ return {
38
+ id: "local",
39
+ label: "Local TreeSeed Market",
40
+ baseUrl: normalizeBaseUrl(
41
+ envValue(TREESEED_MARKET_API_BASE_URL_ENV, env) ?? "http://127.0.0.1:3000"
42
+ ),
43
+ kind: "specialized",
44
+ alwaysAvailable: true
45
+ };
46
+ }
36
47
  function homeConfigPath() {
37
48
  const homeRoot = process.env.HOME && process.env.HOME.trim().length > 0 ? process.env.HOME : homedir();
38
49
  return resolve(homeRoot, MARKET_REGISTRY_RELATIVE_PATH);
@@ -140,6 +151,9 @@ function resolveMarketProfile(selector) {
140
151
  alwaysAvailable: false
141
152
  };
142
153
  }
154
+ if (trimmed === "local") {
155
+ return defaultLocalMarket();
156
+ }
143
157
  const marketId = trimmed || state.activeMarketId || "central";
144
158
  const profile = state.profiles.find((entry) => entry.id === marketId);
145
159
  if (!profile) {
@@ -263,20 +277,38 @@ class MarketClient {
263
277
  }
264
278
  return payload;
265
279
  }
280
+ localAuthPaths(v1Path, legacyPath) {
281
+ return this.options.profile.id === "local" ? [legacyPath, v1Path] : [v1Path];
282
+ }
283
+ async requestFirst(paths, options = {}) {
284
+ let notFound = null;
285
+ for (const path of paths) {
286
+ try {
287
+ return await this.request(path, options);
288
+ } catch (error) {
289
+ if (error instanceof MarketApiError && error.status === 404) {
290
+ notFound = error;
291
+ continue;
292
+ }
293
+ throw error;
294
+ }
295
+ }
296
+ throw notFound ?? new MarketApiError("Market request failed with 404.", 404, {});
297
+ }
266
298
  startDeviceLogin(request) {
267
- return this.request("/v1/auth/device/start", {
299
+ return this.requestFirst(this.localAuthPaths("/v1/auth/device/start", "/auth/device/start"), {
268
300
  method: "POST",
269
301
  body: request
270
302
  });
271
303
  }
272
304
  pollDeviceLogin(request) {
273
- return this.request("/v1/auth/device/poll", {
305
+ return this.requestFirst(this.localAuthPaths("/v1/auth/device/poll", "/auth/device/poll"), {
274
306
  method: "POST",
275
307
  body: request
276
308
  });
277
309
  }
278
310
  refreshToken(request) {
279
- return this.request("/v1/auth/token/refresh", {
311
+ return this.requestFirst(this.localAuthPaths("/v1/auth/token/refresh", "/auth/token/refresh"), {
280
312
  method: "POST",
281
313
  body: request
282
314
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.8.14",
3
+ "version": "0.8.15",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {