@geolonia/geonicdb-sdk 0.14.0 → 0.16.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 +35 -4
- package/geonicdb.cjs +52 -7
- package/geonicdb.cjs.map +2 -2
- package/geonicdb.d.ts +61 -4
- package/geonicdb.iife.js +52 -7
- package/geonicdb.iife.js.map +2 -2
- package/geonicdb.mjs +52 -7
- package/geonicdb.mjs.map +2 -2
- package/package.json +1 -1
- package/react/index.d.ts +49 -6
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-v1.9.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(
|
|
@@ -1900,7 +1931,13 @@ var GeonicDB = class extends EventEmitter {
|
|
|
1900
1931
|
return { deleted: true };
|
|
1901
1932
|
}
|
|
1902
1933
|
// --- Types / Attributes Discovery ---
|
|
1903
|
-
/**
|
|
1934
|
+
/**
|
|
1935
|
+
* List all entity types.
|
|
1936
|
+
*
|
|
1937
|
+
* `details` 未指定の `GET /types` は ETSI OpenAPI v1.8.1 準拠の
|
|
1938
|
+
* `EntityTypeList` オブジェクト(`{ id, type: 'EntityTypeList', typeList }`)を返す。
|
|
1939
|
+
* 型名の一覧は `typeList` から取得する。
|
|
1940
|
+
*/
|
|
1904
1941
|
async getTypes() {
|
|
1905
1942
|
return this._jsonGet("/ngsi-ld/v1/types", "Types query failed");
|
|
1906
1943
|
}
|
|
@@ -1911,7 +1948,13 @@ var GeonicDB = class extends EventEmitter {
|
|
|
1911
1948
|
"Type not found"
|
|
1912
1949
|
);
|
|
1913
1950
|
}
|
|
1914
|
-
/**
|
|
1951
|
+
/**
|
|
1952
|
+
* List all attributes.
|
|
1953
|
+
*
|
|
1954
|
+
* `details` 未指定の `GET /attributes` は ETSI OpenAPI v1.8.1 準拠の
|
|
1955
|
+
* `AttributeList` オブジェクト(`{ id, type: 'AttributeList', attributeList }`)を返す。
|
|
1956
|
+
* 属性名の一覧は `attributeList` から取得する。
|
|
1957
|
+
*/
|
|
1915
1958
|
async getAttributes() {
|
|
1916
1959
|
return this._jsonGet("/ngsi-ld/v1/attributes", "Attributes query failed");
|
|
1917
1960
|
}
|
|
@@ -2086,7 +2129,9 @@ export {
|
|
|
2086
2129
|
GeonicDBError,
|
|
2087
2130
|
NetworkError,
|
|
2088
2131
|
NotFoundError,
|
|
2132
|
+
PasswordResetRequiredError,
|
|
2089
2133
|
RateLimitError,
|
|
2134
|
+
TemporaryPasswordExpiredError,
|
|
2090
2135
|
ValidationError,
|
|
2091
2136
|
buildPathWithParams,
|
|
2092
2137
|
index_default as default
|