@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.d.ts
CHANGED
|
@@ -195,6 +195,13 @@ export interface LoginOptions {
|
|
|
195
195
|
* be sender-constrained, so it is not persisted.
|
|
196
196
|
*/
|
|
197
197
|
rememberSession?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* #1532: 管理者発行の一時パスワードで初回ログインする際に、設定する新パスワードを同梱する。
|
|
200
|
+
* 一時パスワードでのログインは、これを付けないとサーバが `PasswordResetRequired` (409) を
|
|
201
|
+
* 返す。付けると、その場で新パスワードを設定して本トークンを発行する (単発型、再ログイン不要)。
|
|
202
|
+
* 通常のログインでは指定しない。
|
|
203
|
+
*/
|
|
204
|
+
newPassword?: string;
|
|
198
205
|
}
|
|
199
206
|
/** Response from the login endpoint. */
|
|
200
207
|
export interface LoginResponse {
|
|
@@ -274,6 +281,30 @@ export interface GetTemporalEntitiesParams {
|
|
|
274
281
|
*/
|
|
275
282
|
options?: string;
|
|
276
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* `GET /ngsi-ld/v1/types`(`details` 未指定)のレスポンス。
|
|
286
|
+
* ETSI GS CIM 009 / OpenAPI v1.8.1 の `EntityTypeList`(5.2.24)。
|
|
287
|
+
* `details=true` の場合は代わりに `EntityType` の配列が返る(本 SDK では未対応)。
|
|
288
|
+
*/
|
|
289
|
+
export interface EntityTypeList {
|
|
290
|
+
id: string;
|
|
291
|
+
type: "EntityTypeList";
|
|
292
|
+
/** 利用可能なエンティティ型名の配列 */
|
|
293
|
+
typeList: string[];
|
|
294
|
+
"@context"?: string | string[];
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* `GET /ngsi-ld/v1/attributes`(`details` 未指定)のレスポンス。
|
|
298
|
+
* ETSI GS CIM 009 / OpenAPI v1.8.1 の `AttributeList`(5.2.27)。
|
|
299
|
+
* `details=true` の場合は代わりに `Attribute` の配列が返る(本 SDK では未対応)。
|
|
300
|
+
*/
|
|
301
|
+
export interface AttributeList {
|
|
302
|
+
id: string;
|
|
303
|
+
type: "AttributeList";
|
|
304
|
+
/** 利用可能な属性名の配列 */
|
|
305
|
+
attributeList: string[];
|
|
306
|
+
"@context"?: string | string[];
|
|
307
|
+
}
|
|
277
308
|
export type Listener<T> = (data: T) => void;
|
|
278
309
|
declare class EventEmitter {
|
|
279
310
|
private _listeners;
|
|
@@ -313,6 +344,20 @@ export declare class NotFoundError extends GeonicDBError {
|
|
|
313
344
|
export declare class ConflictError extends GeonicDBError {
|
|
314
345
|
constructor(message?: string);
|
|
315
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* 409 — 一時パスワードでの初回ログインで、新パスワードの設定が必要 (#1532)。
|
|
349
|
+
* `login(email, tempPassword)` がこれを投げたら、新パスワードを集めて
|
|
350
|
+
* `login(email, tempPassword, { newPassword })` を呼び直す。
|
|
351
|
+
*/
|
|
352
|
+
export declare class PasswordResetRequiredError extends AuthenticationError {
|
|
353
|
+
constructor(message?: string);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* 403 — 一時パスワードの有効期限切れ (#1532)。管理者に再発行を依頼する。
|
|
357
|
+
*/
|
|
358
|
+
export declare class TemporaryPasswordExpiredError extends AuthenticationError {
|
|
359
|
+
constructor(message?: string);
|
|
360
|
+
}
|
|
316
361
|
/** 422 — Validation error (bad request payload). */
|
|
317
362
|
export declare class ValidationError extends GeonicDBError {
|
|
318
363
|
constructor(message?: string);
|
|
@@ -457,12 +502,24 @@ export declare class GeonicDB extends EventEmitter {
|
|
|
457
502
|
deleteEntity(entityId: string): Promise<{
|
|
458
503
|
deleted: true;
|
|
459
504
|
}>;
|
|
460
|
-
/**
|
|
461
|
-
|
|
505
|
+
/**
|
|
506
|
+
* List all entity types.
|
|
507
|
+
*
|
|
508
|
+
* `details` 未指定の `GET /types` は ETSI OpenAPI v1.8.1 準拠の
|
|
509
|
+
* `EntityTypeList` オブジェクト(`{ id, type: 'EntityTypeList', typeList }`)を返す。
|
|
510
|
+
* 型名の一覧は `typeList` から取得する。
|
|
511
|
+
*/
|
|
512
|
+
getTypes(): Promise<EntityTypeList>;
|
|
462
513
|
/** Get details for a specific entity type. */
|
|
463
514
|
getType(typeName: string): Promise<Record<string, unknown>>;
|
|
464
|
-
/**
|
|
465
|
-
|
|
515
|
+
/**
|
|
516
|
+
* List all attributes.
|
|
517
|
+
*
|
|
518
|
+
* `details` 未指定の `GET /attributes` は ETSI OpenAPI v1.8.1 準拠の
|
|
519
|
+
* `AttributeList` オブジェクト(`{ id, type: 'AttributeList', attributeList }`)を返す。
|
|
520
|
+
* 属性名の一覧は `attributeList` から取得する。
|
|
521
|
+
*/
|
|
522
|
+
getAttributes(): Promise<AttributeList>;
|
|
466
523
|
/** Get details for a specific attribute. */
|
|
467
524
|
getAttribute(attrName: string): Promise<Record<string, unknown>>;
|
|
468
525
|
/** Query temporal entities. */
|
package/geonicdb.iife.js
CHANGED
|
@@ -30,7 +30,9 @@ var GeonicDBModule = (() => {
|
|
|
30
30
|
GeonicDBError: () => GeonicDBError,
|
|
31
31
|
NetworkError: () => NetworkError,
|
|
32
32
|
NotFoundError: () => NotFoundError,
|
|
33
|
+
PasswordResetRequiredError: () => PasswordResetRequiredError,
|
|
33
34
|
RateLimitError: () => RateLimitError,
|
|
35
|
+
TemporaryPasswordExpiredError: () => TemporaryPasswordExpiredError,
|
|
34
36
|
ValidationError: () => ValidationError,
|
|
35
37
|
buildPathWithParams: () => buildPathWithParams,
|
|
36
38
|
default: () => index_default
|
|
@@ -80,6 +82,7 @@ var GeonicDBModule = (() => {
|
|
|
80
82
|
var RECONNECT_BASE_MS = 1e3;
|
|
81
83
|
var RECONNECT_MAX_DELAY_MS = 3e4;
|
|
82
84
|
var SUB_PROTOCOL = "access_token";
|
|
85
|
+
var NGSI_LD_CORE_CONTEXT = "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.9.jsonld";
|
|
83
86
|
var SDK_CACHE_MAX_ENTRIES_DEFAULT = 1e3;
|
|
84
87
|
var SDK_POLL_INTERVAL_MS_DEFAULT = 5e3;
|
|
85
88
|
var DPOP_IDB_NAME = "geonicdb-sdk";
|
|
@@ -321,6 +324,20 @@ var GeonicDBModule = (() => {
|
|
|
321
324
|
this.name = "ConflictError";
|
|
322
325
|
}
|
|
323
326
|
};
|
|
327
|
+
var PasswordResetRequiredError = class extends AuthenticationError {
|
|
328
|
+
constructor(message = "Password reset required: set a new password to complete login") {
|
|
329
|
+
super(message);
|
|
330
|
+
this.name = "PasswordResetRequiredError";
|
|
331
|
+
this.statusCode = 409;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
var TemporaryPasswordExpiredError = class extends AuthenticationError {
|
|
335
|
+
constructor(message = "Temporary password expired: ask an administrator to re-issue it") {
|
|
336
|
+
super(message);
|
|
337
|
+
this.name = "TemporaryPasswordExpiredError";
|
|
338
|
+
this.statusCode = 403;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
324
341
|
var ValidationError = class extends GeonicDBError {
|
|
325
342
|
constructor(message = "Validation failed") {
|
|
326
343
|
super(message, 422);
|
|
@@ -711,16 +728,24 @@ var GeonicDBModule = (() => {
|
|
|
711
728
|
"Content-Type": "application/json"
|
|
712
729
|
};
|
|
713
730
|
if (this._tenant) headers["NGSILD-Tenant"] = this._tenant;
|
|
731
|
+
const loginBody = { email, password };
|
|
732
|
+
if (options?.newPassword !== void 0) loginBody.newPassword = options.newPassword;
|
|
714
733
|
const res = await fetch(this._baseUrl + "/auth/login", {
|
|
715
734
|
method: "POST",
|
|
716
735
|
headers,
|
|
717
|
-
body: JSON.stringify(
|
|
736
|
+
body: JSON.stringify(loginBody)
|
|
718
737
|
});
|
|
719
738
|
if (!res.ok) {
|
|
720
739
|
const e = await res.json().catch(() => ({}));
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
)
|
|
740
|
+
const message = e.detail || e.description || "Login failed: " + res.status;
|
|
741
|
+
const code = e.error || e.type || e.title || "";
|
|
742
|
+
if (res.status === 409 && code.includes("PasswordResetRequired")) {
|
|
743
|
+
throw new PasswordResetRequiredError(message);
|
|
744
|
+
}
|
|
745
|
+
if (res.status === 403 && code.includes("TemporaryPasswordExpired")) {
|
|
746
|
+
throw new TemporaryPasswordExpiredError(message);
|
|
747
|
+
}
|
|
748
|
+
throw new AuthenticationError(message);
|
|
724
749
|
}
|
|
725
750
|
const data = await res.json();
|
|
726
751
|
this._anonymous = false;
|
|
@@ -1221,7 +1246,15 @@ var GeonicDBModule = (() => {
|
|
|
1221
1246
|
}
|
|
1222
1247
|
const url = this._baseUrl + path;
|
|
1223
1248
|
const isDPoP = this._tokenType === "DPoP" && !!this._dpopKeyPair && token !== null;
|
|
1224
|
-
const
|
|
1249
|
+
const isEntityWrite = path.split("?")[0].startsWith("/ngsi-ld/v1/entities");
|
|
1250
|
+
let effectiveBody = body;
|
|
1251
|
+
if (isEntityWrite && effectiveBody !== null && typeof effectiveBody === "object" && !Array.isArray(effectiveBody) && !("@context" in effectiveBody)) {
|
|
1252
|
+
effectiveBody = {
|
|
1253
|
+
...effectiveBody,
|
|
1254
|
+
"@context": NGSI_LD_CORE_CONTEXT
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
const bodyStr = effectiveBody !== void 0 ? JSON.stringify(effectiveBody) : void 0;
|
|
1225
1258
|
const doRequest = async (reqToken, dpopNonce) => {
|
|
1226
1259
|
const reqIsDPoP = this._tokenType === "DPoP" && !!this._dpopKeyPair && reqToken !== null;
|
|
1227
1260
|
const dpopProof = reqIsDPoP ? await createDPoPProof(
|
|
@@ -1934,7 +1967,13 @@ var GeonicDBModule = (() => {
|
|
|
1934
1967
|
return { deleted: true };
|
|
1935
1968
|
}
|
|
1936
1969
|
// --- Types / Attributes Discovery ---
|
|
1937
|
-
/**
|
|
1970
|
+
/**
|
|
1971
|
+
* List all entity types.
|
|
1972
|
+
*
|
|
1973
|
+
* `details` 未指定の `GET /types` は ETSI OpenAPI v1.8.1 準拠の
|
|
1974
|
+
* `EntityTypeList` オブジェクト(`{ id, type: 'EntityTypeList', typeList }`)を返す。
|
|
1975
|
+
* 型名の一覧は `typeList` から取得する。
|
|
1976
|
+
*/
|
|
1938
1977
|
async getTypes() {
|
|
1939
1978
|
return this._jsonGet("/ngsi-ld/v1/types", "Types query failed");
|
|
1940
1979
|
}
|
|
@@ -1945,7 +1984,13 @@ var GeonicDBModule = (() => {
|
|
|
1945
1984
|
"Type not found"
|
|
1946
1985
|
);
|
|
1947
1986
|
}
|
|
1948
|
-
/**
|
|
1987
|
+
/**
|
|
1988
|
+
* List all attributes.
|
|
1989
|
+
*
|
|
1990
|
+
* `details` 未指定の `GET /attributes` は ETSI OpenAPI v1.8.1 準拠の
|
|
1991
|
+
* `AttributeList` オブジェクト(`{ id, type: 'AttributeList', attributeList }`)を返す。
|
|
1992
|
+
* 属性名の一覧は `attributeList` から取得する。
|
|
1993
|
+
*/
|
|
1949
1994
|
async getAttributes() {
|
|
1950
1995
|
return this._jsonGet("/ngsi-ld/v1/attributes", "Attributes query failed");
|
|
1951
1996
|
}
|