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