@openbkn/bkn-sdk 0.1.1-alpha.2 → 0.1.1-alpha.3
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/{chunk-5MOIXIMJ.js → chunk-APJNRHLS.js} +27 -5
- package/dist/chunk-APJNRHLS.js.map +1 -0
- package/dist/cli.js +54 -27
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-5MOIXIMJ.js.map +0 -1
|
@@ -235,8 +235,8 @@ function resolveContext(opts = {}) {
|
|
|
235
235
|
const normalized = baseUrl.replace(/\/+$/, "");
|
|
236
236
|
const stored = readToken(normalized);
|
|
237
237
|
const explicit = opts.token ?? process.env.BKN_TOKEN;
|
|
238
|
-
const token = explicit ?? stored?.accessToken;
|
|
239
|
-
if (!token) {
|
|
238
|
+
const token = explicit ?? stored?.accessToken ?? "";
|
|
239
|
+
if (!token && !stored?.noAuth) {
|
|
240
240
|
throw new InputError("No access token. Set BKN_TOKEN or run `openbkn auth login`.");
|
|
241
241
|
}
|
|
242
242
|
const insecure = opts.insecure ?? stored?.tlsInsecure ?? false;
|
|
@@ -295,6 +295,19 @@ function mergeCookies(existing, res) {
|
|
|
295
295
|
for (const sc of setCookies) add(sc.split(";")[0]?.trim() ?? "");
|
|
296
296
|
return [...map.entries()].map(([k, v]) => `${k}=${v}`).join("; ");
|
|
297
297
|
}
|
|
298
|
+
async function fetchAuthStatus(baseUrl) {
|
|
299
|
+
try {
|
|
300
|
+
const res = await fetch(`${normalizeBaseUrl(baseUrl)}/install-status.json`, {
|
|
301
|
+
headers: { Accept: "application/json" }
|
|
302
|
+
});
|
|
303
|
+
if (!res.ok) return null;
|
|
304
|
+
const j = await res.json();
|
|
305
|
+
if (!j.auth) return null;
|
|
306
|
+
return { enabled: Boolean(j.auth.enabled), stack: j.auth.stack };
|
|
307
|
+
} catch {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
298
311
|
async function refreshAccessToken(baseUrl, refreshToken, clientId = "openbkn-sdk") {
|
|
299
312
|
const base = normalizeBaseUrl(baseUrl);
|
|
300
313
|
const res = await fetch(`${base}/oauth2/token`, {
|
|
@@ -441,8 +454,8 @@ async function credentialDeviceLogin(baseUrl, username, password, opts = {}) {
|
|
|
441
454
|
// src/api/headers.ts
|
|
442
455
|
function buildHeaders(ctx, extra) {
|
|
443
456
|
return {
|
|
444
|
-
|
|
445
|
-
token: ctx.token,
|
|
457
|
+
// No token = a no-auth platform (no bkn-safe); send no Authorization.
|
|
458
|
+
...ctx.token ? { authorization: `Bearer ${ctx.token}`, token: ctx.token } : {},
|
|
446
459
|
"x-business-domain": ctx.businessDomain,
|
|
447
460
|
...extra
|
|
448
461
|
};
|
|
@@ -4966,6 +4979,7 @@ function createClient(opts = {}) {
|
|
|
4966
4979
|
// src/resources/auth.ts
|
|
4967
4980
|
var auth_exports = {};
|
|
4968
4981
|
__export(auth_exports, {
|
|
4982
|
+
attachNoAuth: () => attachNoAuth,
|
|
4969
4983
|
attachToken: () => attachToken,
|
|
4970
4984
|
currentToken: () => currentToken,
|
|
4971
4985
|
deletePlatform: () => deletePlatform,
|
|
@@ -5010,6 +5024,12 @@ function attachToken(baseUrl, accessToken, opts = {}) {
|
|
|
5010
5024
|
setActivePlatform(url);
|
|
5011
5025
|
return { baseUrl: url, userId, username: usernameOf(token) };
|
|
5012
5026
|
}
|
|
5027
|
+
function attachNoAuth(baseUrl, opts = {}) {
|
|
5028
|
+
const url = normalize(baseUrl);
|
|
5029
|
+
writeToken(url, { baseUrl: url, accessToken: "", noAuth: true, tlsInsecure: opts.insecure });
|
|
5030
|
+
setActivePlatform(url);
|
|
5031
|
+
return { baseUrl: url, noAuth: true };
|
|
5032
|
+
}
|
|
5013
5033
|
function status() {
|
|
5014
5034
|
const baseUrl = activePlatform();
|
|
5015
5035
|
if (!baseUrl) return { hasToken: false };
|
|
@@ -5108,6 +5128,7 @@ export {
|
|
|
5108
5128
|
writePlatformConfig,
|
|
5109
5129
|
resolveContext,
|
|
5110
5130
|
openBrowser,
|
|
5131
|
+
fetchAuthStatus,
|
|
5111
5132
|
deviceLogin,
|
|
5112
5133
|
credentialDeviceLogin,
|
|
5113
5134
|
request,
|
|
@@ -5128,6 +5149,7 @@ export {
|
|
|
5128
5149
|
vega,
|
|
5129
5150
|
createClient,
|
|
5130
5151
|
attachToken,
|
|
5152
|
+
attachNoAuth,
|
|
5131
5153
|
status,
|
|
5132
5154
|
currentToken,
|
|
5133
5155
|
whoami,
|
|
@@ -5139,4 +5161,4 @@ export {
|
|
|
5139
5161
|
exportCreds,
|
|
5140
5162
|
auth_exports
|
|
5141
5163
|
};
|
|
5142
|
-
//# sourceMappingURL=chunk-
|
|
5164
|
+
//# sourceMappingURL=chunk-APJNRHLS.js.map
|