@arbidocs/sdk 0.3.7 → 0.3.9
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 +36 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +808 -568
- package/dist/index.d.ts +808 -568
- package/dist/index.js +36 -40
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -388,14 +388,6 @@ function createWorkspaceKeyMiddleware(config) {
|
|
|
388
388
|
function createAutoReloginMiddleware(config) {
|
|
389
389
|
return {
|
|
390
390
|
async onResponse({ response, request }) {
|
|
391
|
-
if (needsWorkspaceKey(request.url, config.urlConfig)) {
|
|
392
|
-
const hasWorkspaceKey = request.headers.has("Workspace-Key");
|
|
393
|
-
console.debug(
|
|
394
|
-
`[${request.method}] ${response.status}`,
|
|
395
|
-
request.url,
|
|
396
|
-
`Workspace-Key: ${hasWorkspaceKey ? "\u2713" : "\u2717"}`
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
391
|
if (response.status === 400) {
|
|
400
392
|
const isSafeMethod = ["GET", "HEAD", "DELETE"].includes(request.method);
|
|
401
393
|
if (isSafeMethod) {
|
|
@@ -404,12 +396,6 @@ function createAutoReloginMiddleware(config) {
|
|
|
404
396
|
if (newToken) {
|
|
405
397
|
const newRequest = request.clone();
|
|
406
398
|
newRequest.headers.set("Authorization", `Bearer ${newToken}`);
|
|
407
|
-
if (needsWorkspaceKey(request.url, config.urlConfig)) {
|
|
408
|
-
const workspaceHeader = config.workspaceKeyProvider.getWorkspaceKeyHeader();
|
|
409
|
-
if (workspaceHeader) {
|
|
410
|
-
newRequest.headers.set("Workspace-Key", workspaceHeader);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
399
|
console.info("[API] Retrying request after re-login");
|
|
414
400
|
return fetch(newRequest);
|
|
415
401
|
}
|
|
@@ -424,12 +410,6 @@ function createAutoReloginMiddleware(config) {
|
|
|
424
410
|
try {
|
|
425
411
|
const newRequest = request.clone();
|
|
426
412
|
newRequest.headers.set("Authorization", `Bearer ${newToken}`);
|
|
427
|
-
if (needsWorkspaceKey(request.url, config.urlConfig)) {
|
|
428
|
-
const workspaceHeader = config.workspaceKeyProvider.getWorkspaceKeyHeader();
|
|
429
|
-
if (workspaceHeader) {
|
|
430
|
-
newRequest.headers.set("Workspace-Key", workspaceHeader);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
413
|
console.info("[API] Retrying request after re-login:", request.method, request.url);
|
|
434
414
|
return fetch(newRequest);
|
|
435
415
|
} catch (cloneError) {
|
|
@@ -541,14 +521,25 @@ function createReloginHandler(deps) {
|
|
|
541
521
|
wrappedKey,
|
|
542
522
|
encryptionKeyPair.secretKey
|
|
543
523
|
);
|
|
544
|
-
const
|
|
524
|
+
const encryptedWorkspaceKey = await deps.crypto.createWorkspaceKeyHeader(
|
|
545
525
|
workspaceKey,
|
|
546
526
|
loginResult.sessionKey
|
|
547
527
|
);
|
|
548
|
-
deps.authState.setCachedWorkspaceHeader(selectedWorkspaceId,
|
|
528
|
+
deps.authState.setCachedWorkspaceHeader(selectedWorkspaceId, encryptedWorkspaceKey);
|
|
529
|
+
if (deps.workspaceOpenProvider) {
|
|
530
|
+
const workspaceJwt = await deps.workspaceOpenProvider.openWorkspace(
|
|
531
|
+
loginResult.accessToken,
|
|
532
|
+
selectedWorkspaceId,
|
|
533
|
+
encryptedWorkspaceKey
|
|
534
|
+
);
|
|
535
|
+
if (workspaceJwt) {
|
|
536
|
+
deps.authState.setAccessToken(workspaceJwt);
|
|
537
|
+
console.info("[API] Workspace-scoped JWT obtained after re-login");
|
|
538
|
+
}
|
|
539
|
+
}
|
|
549
540
|
}
|
|
550
541
|
} catch (error) {
|
|
551
|
-
console.error("[API] Failed to
|
|
542
|
+
console.error("[API] Failed to re-open workspace after re-login:", error);
|
|
552
543
|
}
|
|
553
544
|
}
|
|
554
545
|
console.info("[API] Re-login successful");
|
|
@@ -849,7 +840,7 @@ async function register(params, deps) {
|
|
|
849
840
|
params.password,
|
|
850
841
|
deps.deploymentDomain
|
|
851
842
|
);
|
|
852
|
-
const response = await deps.fetchClient.POST("/
|
|
843
|
+
const response = await deps.fetchClient.POST("/v1/user/register", {
|
|
853
844
|
body: credentials.request
|
|
854
845
|
});
|
|
855
846
|
if (response.error) {
|
|
@@ -883,7 +874,7 @@ async function loginWithKey(params, deps) {
|
|
|
883
874
|
return performLogin(credentials.request, credentials.signingPrivateKey, deps);
|
|
884
875
|
}
|
|
885
876
|
async function performLogin(request, signingPrivateKey, deps) {
|
|
886
|
-
const response = await deps.fetchClient.POST("/
|
|
877
|
+
const response = await deps.fetchClient.POST("/v1/user/login", {
|
|
887
878
|
body: request
|
|
888
879
|
});
|
|
889
880
|
if (response.error || !response.data) {
|
|
@@ -922,7 +913,7 @@ async function changePassword(params, deps) {
|
|
|
922
913
|
params.newPassword,
|
|
923
914
|
deps.deploymentDomain
|
|
924
915
|
);
|
|
925
|
-
const response = await deps.fetchClient.POST("/
|
|
916
|
+
const response = await deps.fetchClient.POST("/v1/user/change_password", {
|
|
926
917
|
body: {
|
|
927
918
|
...credentials.request,
|
|
928
919
|
rewrapped_workspace_keys: params.rewrappedWorkspaceKeys ?? {}
|
|
@@ -938,14 +929,20 @@ async function changePassword(params, deps) {
|
|
|
938
929
|
}
|
|
939
930
|
|
|
940
931
|
// src/client.ts
|
|
932
|
+
var API_PREFIX = "/v1";
|
|
941
933
|
var DEFAULT_WORKSPACE_KEY_URL_CONFIG = {
|
|
942
|
-
excludePatterns: [
|
|
934
|
+
excludePatterns: [
|
|
935
|
+
`${API_PREFIX}/user/`,
|
|
936
|
+
`${API_PREFIX}/health/`,
|
|
937
|
+
`${API_PREFIX}/configs/`,
|
|
938
|
+
`${API_PREFIX}/workspace/create`
|
|
939
|
+
],
|
|
943
940
|
includePatterns: [
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
941
|
+
`${API_PREFIX}/workspace/wrk-`,
|
|
942
|
+
`${API_PREFIX}/document/`,
|
|
943
|
+
`${API_PREFIX}/conversation/`,
|
|
944
|
+
`${API_PREFIX}/assistant/`,
|
|
945
|
+
`${API_PREFIX}/tag/`
|
|
949
946
|
]
|
|
950
947
|
};
|
|
951
948
|
var RETRYABLE_CODES = /* @__PURE__ */ new Set([
|
|
@@ -968,7 +965,8 @@ function createRetryFetch() {
|
|
|
968
965
|
let lastError;
|
|
969
966
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
970
967
|
try {
|
|
971
|
-
|
|
968
|
+
const fetchInput = input instanceof Request ? input.clone() : input;
|
|
969
|
+
return await globalThis.fetch(fetchInput, init);
|
|
972
970
|
} catch (err) {
|
|
973
971
|
lastError = err;
|
|
974
972
|
if (attempt < MAX_RETRIES && isRetryableError(err)) {
|
|
@@ -986,7 +984,7 @@ function createArbiClient(options) {
|
|
|
986
984
|
baseUrl,
|
|
987
985
|
deploymentDomain,
|
|
988
986
|
workspaceKeyUrlConfig = DEFAULT_WORKSPACE_KEY_URL_CONFIG,
|
|
989
|
-
reloginExcludePatterns = [
|
|
987
|
+
reloginExcludePatterns = [`${API_PREFIX}/user/login`],
|
|
990
988
|
credentials = "include",
|
|
991
989
|
ssoTokenProvider = null,
|
|
992
990
|
onReloginSuccess
|
|
@@ -1011,7 +1009,7 @@ function createArbiClient(options) {
|
|
|
1011
1009
|
credentials,
|
|
1012
1010
|
fetch: retryFetch
|
|
1013
1011
|
});
|
|
1014
|
-
const response = await rawFetch.POST("/
|
|
1012
|
+
const response = await rawFetch.POST("/v1/user/login", {
|
|
1015
1013
|
body: {
|
|
1016
1014
|
email: payload.email,
|
|
1017
1015
|
signature: payload.signature,
|
|
@@ -1033,7 +1031,7 @@ function createArbiClient(options) {
|
|
|
1033
1031
|
};
|
|
1034
1032
|
const workspaceKeyRefreshProvider = {
|
|
1035
1033
|
async getWrappedKey(accessToken, workspaceId) {
|
|
1036
|
-
const workspacesResponse = await retryFetch(`${baseUrl}/
|
|
1034
|
+
const workspacesResponse = await retryFetch(`${baseUrl}${API_PREFIX}/user/workspaces`, {
|
|
1037
1035
|
method: "GET",
|
|
1038
1036
|
headers: {
|
|
1039
1037
|
Authorization: `Bearer ${accessToken}`,
|
|
@@ -1073,8 +1071,6 @@ function createArbiClient(options) {
|
|
|
1073
1071
|
fetchClient.use(
|
|
1074
1072
|
createAutoReloginMiddleware({
|
|
1075
1073
|
reloginHandler,
|
|
1076
|
-
workspaceKeyProvider,
|
|
1077
|
-
urlConfig: workspaceKeyUrlConfig,
|
|
1078
1074
|
reloginExcludePatterns
|
|
1079
1075
|
})
|
|
1080
1076
|
);
|
|
@@ -1124,7 +1120,7 @@ function createArbiClient(options) {
|
|
|
1124
1120
|
function buildWebSocketUrl(baseUrl) {
|
|
1125
1121
|
const wsScheme = baseUrl.startsWith("https") ? "wss" : "ws";
|
|
1126
1122
|
const hostAndPath = baseUrl.replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
1127
|
-
return `${wsScheme}://${hostAndPath}/
|
|
1123
|
+
return `${wsScheme}://${hostAndPath}${API_PREFIX}/notifications/ws`;
|
|
1128
1124
|
}
|
|
1129
1125
|
function createAuthMessage(accessToken) {
|
|
1130
1126
|
const msg = { type: "auth", token: accessToken };
|
|
@@ -1145,6 +1141,7 @@ function isMessageType(msg, type) {
|
|
|
1145
1141
|
return msg.type === type;
|
|
1146
1142
|
}
|
|
1147
1143
|
|
|
1144
|
+
exports.API_PREFIX = API_PREFIX;
|
|
1148
1145
|
exports.base64Decode = base64Decode;
|
|
1149
1146
|
exports.base64Encode = base64Encode;
|
|
1150
1147
|
exports.base64ToBytes = base64ToBytes;
|