@geolonia/geonicdb-sdk 0.17.0 → 0.18.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/README.md +84 -4
- package/geonicdb.cjs +44 -17
- package/geonicdb.cjs.map +2 -2
- package/geonicdb.d.ts +31 -4
- package/geonicdb.iife.js +44 -17
- package/geonicdb.iife.js.map +2 -2
- package/geonicdb.mjs +44 -17
- package/geonicdb.mjs.map +2 -2
- package/package.json +1 -1
- package/react/index.d.ts +2 -2
package/geonicdb.mjs
CHANGED
|
@@ -260,13 +260,20 @@ var GeonicDBError = class extends Error {
|
|
|
260
260
|
super(message);
|
|
261
261
|
/** HTTP status code (if applicable) */
|
|
262
262
|
__publicField(this, "statusCode");
|
|
263
|
+
/** The request that failed, when the SDK knows it. */
|
|
264
|
+
__publicField(this, "request");
|
|
263
265
|
this.name = "GeonicDBError";
|
|
264
266
|
this.statusCode = statusCode;
|
|
265
267
|
}
|
|
266
268
|
};
|
|
269
|
+
function withRequest(error, request) {
|
|
270
|
+
error.request = request;
|
|
271
|
+
error.message = `[${request.method} ${request.path}] ${error.message}`;
|
|
272
|
+
return error;
|
|
273
|
+
}
|
|
267
274
|
var AuthenticationError = class extends GeonicDBError {
|
|
268
|
-
constructor(message = "Authentication failed") {
|
|
269
|
-
super(message,
|
|
275
|
+
constructor(message = "Authentication failed", statusCode = 401) {
|
|
276
|
+
super(message, statusCode);
|
|
270
277
|
this.name = "AuthenticationError";
|
|
271
278
|
}
|
|
272
279
|
};
|
|
@@ -290,16 +297,14 @@ var ConflictError = class extends GeonicDBError {
|
|
|
290
297
|
};
|
|
291
298
|
var PasswordResetRequiredError = class extends AuthenticationError {
|
|
292
299
|
constructor(message = "Password reset required: set a new password to complete login") {
|
|
293
|
-
super(message);
|
|
300
|
+
super(message, 409);
|
|
294
301
|
this.name = "PasswordResetRequiredError";
|
|
295
|
-
this.statusCode = 409;
|
|
296
302
|
}
|
|
297
303
|
};
|
|
298
304
|
var TemporaryPasswordExpiredError = class extends AuthenticationError {
|
|
299
305
|
constructor(message = "Temporary password expired: ask an administrator to re-issue it") {
|
|
300
|
-
super(message);
|
|
306
|
+
super(message, 403);
|
|
301
307
|
this.name = "TemporaryPasswordExpiredError";
|
|
302
|
-
this.statusCode = 403;
|
|
303
308
|
}
|
|
304
309
|
};
|
|
305
310
|
var ValidationError = class extends GeonicDBError {
|
|
@@ -704,12 +709,21 @@ var _AuthManager = class _AuthManager {
|
|
|
704
709
|
const message = e.detail || e.description || "Login failed: " + res.status;
|
|
705
710
|
const code = e.error || e.type || e.title || "";
|
|
706
711
|
if (res.status === 409 && code.includes("PasswordResetRequired")) {
|
|
707
|
-
throw new PasswordResetRequiredError(message)
|
|
712
|
+
throw withRequest(new PasswordResetRequiredError(message), {
|
|
713
|
+
method: "POST",
|
|
714
|
+
path: "/auth/login"
|
|
715
|
+
});
|
|
708
716
|
}
|
|
709
717
|
if (res.status === 403 && code.includes("TemporaryPasswordExpired")) {
|
|
710
|
-
throw new TemporaryPasswordExpiredError(message)
|
|
718
|
+
throw withRequest(new TemporaryPasswordExpiredError(message), {
|
|
719
|
+
method: "POST",
|
|
720
|
+
path: "/auth/login"
|
|
721
|
+
});
|
|
711
722
|
}
|
|
712
|
-
throw new AuthenticationError(message)
|
|
723
|
+
throw withRequest(new AuthenticationError(message, res.status), {
|
|
724
|
+
method: "POST",
|
|
725
|
+
path: "/auth/login"
|
|
726
|
+
});
|
|
713
727
|
}
|
|
714
728
|
const data = await res.json();
|
|
715
729
|
this._anonymous = false;
|
|
@@ -812,8 +826,12 @@ var _AuthManager = class _AuthManager {
|
|
|
812
826
|
}
|
|
813
827
|
if (!res.ok) {
|
|
814
828
|
const e = await res.json().catch(() => ({}));
|
|
815
|
-
throw
|
|
816
|
-
|
|
829
|
+
throw withRequest(
|
|
830
|
+
new AuthenticationError(
|
|
831
|
+
e.detail || e.description || "DPoP bind failed: " + res.status,
|
|
832
|
+
res.status
|
|
833
|
+
),
|
|
834
|
+
{ method: "POST", path: "/auth/dpop-bind" }
|
|
817
835
|
);
|
|
818
836
|
}
|
|
819
837
|
return await res.json();
|
|
@@ -985,7 +1003,7 @@ var _AuthManager = class _AuthManager {
|
|
|
985
1003
|
this._refreshToken = null;
|
|
986
1004
|
this._token = null;
|
|
987
1005
|
this._tokenPromise = null;
|
|
988
|
-
throw new AuthenticationError("Token refresh failed: " + res.status);
|
|
1006
|
+
throw new AuthenticationError("Token refresh failed: " + res.status, res.status);
|
|
989
1007
|
}
|
|
990
1008
|
const data = await res.json();
|
|
991
1009
|
this._token = data.accessToken;
|
|
@@ -1053,7 +1071,7 @@ var _AuthManager = class _AuthManager {
|
|
|
1053
1071
|
body: JSON.stringify({ api_key: this._apiKey })
|
|
1054
1072
|
});
|
|
1055
1073
|
if (!nonceRes.ok)
|
|
1056
|
-
throw new AuthenticationError("Nonce request failed: " + nonceRes.status);
|
|
1074
|
+
throw new AuthenticationError("Nonce request failed: " + nonceRes.status, nonceRes.status);
|
|
1057
1075
|
const nonceData = await nonceRes.json();
|
|
1058
1076
|
if (nonceData.dpop_nonce) this._dpopNonce = nonceData.dpop_nonce;
|
|
1059
1077
|
const proof = await solvePoW(nonceData.challenge, nonceData.difficulty);
|
|
@@ -1066,7 +1084,7 @@ var _AuthManager = class _AuthManager {
|
|
|
1066
1084
|
});
|
|
1067
1085
|
const res = await this._doTokenExchange(tokenUrl, tokenBody, this._dpopNonce);
|
|
1068
1086
|
if (!res.ok)
|
|
1069
|
-
throw new AuthenticationError("Token request failed: " + res.status);
|
|
1087
|
+
throw new AuthenticationError("Token request failed: " + res.status, res.status);
|
|
1070
1088
|
const newNonce = res.headers.get("DPoP-Nonce");
|
|
1071
1089
|
if (newNonce) this._dpopNonce = newNonce;
|
|
1072
1090
|
const data = await res.json();
|
|
@@ -1108,8 +1126,8 @@ var _AuthManager = class _AuthManager {
|
|
|
1108
1126
|
return this._doTokenExchange(tokenUrl, tokenBody, serverNonce, retryCount + 1);
|
|
1109
1127
|
}
|
|
1110
1128
|
}
|
|
1111
|
-
throw new
|
|
1112
|
-
"Token request failed: " + (errBody.error_description || errBody.error),
|
|
1129
|
+
throw new AuthenticationError(
|
|
1130
|
+
"Token request failed: " + (errBody.error_description || errBody.error || "400"),
|
|
1113
1131
|
400
|
|
1114
1132
|
);
|
|
1115
1133
|
}
|
|
@@ -1289,6 +1307,7 @@ var WebSocketManager = class {
|
|
|
1289
1307
|
__publicField(this, "_emit");
|
|
1290
1308
|
__publicField(this, "_ws", null);
|
|
1291
1309
|
__publicField(this, "_wsEndpoint", null);
|
|
1310
|
+
__publicField(this, "_deploymentHostname", null);
|
|
1292
1311
|
__publicField(this, "_wsIntentionalClose", false);
|
|
1293
1312
|
__publicField(this, "_reconnectAttempts", 0);
|
|
1294
1313
|
__publicField(this, "_tokenRefreshTimer", null);
|
|
@@ -1378,6 +1397,9 @@ var WebSocketManager = class {
|
|
|
1378
1397
|
const info = await res.json();
|
|
1379
1398
|
if (info.enabled && info.endpoint) {
|
|
1380
1399
|
this._wsEndpoint = info.endpoint;
|
|
1400
|
+
if (info.deployment) {
|
|
1401
|
+
this._deploymentHostname = info.deployment;
|
|
1402
|
+
}
|
|
1381
1403
|
return this._wsEndpoint;
|
|
1382
1404
|
}
|
|
1383
1405
|
}
|
|
@@ -1389,7 +1411,11 @@ var WebSocketManager = class {
|
|
|
1389
1411
|
async _openWebSocket(token) {
|
|
1390
1412
|
const endpoint = await this._discoverWsEndpoint();
|
|
1391
1413
|
return new Promise((resolve, reject) => {
|
|
1392
|
-
const
|
|
1414
|
+
const params = new URLSearchParams({ tenant: this._tenant });
|
|
1415
|
+
if (this._deploymentHostname) {
|
|
1416
|
+
params.set("deployment", this._deploymentHostname);
|
|
1417
|
+
}
|
|
1418
|
+
const wsUrl = endpoint + (endpoint.indexOf("?") === -1 ? "?" : "&") + params.toString();
|
|
1393
1419
|
this._log("connecting", wsUrl);
|
|
1394
1420
|
const ws = new WebSocket(wsUrl, [SUB_PROTOCOL, token]);
|
|
1395
1421
|
this._ws = ws;
|
|
@@ -1688,6 +1714,7 @@ var GeonicDB = class extends EventEmitter {
|
|
|
1688
1714
|
if (!tenant) tenant = script?.getAttribute?.("data-tenant") || "";
|
|
1689
1715
|
if (!baseUrl) baseUrl = script?.getAttribute?.("data-base-url") || "";
|
|
1690
1716
|
}
|
|
1717
|
+
baseUrl = baseUrl.replace(/\/+$/, "");
|
|
1691
1718
|
this._auth = new AuthManager(baseUrl, apiKey, tenant, opts.debug, opts.anonymous);
|
|
1692
1719
|
this._auth.onTokenRefresh = (creds) => {
|
|
1693
1720
|
this.onTokenRefresh?.(creds);
|