@centia-io/sdk 0.2.12 → 0.2.14
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 +57 -0
- package/dist/centia-io-sdk.cjs +216 -4
- package/dist/centia-io-sdk.d.cts +241 -52
- package/dist/centia-io-sdk.d.cts.map +1 -1
- package/dist/centia-io-sdk.d.ts +241 -52
- package/dist/centia-io-sdk.d.ts.map +1 -1
- package/dist/centia-io-sdk.js +212 -4
- package/dist/centia-io-sdk.js.map +1 -1
- package/dist/centia-io-sdk.umd.js +215 -3
- package/package.json +1 -1
package/dist/centia-io-sdk.js
CHANGED
|
@@ -340,6 +340,9 @@ var Gc2Service = class {
|
|
|
340
340
|
isSignUpOptions(options) {
|
|
341
341
|
return "parentDb" in options;
|
|
342
342
|
}
|
|
343
|
+
isGuestFlowOptions(options) {
|
|
344
|
+
return "database" in options && !("username" in options);
|
|
345
|
+
}
|
|
343
346
|
buildUrl(path) {
|
|
344
347
|
if (path.startsWith("http://") || path.startsWith("https://")) return path;
|
|
345
348
|
return `${this.host}${path}`;
|
|
@@ -452,12 +455,24 @@ var Gc2Service = class {
|
|
|
452
455
|
database
|
|
453
456
|
});
|
|
454
457
|
}
|
|
455
|
-
async
|
|
458
|
+
async getGuestToken() {
|
|
456
459
|
var _this5 = this;
|
|
457
|
-
|
|
458
|
-
|
|
460
|
+
let database;
|
|
461
|
+
if (_this5.isGuestFlowOptions(_this5.options)) database = _this5.options.database;
|
|
462
|
+
else throw new Error("GuestFlow options required for this operation");
|
|
463
|
+
const path = `${_this5.host}/api/v4/oauth/guest`;
|
|
459
464
|
return _this5.request(_this5.buildUrl(path), "POST", {
|
|
465
|
+
database,
|
|
460
466
|
client_id: _this5.options.clientId,
|
|
467
|
+
client_secret: _this5.options.clientSecret
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
async getRefreshToken(token) {
|
|
471
|
+
var _this6 = this;
|
|
472
|
+
var _this$options$tokenUr3;
|
|
473
|
+
const path = (_this$options$tokenUr3 = _this6.options.tokenUri) !== null && _this$options$tokenUr3 !== void 0 ? _this$options$tokenUr3 : `${_this6.host}/api/v4/oauth`;
|
|
474
|
+
return _this6.request(_this6.buildUrl(path), "POST", {
|
|
475
|
+
client_id: _this6.options.clientId,
|
|
461
476
|
grant_type: "refresh_token",
|
|
462
477
|
refresh_token: token
|
|
463
478
|
});
|
|
@@ -575,6 +590,48 @@ var PasswordFlow = class {
|
|
|
575
590
|
}
|
|
576
591
|
};
|
|
577
592
|
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/GuestFlow.ts
|
|
595
|
+
/**
|
|
596
|
+
* @author Martin Høgh <mh@mapcentia.com>
|
|
597
|
+
* @copyright 2013-2026 MapCentia ApS
|
|
598
|
+
* @license https://opensource.org/license/mit The MIT License
|
|
599
|
+
*
|
|
600
|
+
*/
|
|
601
|
+
/**
|
|
602
|
+
* Guest token flow. Issues access/refresh tokens for the database's default
|
|
603
|
+
* user (the sub-user used for anonymous access) without any user credentials.
|
|
604
|
+
* `clientSecret` is only required when the OAuth client is not public.
|
|
605
|
+
*/
|
|
606
|
+
var GuestFlow = class {
|
|
607
|
+
constructor(options) {
|
|
608
|
+
this.options = options;
|
|
609
|
+
this.service = new Gc2Service(options);
|
|
610
|
+
}
|
|
611
|
+
async signIn() {
|
|
612
|
+
var _this = this;
|
|
613
|
+
const { access_token, refresh_token } = await _this.service.getGuestToken();
|
|
614
|
+
setTokens({
|
|
615
|
+
accessToken: access_token,
|
|
616
|
+
refreshToken: refresh_token
|
|
617
|
+
});
|
|
618
|
+
setOptions({
|
|
619
|
+
clientId: _this.options.clientId,
|
|
620
|
+
host: _this.options.host,
|
|
621
|
+
redirectUri: "",
|
|
622
|
+
clientSecret: _this.options.clientSecret
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
signOut() {
|
|
626
|
+
this.clear();
|
|
627
|
+
}
|
|
628
|
+
clear() {
|
|
629
|
+
clearTokens();
|
|
630
|
+
clearOptions();
|
|
631
|
+
clearNonce();
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
|
|
578
635
|
//#endregion
|
|
579
636
|
//#region src/http/errors.ts
|
|
580
637
|
/**
|
|
@@ -3040,6 +3097,157 @@ var Mapcache = class {
|
|
|
3040
3097
|
}
|
|
3041
3098
|
};
|
|
3042
3099
|
|
|
3100
|
+
//#endregion
|
|
3101
|
+
//#region src/ogc/Ogc.ts
|
|
3102
|
+
/** Default CRS of the OGC API: WGS 84 in longitude/latitude order. */
|
|
3103
|
+
const OGC_CRS84 = "http://www.opengis.net/def/crs/OGC/1.3/CRS84";
|
|
3104
|
+
/**
|
|
3105
|
+
* CRS URI for an EPSG code, e.g. `ogcEpsgCrs(25832)`. Note that
|
|
3106
|
+
* `ogcEpsgCrs(4326)` is latitude/longitude order; use `OGC_CRS84` for lon/lat.
|
|
3107
|
+
*/
|
|
3108
|
+
function ogcEpsgCrs(epsg) {
|
|
3109
|
+
return `http://www.opengis.net/def/crs/EPSG/0/${epsg}`;
|
|
3110
|
+
}
|
|
3111
|
+
function bboxToString(bbox) {
|
|
3112
|
+
return typeof bbox === "string" ? bbox : bbox.join(",");
|
|
3113
|
+
}
|
|
3114
|
+
function spatialQuery(options) {
|
|
3115
|
+
const query = {};
|
|
3116
|
+
if ((options === null || options === void 0 ? void 0 : options.bbox) !== void 0) query.bbox = bboxToString(options.bbox);
|
|
3117
|
+
if ((options === null || options === void 0 ? void 0 : options.bboxCrs) !== void 0) query["bbox-crs"] = options.bboxCrs;
|
|
3118
|
+
if ((options === null || options === void 0 ? void 0 : options.crs) !== void 0) query.crs = options.crs;
|
|
3119
|
+
if ((options === null || options === void 0 ? void 0 : options.datetime) !== void 0) query.datetime = options.datetime;
|
|
3120
|
+
return query;
|
|
3121
|
+
}
|
|
3122
|
+
function nonEmpty(query) {
|
|
3123
|
+
return Object.keys(query).length > 0 ? query : void 0;
|
|
3124
|
+
}
|
|
3125
|
+
/**
|
|
3126
|
+
* OGC API Features (Part 1 Core, Part 2 CRS) and OGC API Maps (Part 1 Core)
|
|
3127
|
+
* wrapper for `/api/v4/ogc/database/{database}`.
|
|
3128
|
+
*
|
|
3129
|
+
* The endpoints accept Bearer token, HTTP Basic and anonymous requests. A
|
|
3130
|
+
* Bearer token must match the `database` in the path. Anonymous callers read
|
|
3131
|
+
* layers below `Read/write`; a `Read/write` collection answers 401 (Basic
|
|
3132
|
+
* challenge) for anonymous callers and 403 for identities without privilege.
|
|
3133
|
+
* Geofence rules, versioning and workflow are applied server-side.
|
|
3134
|
+
*
|
|
3135
|
+
* Map images cannot be fetched through this client; use `mapUrl` /
|
|
3136
|
+
* `datasetMapUrl` to build image URLs for `<img>` tags or map libraries.
|
|
3137
|
+
*
|
|
3138
|
+
* ```ts
|
|
3139
|
+
* const ogc = new Ogc(createCentiaClient({ baseUrl, auth }));
|
|
3140
|
+
* const page = await ogc.getItems('my_database', 'my_schema.roads', { bbox: [9, 55, 10, 56], limit: 100 });
|
|
3141
|
+
* ```
|
|
3142
|
+
*/
|
|
3143
|
+
var Ogc = class {
|
|
3144
|
+
constructor(client) {
|
|
3145
|
+
this.client = client;
|
|
3146
|
+
}
|
|
3147
|
+
basePath(database) {
|
|
3148
|
+
return `api/v4/ogc/database/${encodeURIComponent(database)}`;
|
|
3149
|
+
}
|
|
3150
|
+
collectionPath(database, collectionId) {
|
|
3151
|
+
return `${this.basePath(database)}/collections/${encodeURIComponent(collectionId)}`;
|
|
3152
|
+
}
|
|
3153
|
+
/** The landing page with links to conformance, collections and the OpenAPI document. */
|
|
3154
|
+
async getLandingPage(database) {
|
|
3155
|
+
var _this = this;
|
|
3156
|
+
return _this.client.request({
|
|
3157
|
+
path: _this.basePath(database),
|
|
3158
|
+
method: "GET"
|
|
3159
|
+
});
|
|
3160
|
+
}
|
|
3161
|
+
/** Conformance classes implemented by the server. */
|
|
3162
|
+
async getConformance(database) {
|
|
3163
|
+
var _this2 = this;
|
|
3164
|
+
return _this2.client.request({
|
|
3165
|
+
path: `${_this2.basePath(database)}/conformance`,
|
|
3166
|
+
method: "GET"
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
3169
|
+
/** The collections (OWS-enabled layers) the caller may read, paged. */
|
|
3170
|
+
async getCollections(database, options) {
|
|
3171
|
+
var _this3 = this;
|
|
3172
|
+
const query = {};
|
|
3173
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) !== void 0) query.limit = String(options.limit);
|
|
3174
|
+
if ((options === null || options === void 0 ? void 0 : options.offset) !== void 0) query.offset = String(options.offset);
|
|
3175
|
+
return _this3.client.request({
|
|
3176
|
+
path: `${_this3.basePath(database)}/collections`,
|
|
3177
|
+
method: "GET",
|
|
3178
|
+
query: nonEmpty(query)
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* One collection. Throws a `CentiaApiError` with status 404 (unknown),
|
|
3183
|
+
* 401 (anonymous caller, credentials required) or 403 (no privilege).
|
|
3184
|
+
*/
|
|
3185
|
+
async getCollection(database, collectionId) {
|
|
3186
|
+
var _this4 = this;
|
|
3187
|
+
return _this4.client.request({
|
|
3188
|
+
path: _this4.collectionPath(database, collectionId),
|
|
3189
|
+
method: "GET"
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3192
|
+
/**
|
|
3193
|
+
* Features of a collection as a GeoJSON FeatureCollection page. The default
|
|
3194
|
+
* page size is 10; follow `links` with `rel: 'next'` or pass `offset`.
|
|
3195
|
+
*/
|
|
3196
|
+
async getItems(database, collectionId, options) {
|
|
3197
|
+
var _this5 = this;
|
|
3198
|
+
const query = {};
|
|
3199
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) !== void 0) query.limit = String(options.limit);
|
|
3200
|
+
if ((options === null || options === void 0 ? void 0 : options.offset) !== void 0) query.offset = String(options.offset);
|
|
3201
|
+
Object.assign(query, spatialQuery(options));
|
|
3202
|
+
return _this5.client.request({
|
|
3203
|
+
path: `${_this5.collectionPath(database, collectionId)}/items`,
|
|
3204
|
+
method: "GET",
|
|
3205
|
+
query: nonEmpty(query),
|
|
3206
|
+
accept: "application/geo+json"
|
|
3207
|
+
});
|
|
3208
|
+
}
|
|
3209
|
+
/** One feature by primary key. Throws a 404 `CentiaApiError` when it does not exist. */
|
|
3210
|
+
async getItem(database, collectionId, featureId, options) {
|
|
3211
|
+
var _this6 = this;
|
|
3212
|
+
const query = {};
|
|
3213
|
+
if ((options === null || options === void 0 ? void 0 : options.crs) !== void 0) query.crs = options.crs;
|
|
3214
|
+
if ((options === null || options === void 0 ? void 0 : options.datetime) !== void 0) query.datetime = options.datetime;
|
|
3215
|
+
return _this6.client.request({
|
|
3216
|
+
path: `${_this6.collectionPath(database, collectionId)}/items/${encodeURIComponent(String(featureId))}`,
|
|
3217
|
+
method: "GET",
|
|
3218
|
+
query: nonEmpty(query),
|
|
3219
|
+
accept: "application/geo+json"
|
|
3220
|
+
});
|
|
3221
|
+
}
|
|
3222
|
+
/**
|
|
3223
|
+
* URL of a rendered map of one collection (PNG/JPEG), without fetching it.
|
|
3224
|
+
* Authorization travels in the `Authorization` header, so for protected
|
|
3225
|
+
* collections fetch the image with the header set (or use Basic auth).
|
|
3226
|
+
*/
|
|
3227
|
+
mapUrl(database, collectionId, options) {
|
|
3228
|
+
return this.buildUrl(`${this.collectionPath(database, collectionId)}/map`, this.mapQuery(options));
|
|
3229
|
+
}
|
|
3230
|
+
/** URL of a rendered map of several collections of the same schema. */
|
|
3231
|
+
datasetMapUrl(database, collections, options) {
|
|
3232
|
+
const query = _objectSpread2({ collections: collections.join(",") }, this.mapQuery(options));
|
|
3233
|
+
return this.buildUrl(`${this.basePath(database)}/map`, query);
|
|
3234
|
+
}
|
|
3235
|
+
mapQuery(options) {
|
|
3236
|
+
const query = spatialQuery(options);
|
|
3237
|
+
if ((options === null || options === void 0 ? void 0 : options.width) !== void 0) query.width = String(options.width);
|
|
3238
|
+
if ((options === null || options === void 0 ? void 0 : options.height) !== void 0) query.height = String(options.height);
|
|
3239
|
+
if ((options === null || options === void 0 ? void 0 : options.format) !== void 0) query.f = options.format;
|
|
3240
|
+
if ((options === null || options === void 0 ? void 0 : options.transparent) !== void 0) query.transparent = String(options.transparent);
|
|
3241
|
+
if ((options === null || options === void 0 ? void 0 : options.bgcolor) !== void 0) query.bgcolor = options.bgcolor;
|
|
3242
|
+
return query;
|
|
3243
|
+
}
|
|
3244
|
+
buildUrl(path, query) {
|
|
3245
|
+
let url = `${this.client.baseUrl}/${path}`;
|
|
3246
|
+
if (Object.keys(query).length > 0) url += `?${new URLSearchParams(query).toString()}`;
|
|
3247
|
+
return url;
|
|
3248
|
+
}
|
|
3249
|
+
};
|
|
3250
|
+
|
|
3043
3251
|
//#endregion
|
|
3044
3252
|
//#region src/keyvalue/Keyvalue.ts
|
|
3045
3253
|
/**
|
|
@@ -3299,5 +3507,5 @@ function isExpired(jwt, skewSeconds) {
|
|
|
3299
3507
|
*/
|
|
3300
3508
|
|
|
3301
3509
|
//#endregion
|
|
3302
|
-
export { CentiaApiError, Claims, CodeFlow, Features, Gql, Keyvalue, Mapcache, Meta, NotLoggedInError, Ows, PasswordFlow, Rpc, SessionExpiredError, SignUp, Sql, SqlNoToken, Stats, Status, Tables, Users, Wfs, Ws, createApi, createCentiaAdminClient, createCentiaClient, createSqlBuilder, createTokenProvider, isCentiaApiError };
|
|
3510
|
+
export { CentiaApiError, Claims, CodeFlow, Features, Gql, GuestFlow, Keyvalue, Mapcache, Meta, NotLoggedInError, OGC_CRS84, Ogc, Ows, PasswordFlow, Rpc, SessionExpiredError, SignUp, Sql, SqlNoToken, Stats, Status, Tables, Users, Wfs, Ws, createApi, createCentiaAdminClient, createCentiaClient, createSqlBuilder, createTokenProvider, isCentiaApiError, ogcEpsgCrs };
|
|
3303
3511
|
//# sourceMappingURL=centia-io-sdk.js.map
|