@centia-io/sdk 0.2.13 → 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.
@@ -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 getRefreshToken(token) {
458
+ async getGuestToken() {
456
459
  var _this5 = this;
457
- var _this$options$tokenUr3;
458
- const path = (_this$options$tokenUr3 = _this5.options.tokenUri) !== null && _this$options$tokenUr3 !== void 0 ? _this$options$tokenUr3 : `${_this5.host}/api/v4/oauth`;
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
  /**
@@ -3450,5 +3507,5 @@ function isExpired(jwt, skewSeconds) {
3450
3507
  */
3451
3508
 
3452
3509
  //#endregion
3453
- export { CentiaApiError, Claims, CodeFlow, Features, Gql, 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 };
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 };
3454
3511
  //# sourceMappingURL=centia-io-sdk.js.map