@arbidocs/client 0.4.169 → 0.5.0
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.cjs +88 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +88 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1227,6 +1227,59 @@ function workspaceKeyRequiredOf(body) {
|
|
|
1227
1227
|
return d.code === "workspace_key_required" && typeof d.workspace_ext_id === "string" ? d.workspace_ext_id : null;
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
1230
|
+
// src/workspace-opens.ts
|
|
1231
|
+
function createWorkspaceOpens() {
|
|
1232
|
+
let tail = Promise.resolve();
|
|
1233
|
+
let pending = 0;
|
|
1234
|
+
let generation = 0;
|
|
1235
|
+
let active = null;
|
|
1236
|
+
return {
|
|
1237
|
+
run(target, open) {
|
|
1238
|
+
pending++;
|
|
1239
|
+
const result = tail.then(async () => {
|
|
1240
|
+
const workspaceId = target();
|
|
1241
|
+
if (workspaceId === null || workspaceId !== active) {
|
|
1242
|
+
generation++;
|
|
1243
|
+
active = null;
|
|
1244
|
+
}
|
|
1245
|
+
try {
|
|
1246
|
+
const value = await open();
|
|
1247
|
+
active = workspaceId;
|
|
1248
|
+
return value;
|
|
1249
|
+
} catch (error) {
|
|
1250
|
+
generation++;
|
|
1251
|
+
active = null;
|
|
1252
|
+
throw error;
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
const done = () => {
|
|
1256
|
+
pending--;
|
|
1257
|
+
};
|
|
1258
|
+
tail = result.then(done, done);
|
|
1259
|
+
return result;
|
|
1260
|
+
},
|
|
1261
|
+
get busy() {
|
|
1262
|
+
return pending > 0;
|
|
1263
|
+
},
|
|
1264
|
+
get generation() {
|
|
1265
|
+
return generation;
|
|
1266
|
+
},
|
|
1267
|
+
get active() {
|
|
1268
|
+
return active;
|
|
1269
|
+
},
|
|
1270
|
+
async idle() {
|
|
1271
|
+
for (let current = tail; ; current = tail) {
|
|
1272
|
+
await current;
|
|
1273
|
+
if (current === tail && pending === 0) return;
|
|
1274
|
+
}
|
|
1275
|
+
},
|
|
1276
|
+
reset() {
|
|
1277
|
+
generation++;
|
|
1278
|
+
active = null;
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1230
1283
|
// src/middleware/auto-relogin.ts
|
|
1231
1284
|
var NO_ACTIVE_WORKSPACE = /no active workspace/i;
|
|
1232
1285
|
async function keyRequiredWorkspace(response) {
|
|
@@ -1505,7 +1558,11 @@ function createAllWorkspacesOpener(deps) {
|
|
|
1505
1558
|
} catch {
|
|
1506
1559
|
return;
|
|
1507
1560
|
}
|
|
1508
|
-
|
|
1561
|
+
const last = deps.lastWorkspace?.() ?? null;
|
|
1562
|
+
const ordered = [...workspaces ?? []].sort(
|
|
1563
|
+
(a, b) => Number(a.external_id === last) - Number(b.external_id === last)
|
|
1564
|
+
);
|
|
1565
|
+
for (const ws of ordered) {
|
|
1509
1566
|
if (!ws.wrapped_key || !ws.external_id) continue;
|
|
1510
1567
|
try {
|
|
1511
1568
|
const workspaceKey = deps.unwrapWorkspaceKey(ws.wrapped_key, session.signingPrivateKey);
|
|
@@ -1754,7 +1811,7 @@ function readBaseUrlPerRequest(fetchClient, base) {
|
|
|
1754
1811
|
}
|
|
1755
1812
|
var deploymentDomainOf = ({ deploymentDomain }) => typeof deploymentDomain === "function" ? deploymentDomain() : deploymentDomain;
|
|
1756
1813
|
function createArbiClient(options) {
|
|
1757
|
-
const { fetch: fetch2, session, persistence, workspaceKeys, auth } = createTransport(options);
|
|
1814
|
+
const { fetch: fetch2, session, persistence, workspaceKeys, workspaceOpens, auth } = createTransport(options);
|
|
1758
1815
|
const authDeps = {
|
|
1759
1816
|
fetchClient: fetch2,
|
|
1760
1817
|
session,
|
|
@@ -1767,6 +1824,7 @@ function createArbiClient(options) {
|
|
|
1767
1824
|
return {
|
|
1768
1825
|
fetch: fetch2,
|
|
1769
1826
|
workspaceKeys,
|
|
1827
|
+
workspaceOpens,
|
|
1770
1828
|
session,
|
|
1771
1829
|
auth: {
|
|
1772
1830
|
register: (params) => register(params, authDeps),
|
|
@@ -1892,10 +1950,14 @@ function createTransport(options) {
|
|
|
1892
1950
|
if (!response.ok) throw new Error(`Could not unlock the workspace (${response.status})`);
|
|
1893
1951
|
}
|
|
1894
1952
|
});
|
|
1953
|
+
const workspaceOpens = createWorkspaceOpens();
|
|
1895
1954
|
let keysUser = session.getState().signedIn ? session.getState().userExtId : null;
|
|
1896
1955
|
session.subscribe((state) => {
|
|
1897
1956
|
const user = state.signedIn ? state.userExtId : null;
|
|
1898
|
-
if (user !== keysUser)
|
|
1957
|
+
if (user !== keysUser) {
|
|
1958
|
+
workspaceKeys.clear();
|
|
1959
|
+
workspaceOpens.reset();
|
|
1960
|
+
}
|
|
1899
1961
|
keysUser = user;
|
|
1900
1962
|
});
|
|
1901
1963
|
const workspaceKeyRefreshProvider = {
|
|
@@ -1903,7 +1965,7 @@ function createTransport(options) {
|
|
|
1903
1965
|
return (await workspaceKeys.wrappedKey(workspaceId).catch(() => null))?.wrappedKey ?? null;
|
|
1904
1966
|
}
|
|
1905
1967
|
};
|
|
1906
|
-
const
|
|
1968
|
+
const rawWorkspaceOpenProvider = {
|
|
1907
1969
|
async openWorkspace(accessToken, workspaceId, encryptedWorkspaceKey) {
|
|
1908
1970
|
const query = "?include_documents=false&include_conversations=false&include_tags=false";
|
|
1909
1971
|
try {
|
|
@@ -1925,6 +1987,16 @@ function createTransport(options) {
|
|
|
1925
1987
|
}
|
|
1926
1988
|
}
|
|
1927
1989
|
};
|
|
1990
|
+
const workspaceOpenProvider = {
|
|
1991
|
+
openWorkspace: (accessToken, workspaceId, encryptedWorkspaceKey) => workspaceOpens.busy ? Promise.resolve(true) : workspaceOpens.run(
|
|
1992
|
+
() => workspaceId,
|
|
1993
|
+
() => rawWorkspaceOpenProvider.openWorkspace(
|
|
1994
|
+
accessToken,
|
|
1995
|
+
workspaceId,
|
|
1996
|
+
encryptedWorkspaceKey
|
|
1997
|
+
)
|
|
1998
|
+
)
|
|
1999
|
+
};
|
|
1928
2000
|
let lastFailure = null;
|
|
1929
2001
|
const expiredListeners = /* @__PURE__ */ new Set();
|
|
1930
2002
|
const rawRelogin = createReloginHandler({
|
|
@@ -1958,15 +2030,19 @@ function createTransport(options) {
|
|
|
1958
2030
|
}
|
|
1959
2031
|
return null;
|
|
1960
2032
|
}
|
|
1961
|
-
const
|
|
2033
|
+
const reopenSelected = createWorkspaceReopener({
|
|
1962
2034
|
crypto: cryptoProvider,
|
|
1963
2035
|
persistence,
|
|
1964
2036
|
authState,
|
|
1965
2037
|
getAccessToken: () => session.getState().accessToken,
|
|
1966
2038
|
workspaceKeyRefreshProvider,
|
|
1967
|
-
workspaceOpenProvider
|
|
2039
|
+
workspaceOpenProvider: rawWorkspaceOpenProvider
|
|
2040
|
+
});
|
|
2041
|
+
let reopening = null;
|
|
2042
|
+
const reopenWorkspace = () => reopening ??= workspaceOpens.run(() => authState.getSelectedWorkspaceId(), reopenSelected).finally(() => {
|
|
2043
|
+
reopening = null;
|
|
1968
2044
|
});
|
|
1969
|
-
const
|
|
2045
|
+
const openEveryWorkspace = createAllWorkspacesOpener({
|
|
1970
2046
|
crypto: cryptoProvider,
|
|
1971
2047
|
persistence,
|
|
1972
2048
|
getAccessToken: () => session.getState().accessToken,
|
|
@@ -1976,8 +2052,10 @@ function createTransport(options) {
|
|
|
1976
2052
|
const list = await listWorkspaces(accessToken);
|
|
1977
2053
|
return list && workspaceKeys.remember(list);
|
|
1978
2054
|
},
|
|
1979
|
-
workspaceOpenProvider
|
|
2055
|
+
workspaceOpenProvider: rawWorkspaceOpenProvider,
|
|
2056
|
+
lastWorkspace: () => authState.getSelectedWorkspaceId()
|
|
1980
2057
|
});
|
|
2058
|
+
const openAllWorkspaces = () => workspaceOpens.run(() => null, openEveryWorkspace);
|
|
1981
2059
|
const fetchClient = createFetchClient__default.default({
|
|
1982
2060
|
baseUrl: base(),
|
|
1983
2061
|
credentials,
|
|
@@ -2006,6 +2084,7 @@ function createTransport(options) {
|
|
|
2006
2084
|
session,
|
|
2007
2085
|
persistence,
|
|
2008
2086
|
workspaceKeys,
|
|
2087
|
+
workspaceOpens,
|
|
2009
2088
|
auth: {
|
|
2010
2089
|
relogin,
|
|
2011
2090
|
reopenWorkspace,
|
|
@@ -2137,6 +2216,7 @@ exports.createRecoveryUrl = createRecoveryUrl;
|
|
|
2137
2216
|
exports.createReloginHandler = createReloginHandler;
|
|
2138
2217
|
exports.createSessionManager = createSessionManager;
|
|
2139
2218
|
exports.createWorkspaceKeys = createWorkspaceKeys;
|
|
2219
|
+
exports.createWorkspaceOpens = createWorkspaceOpens;
|
|
2140
2220
|
exports.createWorkspaceReopener = createWorkspaceReopener;
|
|
2141
2221
|
exports.decodeCallKey = decodeCallKey;
|
|
2142
2222
|
exports.decodeSecureMailKey = decodeSecureMailKey;
|