@arbidocs/sdk 0.4.95 → 0.4.97
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/browser.cjs +36 -22
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +36 -22
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +36 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser.cjs
CHANGED
|
@@ -3695,6 +3695,12 @@ async function getRawWorkspaceKey(arbi, workspaceId, signingPrivateKeyBase64) {
|
|
|
3695
3695
|
});
|
|
3696
3696
|
return client.sealedBoxDecrypt(ws.wrapped_key, encryptionKeyPair.secretKey);
|
|
3697
3697
|
}
|
|
3698
|
+
var StaleSessionError = class extends ArbiError {
|
|
3699
|
+
constructor(message) {
|
|
3700
|
+
super(message);
|
|
3701
|
+
this.name = "StaleSessionError";
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3698
3704
|
async function openWorkspaceEntry(arbi, ws, serverSessionKey, signingPrivateKeyBase64) {
|
|
3699
3705
|
if (ws.wrapped_key) {
|
|
3700
3706
|
const sealedKey = await selectWorkspace(
|
|
@@ -3704,12 +3710,13 @@ async function openWorkspaceEntry(arbi, ws, serverSessionKey, signingPrivateKeyB
|
|
|
3704
3710
|
serverSessionKey,
|
|
3705
3711
|
signingPrivateKeyBase64
|
|
3706
3712
|
);
|
|
3707
|
-
const { error: error2 } = await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
|
|
3713
|
+
const { error: error2, response } = await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
|
|
3708
3714
|
params: { path: { workspace_ext_id: ws.external_id } },
|
|
3709
3715
|
body: { workspace_key: sealedKey }
|
|
3710
3716
|
});
|
|
3711
3717
|
if (error2) {
|
|
3712
|
-
|
|
3718
|
+
const message = `Workspace open failed for ${ws.external_id}: ${JSON.stringify(error2)}`;
|
|
3719
|
+
throw response.status === 401 ? new StaleSessionError(message) : new ArbiError(message);
|
|
3713
3720
|
}
|
|
3714
3721
|
return sealedKey;
|
|
3715
3722
|
}
|
|
@@ -3768,6 +3775,28 @@ async function resolveAuth(store) {
|
|
|
3768
3775
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
3769
3776
|
return { arbi, loginResult, config };
|
|
3770
3777
|
}
|
|
3778
|
+
async function openOnCachedSession(store, config, creds, workspaceId) {
|
|
3779
|
+
const { arbi, loginResult } = await buildAuthFromCache(config, creds, store);
|
|
3780
|
+
arbi.session.setSelectedWorkspace(workspaceId);
|
|
3781
|
+
await selectWorkspaceById(
|
|
3782
|
+
arbi,
|
|
3783
|
+
workspaceId,
|
|
3784
|
+
loginResult.serverSessionKey,
|
|
3785
|
+
creds.signingPrivateKeyBase64
|
|
3786
|
+
);
|
|
3787
|
+
const nextOpened = Array.from(/* @__PURE__ */ new Set([...creds.openedWorkspaces ?? [], workspaceId]));
|
|
3788
|
+
store.saveCredentials({
|
|
3789
|
+
...store.requireCredentials(),
|
|
3790
|
+
openedWorkspaces: nextOpened
|
|
3791
|
+
});
|
|
3792
|
+
return {
|
|
3793
|
+
arbi,
|
|
3794
|
+
loginResult,
|
|
3795
|
+
config,
|
|
3796
|
+
workspaceId,
|
|
3797
|
+
accessToken: creds.accessToken
|
|
3798
|
+
};
|
|
3799
|
+
}
|
|
3771
3800
|
async function resolveWorkspace(store, workspaceOpt) {
|
|
3772
3801
|
const config = store.requireConfig();
|
|
3773
3802
|
const creds = store.requireCredentials();
|
|
@@ -3776,26 +3805,11 @@ async function resolveWorkspace(store, workspaceOpt) {
|
|
|
3776
3805
|
throw new ArbiError("No workspace selected. Run: arbi workspace select <id>");
|
|
3777
3806
|
}
|
|
3778
3807
|
if (isSessionAlive(creds)) {
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
loginResult2.serverSessionKey,
|
|
3785
|
-
creds.signingPrivateKeyBase64
|
|
3786
|
-
);
|
|
3787
|
-
const nextOpened = Array.from(/* @__PURE__ */ new Set([...creds.openedWorkspaces ?? [], workspaceId]));
|
|
3788
|
-
store.saveCredentials({
|
|
3789
|
-
...store.requireCredentials(),
|
|
3790
|
-
openedWorkspaces: nextOpened
|
|
3791
|
-
});
|
|
3792
|
-
return {
|
|
3793
|
-
arbi: arbi2,
|
|
3794
|
-
loginResult: loginResult2,
|
|
3795
|
-
config,
|
|
3796
|
-
workspaceId,
|
|
3797
|
-
accessToken: creds.accessToken
|
|
3798
|
-
};
|
|
3808
|
+
try {
|
|
3809
|
+
return await openOnCachedSession(store, config, creds, workspaceId);
|
|
3810
|
+
} catch (err) {
|
|
3811
|
+
if (!(err instanceof StaleSessionError)) throw err;
|
|
3812
|
+
}
|
|
3799
3813
|
}
|
|
3800
3814
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
3801
3815
|
await selectWorkspaceById(
|