tines 0.0.120 → 0.0.122
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 +51 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3725,6 +3725,40 @@ var ApiError = class extends Error {
|
|
|
3725
3725
|
this.details = body?.details;
|
|
3726
3726
|
}
|
|
3727
3727
|
};
|
|
3728
|
+
function causeCode(err) {
|
|
3729
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3730
|
+
let node = err;
|
|
3731
|
+
while (node && typeof node === "object" && !seen.has(node)) {
|
|
3732
|
+
seen.add(node);
|
|
3733
|
+
const e = node;
|
|
3734
|
+
if (typeof e.code === "string") return e.code;
|
|
3735
|
+
node = e.cause ?? (Array.isArray(e.errors) ? e.errors[0] : void 0);
|
|
3736
|
+
}
|
|
3737
|
+
return void 0;
|
|
3738
|
+
}
|
|
3739
|
+
var ApiNetworkError = class extends Error {
|
|
3740
|
+
/** Method of the request that never completed. */
|
|
3741
|
+
method;
|
|
3742
|
+
/** Request path, query string included. */
|
|
3743
|
+
path;
|
|
3744
|
+
/** Base URL the client was built with; `''` for a same-origin caller. */
|
|
3745
|
+
baseUrl;
|
|
3746
|
+
/** The URL that was attempted (`baseUrl + path`). */
|
|
3747
|
+
url;
|
|
3748
|
+
/** The runtime's code for the failure (`ECONNREFUSED`, `ENOTFOUND`, …), when it gives one. */
|
|
3749
|
+
code;
|
|
3750
|
+
constructor(method, path2, baseUrl, cause) {
|
|
3751
|
+
const code = causeCode(cause);
|
|
3752
|
+
const detail = code ?? (cause instanceof Error ? cause.message : String(cause));
|
|
3753
|
+
super(`${method} ${path2}: could not reach ${baseUrl || "the server"} (${detail})`, { cause });
|
|
3754
|
+
this.name = "ApiNetworkError";
|
|
3755
|
+
this.method = method;
|
|
3756
|
+
this.path = path2;
|
|
3757
|
+
this.baseUrl = baseUrl;
|
|
3758
|
+
this.url = `${baseUrl}${path2}`;
|
|
3759
|
+
this.code = code;
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3728
3762
|
function query(params) {
|
|
3729
3763
|
const search = new URLSearchParams();
|
|
3730
3764
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -3738,11 +3772,18 @@ function query(params) {
|
|
|
3738
3772
|
function createApiClient(options) {
|
|
3739
3773
|
const base = options.baseUrl.replace(/\/+$/, "");
|
|
3740
3774
|
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
3775
|
+
async function send(method, path2, init) {
|
|
3776
|
+
try {
|
|
3777
|
+
return await fetchFn(`${base}${path2}`, init);
|
|
3778
|
+
} catch (err) {
|
|
3779
|
+
throw new ApiNetworkError(method, path2, base, err);
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3741
3782
|
async function request(method, path2, body) {
|
|
3742
3783
|
const headers = { accept: "application/json" };
|
|
3743
3784
|
if (options.apiKey) headers.authorization = `Bearer ${options.apiKey}`;
|
|
3744
3785
|
if (body !== void 0) headers["content-type"] = "application/json";
|
|
3745
|
-
const res = await
|
|
3786
|
+
const res = await send(method, path2, {
|
|
3746
3787
|
method,
|
|
3747
3788
|
headers,
|
|
3748
3789
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
@@ -3766,7 +3807,7 @@ function createApiClient(options) {
|
|
|
3766
3807
|
opts.body.byteOffset,
|
|
3767
3808
|
opts.body.byteOffset + opts.body.byteLength
|
|
3768
3809
|
) : opts.body;
|
|
3769
|
-
const res = await
|
|
3810
|
+
const res = await send(method, path2, { method, headers, body });
|
|
3770
3811
|
if (!res.ok) {
|
|
3771
3812
|
let parsed = null;
|
|
3772
3813
|
try {
|
|
@@ -4364,6 +4405,12 @@ requires artifact "${r.artifact}"${spec ? ` (${spec})` : ""}: ${r.status ?? "unm
|
|
|
4364
4405
|
}
|
|
4365
4406
|
die(message3);
|
|
4366
4407
|
}
|
|
4408
|
+
if (err instanceof ApiNetworkError) {
|
|
4409
|
+
die(
|
|
4410
|
+
`${err.message}
|
|
4411
|
+
hint: set the base URL with --url, TINES_API_URL, or \`tines login --url <url>\` (\`tines config\` shows the one in effect)`
|
|
4412
|
+
);
|
|
4413
|
+
}
|
|
4367
4414
|
die(err instanceof Error ? err.message : String(err));
|
|
4368
4415
|
}
|
|
4369
4416
|
function printJson(value) {
|
|
@@ -5726,9 +5773,9 @@ function register5(program3) {
|
|
|
5726
5773
|
die(`${url} rejected the API key (${err.message}); nothing stored`);
|
|
5727
5774
|
}
|
|
5728
5775
|
if (err instanceof ApiError) throw err;
|
|
5729
|
-
const
|
|
5776
|
+
const code = err instanceof ApiNetworkError ? err.code : void 0;
|
|
5730
5777
|
die(
|
|
5731
|
-
`could not reach ${url}${
|
|
5778
|
+
`could not reach ${url}${code ? ` (${code})` : ""}; nothing stored (pass --no-verify to store anyway)`
|
|
5732
5779
|
);
|
|
5733
5780
|
}
|
|
5734
5781
|
}
|