@zenadmin-ai/sdk 0.3.0 → 0.3.1
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/auth.d.ts +5 -0
- package/dist/client.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.js +15 -3
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface ResolvedCredentials {
|
|
|
8
8
|
source: "option" | "environment" | "file" | null;
|
|
9
9
|
/** The credentials file is readable by other users. */
|
|
10
10
|
insecureFile: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Set when a saved token was not used because it was saved for another API URL (this one): the
|
|
13
|
+
* token is never sent anywhere else.
|
|
14
|
+
*/
|
|
15
|
+
savedTokenUrl?: string;
|
|
11
16
|
}
|
|
12
17
|
/** Only http(s) origins; the agent API path is added by the client. */
|
|
13
18
|
export declare function normaliseApiUrl(value: string): string;
|
package/dist/client.d.ts
CHANGED
package/dist/errors.d.ts
CHANGED
|
@@ -48,6 +48,6 @@ export declare class NetworkError extends ZenAdminError {
|
|
|
48
48
|
}
|
|
49
49
|
/** No token was configured. */
|
|
50
50
|
export declare class NotSignedInError extends ZenAdminError {
|
|
51
|
-
constructor();
|
|
51
|
+
constructor(message?: string);
|
|
52
52
|
}
|
|
53
53
|
export declare function errorFromResponse(status: number, body: unknown, requestId: string | null, retryAfter: string | null): ZenAdminError;
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,15 @@ async function resolveCredentials(options = {}, env = process.env) {
|
|
|
45
45
|
return { token: env.ZENADMIN_TOKEN, apiUrl, source: "environment", insecureFile: false };
|
|
46
46
|
}
|
|
47
47
|
if (stored.creds) {
|
|
48
|
+
let savedFor;
|
|
49
|
+
try {
|
|
50
|
+
savedFor = normaliseApiUrl(stored.creds.api_url || DEFAULT_API_URL);
|
|
51
|
+
} catch {
|
|
52
|
+
savedFor = String(stored.creds.api_url);
|
|
53
|
+
}
|
|
54
|
+
if (savedFor !== apiUrl) {
|
|
55
|
+
return { token: null, apiUrl, source: null, insecureFile: stored.insecure, savedTokenUrl: savedFor };
|
|
56
|
+
}
|
|
48
57
|
return { token: stored.creds.token, apiUrl, source: "file", insecureFile: stored.insecure };
|
|
49
58
|
}
|
|
50
59
|
return { token: null, apiUrl, source: null, insecureFile: false };
|
|
@@ -160,10 +169,10 @@ class NetworkError extends ZenAdminError {
|
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
class NotSignedInError extends ZenAdminError {
|
|
163
|
-
constructor() {
|
|
172
|
+
constructor(message) {
|
|
164
173
|
super({
|
|
165
174
|
code: "NOT_SIGNED_IN",
|
|
166
|
-
message: "No ZenAdmin token. Create one in ZenAdmin (Zen AI > Access tokens), then run `zen login` or set ZENADMIN_TOKEN.",
|
|
175
|
+
message: message ?? "No ZenAdmin token. Create one in ZenAdmin (Zen AI > Access tokens), then run `zen login` or set ZENADMIN_TOKEN.",
|
|
167
176
|
status: 0
|
|
168
177
|
});
|
|
169
178
|
this.name = "NotSignedInError";
|
|
@@ -273,7 +282,7 @@ var isReusable = (operation) => !isSettled(operation) || operation.status === "u
|
|
|
273
282
|
var ReadResultSchema = z.record(z.string(), z.unknown());
|
|
274
283
|
|
|
275
284
|
// packages/sdk/src/client.ts
|
|
276
|
-
var SDK_VERSION = "0.3.
|
|
285
|
+
var SDK_VERSION = "0.3.1";
|
|
277
286
|
var REQUEST_ID = /^[A-Za-z0-9_-]{8,64}$/;
|
|
278
287
|
var RETRY_STATUSES = new Set([429, 502, 503, 504]);
|
|
279
288
|
var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -329,6 +338,9 @@ class ZenAdmin {
|
|
|
329
338
|
}
|
|
330
339
|
static async fromEnvironment(options = {}, env = process.env) {
|
|
331
340
|
const creds = await resolveCredentials({ token: options.token, apiUrl: options.apiUrl }, env);
|
|
341
|
+
if (!creds.token && creds.savedTokenUrl) {
|
|
342
|
+
throw new NotSignedInError(`The token saved by \`zen login\` is for ${creds.savedTokenUrl}, so it is not sent to ${creds.apiUrl}. ` + `Run \`zen login --api-url ${creds.apiUrl}\` to sign in there, or set ZENADMIN_TOKEN.`);
|
|
343
|
+
}
|
|
332
344
|
if (!creds.token)
|
|
333
345
|
throw new NotSignedInError;
|
|
334
346
|
return new ZenAdmin({ ...options, token: creds.token, apiUrl: creds.apiUrl });
|