@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.
@@ -346,6 +346,9 @@
346
346
  isSignUpOptions(options) {
347
347
  return "parentDb" in options;
348
348
  }
349
+ isGuestFlowOptions(options) {
350
+ return "database" in options && !("username" in options);
351
+ }
349
352
  buildUrl(path) {
350
353
  if (path.startsWith("http://") || path.startsWith("https://")) return path;
351
354
  return `${this.host}${path}`;
@@ -458,12 +461,24 @@
458
461
  database
459
462
  });
460
463
  }
461
- async getRefreshToken(token) {
464
+ async getGuestToken() {
462
465
  var _this5 = this;
463
- var _this$options$tokenUr3;
464
- const path = (_this$options$tokenUr3 = _this5.options.tokenUri) !== null && _this$options$tokenUr3 !== void 0 ? _this$options$tokenUr3 : `${_this5.host}/api/v4/oauth`;
466
+ let database;
467
+ if (_this5.isGuestFlowOptions(_this5.options)) database = _this5.options.database;
468
+ else throw new Error("GuestFlow options required for this operation");
469
+ const path = `${_this5.host}/api/v4/oauth/guest`;
465
470
  return _this5.request(_this5.buildUrl(path), "POST", {
471
+ database,
466
472
  client_id: _this5.options.clientId,
473
+ client_secret: _this5.options.clientSecret
474
+ });
475
+ }
476
+ async getRefreshToken(token) {
477
+ var _this6 = this;
478
+ var _this$options$tokenUr3;
479
+ const path = (_this$options$tokenUr3 = _this6.options.tokenUri) !== null && _this$options$tokenUr3 !== void 0 ? _this$options$tokenUr3 : `${_this6.host}/api/v4/oauth`;
480
+ return _this6.request(_this6.buildUrl(path), "POST", {
481
+ client_id: _this6.options.clientId,
467
482
  grant_type: "refresh_token",
468
483
  refresh_token: token
469
484
  });
@@ -581,6 +596,48 @@
581
596
  }
582
597
  };
583
598
 
599
+ //#endregion
600
+ //#region src/GuestFlow.ts
601
+ /**
602
+ * @author Martin Høgh <mh@mapcentia.com>
603
+ * @copyright 2013-2026 MapCentia ApS
604
+ * @license https://opensource.org/license/mit The MIT License
605
+ *
606
+ */
607
+ /**
608
+ * Guest token flow. Issues access/refresh tokens for the database's default
609
+ * user (the sub-user used for anonymous access) without any user credentials.
610
+ * `clientSecret` is only required when the OAuth client is not public.
611
+ */
612
+ var GuestFlow = class {
613
+ constructor(options) {
614
+ this.options = options;
615
+ this.service = new Gc2Service(options);
616
+ }
617
+ async signIn() {
618
+ var _this = this;
619
+ const { access_token, refresh_token } = await _this.service.getGuestToken();
620
+ setTokens({
621
+ accessToken: access_token,
622
+ refreshToken: refresh_token
623
+ });
624
+ setOptions({
625
+ clientId: _this.options.clientId,
626
+ host: _this.options.host,
627
+ redirectUri: "",
628
+ clientSecret: _this.options.clientSecret
629
+ });
630
+ }
631
+ signOut() {
632
+ this.clear();
633
+ }
634
+ clear() {
635
+ clearTokens();
636
+ clearOptions();
637
+ clearNonce();
638
+ }
639
+ };
640
+
584
641
  //#endregion
585
642
  //#region src/http/errors.ts
586
643
  /**
@@ -3461,6 +3518,7 @@ exports.Claims = Claims;
3461
3518
  exports.CodeFlow = CodeFlow;
3462
3519
  exports.Features = Features;
3463
3520
  exports.Gql = Gql;
3521
+ exports.GuestFlow = GuestFlow;
3464
3522
  exports.Keyvalue = Keyvalue;
3465
3523
  exports.Mapcache = Mapcache;
3466
3524
  exports.Meta = Meta;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centia-io/sdk",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Centia-io TypeScript SDK",
5
5
  "author": "Martin Høgh",
6
6
  "license": "MIT",