nexrall-code 0.5.209 → 0.5.210
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 +35 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10097,7 +10097,7 @@ var require_client = __commonJS({
|
|
|
10097
10097
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
10098
10098
|
};
|
|
10099
10099
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10100
|
-
exports.SCHEDULE_MAX_MINUTES = exports.SCHEDULE_MIN_MINUTES = exports.API_BASE = void 0;
|
|
10100
|
+
exports.SCHEDULE_MAX_MINUTES = exports.SCHEDULE_MIN_MINUTES = exports.DEVICE_ACCOUNT_LIMIT = exports.API_BASE = void 0;
|
|
10101
10101
|
exports.chooseFinalContent = chooseFinalContent;
|
|
10102
10102
|
exports.refreshAccessToken = refreshAccessToken3;
|
|
10103
10103
|
exports.earlyToolResolveEnabled = earlyToolResolveEnabled;
|
|
@@ -10112,6 +10112,8 @@ var require_client = __commonJS({
|
|
|
10112
10112
|
exports.getOrgs = getOrgs3;
|
|
10113
10113
|
exports.getCodeModels = getCodeModels;
|
|
10114
10114
|
exports.getUsageDaily = getUsageDaily;
|
|
10115
|
+
exports.parseApiRefusal = parseApiRefusal;
|
|
10116
|
+
exports.refusalMessage = refusalMessage;
|
|
10115
10117
|
exports.exchangeVscodeCode = exchangeVscodeCode;
|
|
10116
10118
|
exports.login = login2;
|
|
10117
10119
|
exports.exchangeAuthCode = exchangeAuthCode2;
|
|
@@ -11122,15 +11124,41 @@ var require_client = __commonJS({
|
|
|
11122
11124
|
totalSpent: typeof data.totalSpent === "number" ? data.totalSpent : 0
|
|
11123
11125
|
};
|
|
11124
11126
|
}
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
+
exports.DEVICE_ACCOUNT_LIMIT = "device_account_limit";
|
|
11128
|
+
function parseApiRefusal(raw) {
|
|
11129
|
+
const text = raw.trim();
|
|
11130
|
+
try {
|
|
11131
|
+
const body = JSON.parse(text);
|
|
11132
|
+
const message = typeof body.error === "string" && body.error.trim() ? body.error.trim() : void 0;
|
|
11133
|
+
return {
|
|
11134
|
+
raw: text,
|
|
11135
|
+
...message ? { message } : {},
|
|
11136
|
+
...typeof body.code === "string" && body.code ? { code: body.code } : {},
|
|
11137
|
+
...typeof body.limit === "number" ? { limit: body.limit } : {}
|
|
11138
|
+
};
|
|
11139
|
+
} catch {
|
|
11140
|
+
return { raw: text };
|
|
11141
|
+
}
|
|
11142
|
+
}
|
|
11143
|
+
function refusalMessage(raw) {
|
|
11144
|
+
const { code, message, limit, raw: text } = parseApiRefusal(raw);
|
|
11145
|
+
if (code === exports.DEVICE_ACCOUNT_LIMIT) {
|
|
11146
|
+
return message ?? `This device has reached its limit of ${limit ?? "the maximum number of"} accounts. Sign in with an account already used on this device, or use a different device.`;
|
|
11147
|
+
}
|
|
11148
|
+
return message ?? text;
|
|
11149
|
+
}
|
|
11150
|
+
function postVscodeExchange(code) {
|
|
11151
|
+
return (0, node_fetch_1.default)(`${exports.API_BASE}/api/auth/vscode-exchange`, {
|
|
11127
11152
|
method: "POST",
|
|
11128
11153
|
headers: { "Content-Type": "application/json", ...deviceHeader() },
|
|
11129
11154
|
body: JSON.stringify({ code })
|
|
11130
11155
|
});
|
|
11156
|
+
}
|
|
11157
|
+
async function exchangeVscodeCode(code) {
|
|
11158
|
+
const response = await postVscodeExchange(code);
|
|
11131
11159
|
if (!response.ok) {
|
|
11132
11160
|
const errText3 = await response.text();
|
|
11133
|
-
throw new Error(`OAuth exchange failed (${response.status}): ${errText3}`);
|
|
11161
|
+
throw new Error(`OAuth exchange failed (${response.status}): ${refusalMessage(errText3)}`);
|
|
11134
11162
|
}
|
|
11135
11163
|
const data = await response.json();
|
|
11136
11164
|
if (!data.token)
|
|
@@ -11149,7 +11177,7 @@ var require_client = __commonJS({
|
|
|
11149
11177
|
});
|
|
11150
11178
|
if (!response.ok) {
|
|
11151
11179
|
const errText3 = await response.text();
|
|
11152
|
-
throw new Error(`Login failed (${response.status}): ${errText3}`);
|
|
11180
|
+
throw new Error(`Login failed (${response.status}): ${refusalMessage(errText3)}`);
|
|
11153
11181
|
}
|
|
11154
11182
|
const data = await response.json();
|
|
11155
11183
|
if (!data.token) {
|
|
@@ -11162,17 +11190,13 @@ var require_client = __commonJS({
|
|
|
11162
11190
|
};
|
|
11163
11191
|
}
|
|
11164
11192
|
async function exchangeAuthCode2(code) {
|
|
11165
|
-
const response = await (
|
|
11166
|
-
method: "POST",
|
|
11167
|
-
headers: { "Content-Type": "application/json", ...deviceHeader() },
|
|
11168
|
-
body: JSON.stringify({ code })
|
|
11169
|
-
});
|
|
11193
|
+
const response = await postVscodeExchange(code);
|
|
11170
11194
|
if (response.status === 401 || response.status === 400) {
|
|
11171
11195
|
throw new Error("That sign-in code is invalid or has expired (codes last 5 minutes). Run `nex auth --browser` again.");
|
|
11172
11196
|
}
|
|
11173
11197
|
if (!response.ok) {
|
|
11174
11198
|
const errText3 = await response.text().catch(() => "");
|
|
11175
|
-
throw new Error(`Sign-in failed (${response.status}): ${errText3}`);
|
|
11199
|
+
throw new Error(`Sign-in failed (${response.status}): ${refusalMessage(errText3)}`);
|
|
11176
11200
|
}
|
|
11177
11201
|
const data = await response.json();
|
|
11178
11202
|
if (!data.token)
|