@ascendkit/cli 0.2.0 → 0.3.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.
@@ -13,6 +13,7 @@ export declare class AscendKitClient {
13
13
  });
14
14
  get configured(): boolean;
15
15
  get currentPublicKey(): string | null;
16
+ get currentApiUrl(): string;
16
17
  get platformConfigured(): boolean;
17
18
  configure(publicKey: string, apiUrl?: string): void;
18
19
  configurePlatform(token: string, apiUrl?: string): void;
@@ -32,6 +33,7 @@ export declare class AscendKitClient {
32
33
  delete<T = unknown>(path: string): Promise<T>;
33
34
  /** Write operation requiring both public key and platform auth. */
34
35
  managedRequest<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
36
+ managedGet<T = unknown>(path: string): Promise<T>;
35
37
  managedPut<T = unknown>(path: string, body?: unknown): Promise<T>;
36
38
  managedPost<T = unknown>(path: string, body?: unknown): Promise<T>;
37
39
  managedDelete<T = unknown>(path: string): Promise<T>;
@@ -17,6 +17,30 @@ function readPackageVersion() {
17
17
  }
18
18
  }
19
19
  export const CLI_VERSION = readPackageVersion();
20
+ async function extractErrorMessage(response) {
21
+ const text = await response.text();
22
+ if (!text) {
23
+ return `AscendKit API error ${response.status}: ${response.statusText}`;
24
+ }
25
+ try {
26
+ const parsed = JSON.parse(text);
27
+ if (typeof parsed.error === "string") {
28
+ return parsed.error;
29
+ }
30
+ if (typeof parsed.detail === "string") {
31
+ return parsed.detail;
32
+ }
33
+ if (parsed.detail
34
+ && typeof parsed.detail === "object"
35
+ && typeof parsed.detail.message === "string") {
36
+ return parsed.detail.message;
37
+ }
38
+ }
39
+ catch {
40
+ // Fall back to the raw response body below.
41
+ }
42
+ return `AscendKit API error ${response.status}: ${text}`;
43
+ }
20
44
  export class AscendKitClient {
21
45
  baseUrl;
22
46
  publicKey;
@@ -33,6 +57,9 @@ export class AscendKitClient {
33
57
  get currentPublicKey() {
34
58
  return this.publicKey;
35
59
  }
60
+ get currentApiUrl() {
61
+ return this.baseUrl;
62
+ }
36
63
  get platformConfigured() {
37
64
  return this.platformToken !== null;
38
65
  }
@@ -105,8 +132,7 @@ export class AscendKitClient {
105
132
  const response = await fetch(url, init);
106
133
  this.checkUpgradeHeader(response);
107
134
  if (!response.ok) {
108
- const text = await response.text();
109
- throw new Error(`AscendKit API error ${response.status}: ${text}`);
135
+ throw new Error(await extractErrorMessage(response));
110
136
  }
111
137
  const json = (await response.json());
112
138
  return json.data;
@@ -123,8 +149,7 @@ export class AscendKitClient {
123
149
  const response = await fetch(url, init);
124
150
  this.checkUpgradeHeader(response);
125
151
  if (!response.ok) {
126
- const text = await response.text();
127
- throw new Error(`AscendKit API error ${response.status}: ${text}`);
152
+ throw new Error(await extractErrorMessage(response));
128
153
  }
129
154
  const json = (await response.json());
130
155
  return json.data;
@@ -142,8 +167,7 @@ export class AscendKitClient {
142
167
  const response = await fetch(url, init);
143
168
  this.checkUpgradeHeader(response);
144
169
  if (!response.ok) {
145
- const text = await response.text();
146
- throw new Error(`AscendKit API error ${response.status}: ${text}`);
170
+ throw new Error(await extractErrorMessage(response));
147
171
  }
148
172
  const json = (await response.json());
149
173
  return json.data;
@@ -173,12 +197,14 @@ export class AscendKitClient {
173
197
  const response = await fetch(url, init);
174
198
  this.checkUpgradeHeader(response);
175
199
  if (!response.ok) {
176
- const text = await response.text();
177
- throw new Error(`AscendKit API error ${response.status}: ${text}`);
200
+ throw new Error(await extractErrorMessage(response));
178
201
  }
179
202
  const json = (await response.json());
180
203
  return json.data;
181
204
  }
205
+ managedGet(path) {
206
+ return this.managedRequest("GET", path);
207
+ }
182
208
  managedPut(path, body) {
183
209
  return this.managedRequest("PUT", path, body);
184
210
  }