@hipnation-truth/sdk 0.23.2 → 0.25.1

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/dist/index.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __getProtoOf = Object.getPrototypeOf;
3
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
5
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
+ var __reflectGet = Reflect.get;
5
7
  var __pow = Math.pow;
6
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
9
  var __spreadValues = (a, b) => {
@@ -15,6 +17,7 @@ var __spreadValues = (a, b) => {
15
17
  }
16
18
  return a;
17
19
  };
20
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
18
21
  var __async = (__this, __arguments, generator) => {
19
22
  return new Promise((resolve, reject) => {
20
23
  var fulfilled = (value) => {
@@ -36,8 +39,53 @@ var __async = (__this, __arguments, generator) => {
36
39
  });
37
40
  };
38
41
 
39
- // src/client.ts
42
+ // src/auth-convex-client.ts
40
43
  import { ConvexHttpClient } from "convex/browser";
44
+ var AuthAwareConvexHttpClient = class _AuthAwareConvexHttpClient extends ConvexHttpClient {
45
+ constructor(address, getAuthToken) {
46
+ super(address);
47
+ this.getAuthToken = getAuthToken;
48
+ }
49
+ /**
50
+ * Pull a fresh token from the fetcher and apply it. A fetcher error
51
+ * keeps the previously-applied token rather than dropping auth
52
+ * mid-session.
53
+ */
54
+ syncAuth() {
55
+ return __async(this, null, function* () {
56
+ if (!this.getAuthToken) {
57
+ return;
58
+ }
59
+ try {
60
+ const token = yield this.getAuthToken();
61
+ if (token) {
62
+ this.setAuth(token);
63
+ } else {
64
+ this.clearAuth();
65
+ }
66
+ } catch (e) {
67
+ }
68
+ });
69
+ }
70
+ query(query, ...args) {
71
+ return __async(this, null, function* () {
72
+ yield this.syncAuth();
73
+ return __superGet(_AuthAwareConvexHttpClient.prototype, this, "query").call(this, query, ...args);
74
+ });
75
+ }
76
+ mutation(mutation, ...args) {
77
+ return __async(this, null, function* () {
78
+ yield this.syncAuth();
79
+ return __superGet(_AuthAwareConvexHttpClient.prototype, this, "mutation").call(this, mutation, ...args);
80
+ });
81
+ }
82
+ action(action, ...args) {
83
+ return __async(this, null, function* () {
84
+ yield this.syncAuth();
85
+ return __superGet(_AuthAwareConvexHttpClient.prototype, this, "action").call(this, action, ...args);
86
+ });
87
+ }
88
+ };
41
89
 
42
90
  // src/resources/appointments.ts
43
91
  var AppointmentResource = class {
@@ -1868,7 +1916,7 @@ var TruthClient = class {
1868
1916
  this._webPushReady = null;
1869
1917
  var _a, _b, _c, _d, _e, _f, _g, _h;
1870
1918
  const convexUrl = (_b = (_a = config.convexUrl) != null ? _a : CONVEX_URLS[config.environment]) != null ? _b : CONVEX_URLS.local;
1871
- this.convex = new ConvexHttpClient(convexUrl);
1919
+ this.convex = new AuthAwareConvexHttpClient(convexUrl, config.getAuthToken);
1872
1920
  this.tracker = new Tracker({
1873
1921
  apiKey: config.apiKey,
1874
1922
  environment: config.environment,