@arbidocs/sdk 0.4.95 → 0.4.96
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/index.cjs
CHANGED
|
@@ -4088,6 +4088,12 @@ async function getRawWorkspaceKey(arbi, workspaceId, signingPrivateKeyBase64) {
|
|
|
4088
4088
|
});
|
|
4089
4089
|
return client.sealedBoxDecrypt(ws.wrapped_key, encryptionKeyPair.secretKey);
|
|
4090
4090
|
}
|
|
4091
|
+
var StaleSessionError = class extends ArbiError {
|
|
4092
|
+
constructor(message) {
|
|
4093
|
+
super(message);
|
|
4094
|
+
this.name = "StaleSessionError";
|
|
4095
|
+
}
|
|
4096
|
+
};
|
|
4091
4097
|
async function openWorkspaceEntry(arbi, ws, serverSessionKey, signingPrivateKeyBase64) {
|
|
4092
4098
|
if (ws.wrapped_key) {
|
|
4093
4099
|
const sealedKey = await selectWorkspace(
|
|
@@ -4097,12 +4103,13 @@ async function openWorkspaceEntry(arbi, ws, serverSessionKey, signingPrivateKeyB
|
|
|
4097
4103
|
serverSessionKey,
|
|
4098
4104
|
signingPrivateKeyBase64
|
|
4099
4105
|
);
|
|
4100
|
-
const { error: error2 } = await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
|
|
4106
|
+
const { error: error2, response } = await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/open", {
|
|
4101
4107
|
params: { path: { workspace_ext_id: ws.external_id } },
|
|
4102
4108
|
body: { workspace_key: sealedKey }
|
|
4103
4109
|
});
|
|
4104
4110
|
if (error2) {
|
|
4105
|
-
|
|
4111
|
+
const message = `Workspace open failed for ${ws.external_id}: ${JSON.stringify(error2)}`;
|
|
4112
|
+
throw response.status === 401 ? new StaleSessionError(message) : new ArbiError(message);
|
|
4106
4113
|
}
|
|
4107
4114
|
return sealedKey;
|
|
4108
4115
|
}
|
|
@@ -4161,6 +4168,28 @@ async function resolveAuth(store) {
|
|
|
4161
4168
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
4162
4169
|
return { arbi, loginResult, config };
|
|
4163
4170
|
}
|
|
4171
|
+
async function openOnCachedSession(store, config, creds, workspaceId) {
|
|
4172
|
+
const { arbi, loginResult } = await buildAuthFromCache(config, creds, store);
|
|
4173
|
+
arbi.session.setSelectedWorkspace(workspaceId);
|
|
4174
|
+
await selectWorkspaceById(
|
|
4175
|
+
arbi,
|
|
4176
|
+
workspaceId,
|
|
4177
|
+
loginResult.serverSessionKey,
|
|
4178
|
+
creds.signingPrivateKeyBase64
|
|
4179
|
+
);
|
|
4180
|
+
const nextOpened = Array.from(/* @__PURE__ */ new Set([...creds.openedWorkspaces ?? [], workspaceId]));
|
|
4181
|
+
store.saveCredentials({
|
|
4182
|
+
...store.requireCredentials(),
|
|
4183
|
+
openedWorkspaces: nextOpened
|
|
4184
|
+
});
|
|
4185
|
+
return {
|
|
4186
|
+
arbi,
|
|
4187
|
+
loginResult,
|
|
4188
|
+
config,
|
|
4189
|
+
workspaceId,
|
|
4190
|
+
accessToken: creds.accessToken
|
|
4191
|
+
};
|
|
4192
|
+
}
|
|
4164
4193
|
async function resolveWorkspace(store, workspaceOpt) {
|
|
4165
4194
|
const config = store.requireConfig();
|
|
4166
4195
|
const creds = store.requireCredentials();
|
|
@@ -4169,26 +4198,11 @@ async function resolveWorkspace(store, workspaceOpt) {
|
|
|
4169
4198
|
throw new ArbiError("No workspace selected. Run: arbi workspace select <id>");
|
|
4170
4199
|
}
|
|
4171
4200
|
if (isSessionAlive(creds)) {
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
loginResult2.serverSessionKey,
|
|
4178
|
-
creds.signingPrivateKeyBase64
|
|
4179
|
-
);
|
|
4180
|
-
const nextOpened = Array.from(/* @__PURE__ */ new Set([...creds.openedWorkspaces ?? [], workspaceId]));
|
|
4181
|
-
store.saveCredentials({
|
|
4182
|
-
...store.requireCredentials(),
|
|
4183
|
-
openedWorkspaces: nextOpened
|
|
4184
|
-
});
|
|
4185
|
-
return {
|
|
4186
|
-
arbi: arbi2,
|
|
4187
|
-
loginResult: loginResult2,
|
|
4188
|
-
config,
|
|
4189
|
-
workspaceId,
|
|
4190
|
-
accessToken: creds.accessToken
|
|
4191
|
-
};
|
|
4201
|
+
try {
|
|
4202
|
+
return await openOnCachedSession(store, config, creds, workspaceId);
|
|
4203
|
+
} catch (err) {
|
|
4204
|
+
if (!(err instanceof StaleSessionError)) throw err;
|
|
4205
|
+
}
|
|
4192
4206
|
}
|
|
4193
4207
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
4194
4208
|
await selectWorkspaceById(
|