@geolonia/geonicdb-sdk 0.14.0 → 0.15.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 +29 -0
- package/geonicdb.cjs +38 -5
- package/geonicdb.cjs.map +2 -2
- package/geonicdb.d.ts +21 -0
- package/geonicdb.iife.js +38 -5
- package/geonicdb.iife.js.map +2 -2
- package/geonicdb.mjs +38 -5
- package/geonicdb.mjs.map +2 -2
- package/package.json +1 -1
- package/react/index.d.ts +8 -1
package/geonicdb.mjs
CHANGED
|
@@ -46,6 +46,7 @@ var RECONNECT_MAX_ATTEMPTS = 10;
|
|
|
46
46
|
var RECONNECT_BASE_MS = 1e3;
|
|
47
47
|
var RECONNECT_MAX_DELAY_MS = 3e4;
|
|
48
48
|
var SUB_PROTOCOL = "access_token";
|
|
49
|
+
var NGSI_LD_CORE_CONTEXT = "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld";
|
|
49
50
|
var SDK_CACHE_MAX_ENTRIES_DEFAULT = 1e3;
|
|
50
51
|
var SDK_POLL_INTERVAL_MS_DEFAULT = 5e3;
|
|
51
52
|
var DPOP_IDB_NAME = "geonicdb-sdk";
|
|
@@ -287,6 +288,20 @@ var ConflictError = class extends GeonicDBError {
|
|
|
287
288
|
this.name = "ConflictError";
|
|
288
289
|
}
|
|
289
290
|
};
|
|
291
|
+
var PasswordResetRequiredError = class extends AuthenticationError {
|
|
292
|
+
constructor(message = "Password reset required: set a new password to complete login") {
|
|
293
|
+
super(message);
|
|
294
|
+
this.name = "PasswordResetRequiredError";
|
|
295
|
+
this.statusCode = 409;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var TemporaryPasswordExpiredError = class extends AuthenticationError {
|
|
299
|
+
constructor(message = "Temporary password expired: ask an administrator to re-issue it") {
|
|
300
|
+
super(message);
|
|
301
|
+
this.name = "TemporaryPasswordExpiredError";
|
|
302
|
+
this.statusCode = 403;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
290
305
|
var ValidationError = class extends GeonicDBError {
|
|
291
306
|
constructor(message = "Validation failed") {
|
|
292
307
|
super(message, 422);
|
|
@@ -677,16 +692,24 @@ var _AuthManager = class _AuthManager {
|
|
|
677
692
|
"Content-Type": "application/json"
|
|
678
693
|
};
|
|
679
694
|
if (this._tenant) headers["NGSILD-Tenant"] = this._tenant;
|
|
695
|
+
const loginBody = { email, password };
|
|
696
|
+
if (options?.newPassword !== void 0) loginBody.newPassword = options.newPassword;
|
|
680
697
|
const res = await fetch(this._baseUrl + "/auth/login", {
|
|
681
698
|
method: "POST",
|
|
682
699
|
headers,
|
|
683
|
-
body: JSON.stringify(
|
|
700
|
+
body: JSON.stringify(loginBody)
|
|
684
701
|
});
|
|
685
702
|
if (!res.ok) {
|
|
686
703
|
const e = await res.json().catch(() => ({}));
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
)
|
|
704
|
+
const message = e.detail || e.description || "Login failed: " + res.status;
|
|
705
|
+
const code = e.error || e.type || e.title || "";
|
|
706
|
+
if (res.status === 409 && code.includes("PasswordResetRequired")) {
|
|
707
|
+
throw new PasswordResetRequiredError(message);
|
|
708
|
+
}
|
|
709
|
+
if (res.status === 403 && code.includes("TemporaryPasswordExpired")) {
|
|
710
|
+
throw new TemporaryPasswordExpiredError(message);
|
|
711
|
+
}
|
|
712
|
+
throw new AuthenticationError(message);
|
|
690
713
|
}
|
|
691
714
|
const data = await res.json();
|
|
692
715
|
this._anonymous = false;
|
|
@@ -1187,7 +1210,15 @@ var _AuthManager = class _AuthManager {
|
|
|
1187
1210
|
}
|
|
1188
1211
|
const url = this._baseUrl + path;
|
|
1189
1212
|
const isDPoP = this._tokenType === "DPoP" && !!this._dpopKeyPair && token !== null;
|
|
1190
|
-
const
|
|
1213
|
+
const isEntityWrite = path.split("?")[0].startsWith("/ngsi-ld/v1/entities");
|
|
1214
|
+
let effectiveBody = body;
|
|
1215
|
+
if (isEntityWrite && effectiveBody !== null && typeof effectiveBody === "object" && !Array.isArray(effectiveBody) && !("@context" in effectiveBody)) {
|
|
1216
|
+
effectiveBody = {
|
|
1217
|
+
...effectiveBody,
|
|
1218
|
+
"@context": NGSI_LD_CORE_CONTEXT
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
const bodyStr = effectiveBody !== void 0 ? JSON.stringify(effectiveBody) : void 0;
|
|
1191
1222
|
const doRequest = async (reqToken, dpopNonce) => {
|
|
1192
1223
|
const reqIsDPoP = this._tokenType === "DPoP" && !!this._dpopKeyPair && reqToken !== null;
|
|
1193
1224
|
const dpopProof = reqIsDPoP ? await createDPoPProof(
|
|
@@ -2086,7 +2117,9 @@ export {
|
|
|
2086
2117
|
GeonicDBError,
|
|
2087
2118
|
NetworkError,
|
|
2088
2119
|
NotFoundError,
|
|
2120
|
+
PasswordResetRequiredError,
|
|
2089
2121
|
RateLimitError,
|
|
2122
|
+
TemporaryPasswordExpiredError,
|
|
2090
2123
|
ValidationError,
|
|
2091
2124
|
buildPathWithParams,
|
|
2092
2125
|
index_default as default
|