@hipnation-truth/sdk 0.24.0 → 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/react.d.ts CHANGED
@@ -1257,12 +1257,26 @@ declare const ENVIRONMENTS: {
1257
1257
  readonly production: "production";
1258
1258
  };
1259
1259
  type Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];
1260
+ /**
1261
+ * Fetches a user-identity JWT for Convex calls. Return the token from
1262
+ * your identity provider's Clerk JWT template named "convex"
1263
+ * (e.g. `getToken({ template: "convex" })` from `@clerk/expo`), or
1264
+ * `null` when no user is signed in.
1265
+ */
1266
+ type AuthTokenFetcher = () => Promise<string | null | undefined>;
1260
1267
  /**
1261
1268
  * Configuration for initializing a TruthClient.
1262
1269
  */
1263
1270
  interface TruthClientConfig {
1264
1271
  /** API key for authenticating with the Truth platform (e.g. "hn_live_...") */
1265
1272
  apiKey: string;
1273
+ /**
1274
+ * Per-call Clerk JWT fetcher for Convex data access. When provided,
1275
+ * every Convex query/mutation/action carries the caller's identity;
1276
+ * Convex deployments with `CLERK_AUTH_REQUIRED` enabled reject calls
1277
+ * without it. Omit for service contexts that don't act as a user.
1278
+ */
1279
+ getAuthToken?: AuthTokenFetcher;
1266
1280
  /** Target environment */
1267
1281
  environment: Environment;
1268
1282
  /** Override the default Convex URL for data access */
@@ -1448,12 +1462,6 @@ interface SetConversationTaskStatusInput {
1448
1462
  taskId: string;
1449
1463
  status: ConversationTaskStatus;
1450
1464
  resolvedBy?: string;
1451
- /**
1452
- * Email of the user performing the action. Truth excludes the actor
1453
- * from the task-action push fan-out (legacy parity) — omit it and the
1454
- * actor notifies themselves.
1455
- */
1456
- actor?: string;
1457
1465
  }
1458
1466
  interface UpdateConversationTaskInput {
1459
1467
  taskId: string;
@@ -1468,18 +1476,6 @@ interface UpdateConversationTaskInput {
1468
1476
  status?: ConversationTaskStatus;
1469
1477
  assignee?: string;
1470
1478
  type?: string;
1471
- /**
1472
- * Email of the user performing the action. Truth excludes the actor
1473
- * from the task-action push fan-out (legacy parity) — omit it and the
1474
- * actor notifies themselves.
1475
- */
1476
- actor?: string;
1477
- }
1478
- interface SetConversationTaskArchivedInput {
1479
- taskId: string;
1480
- archived: boolean;
1481
- /** Email of the acting user — excluded from the archive push fan-out. */
1482
- actor?: string;
1483
1479
  }
1484
1480
  interface SendConversationMessageInput {
1485
1481
  fromNumber: string;
@@ -1512,11 +1508,6 @@ declare class ConversationTasksSubresource {
1512
1508
  setStatus(input: SetConversationTaskStatusInput): Promise<{
1513
1509
  ok: true;
1514
1510
  }>;
1515
- /** Archive or un-archive a task (hides it from My Tasks without deleting). */
1516
- setArchived(input: SetConversationTaskArchivedInput): Promise<{
1517
- ok: true;
1518
- changed: boolean;
1519
- }>;
1520
1511
  /**
1521
1512
  * Update task fields (priority, assignee, description, type). Wraps
1522
1513
  * `PATCH /api/conversations/tasks/{id}` so CommHub doesn't have to
@@ -2813,6 +2804,16 @@ interface TruthProviderProps {
2813
2804
  source?: string;
2814
2805
  sourceVersion?: string;
2815
2806
  tenantId?: string;
2807
+ /**
2808
+ * Per-call Clerk JWT fetcher (template "convex") identifying the
2809
+ * signed-in user to Convex. Wire it to your identity provider, e.g.
2810
+ * `useAuth().getToken({ template: "convex" })` from `@clerk/expo`.
2811
+ * Applied to both the live websocket client (React hooks) and the
2812
+ * shared `TruthClient` (resource methods). Identity changes are
2813
+ * picked up without remounting — the latest fetcher is read through
2814
+ * a ref on every call.
2815
+ */
2816
+ getAuthToken?: AuthTokenFetcher;
2816
2817
  /**
2817
2818
  * Synchronous encrypted KV mirror for durable offline reads, injected
2818
2819
  * by the consuming app (e.g. MMKV on `ch/`). Omit on web — the SDK
@@ -2830,7 +2831,7 @@ interface TruthProviderProps {
2830
2831
  offlineEnabled?: boolean;
2831
2832
  children: ReactNode;
2832
2833
  }
2833
- declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, offlineStore, offlineEnabled, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
2834
+ declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, getAuthToken, offlineStore, offlineEnabled, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
2834
2835
 
2835
2836
  /**
2836
2837
  * React hooks for conversation reminders — bulk lookup keyed by
package/dist/react.js CHANGED
@@ -4,8 +4,10 @@ var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __reflectGet = Reflect.get;
9
11
  var __pow = Math.pow;
10
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
13
  var __spreadValues = (a, b) => {
@@ -32,6 +34,7 @@ var __copyProps = (to, from, except, desc) => {
32
34
  return to;
33
35
  };
34
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
35
38
  var __async = (__this, __arguments, generator) => {
36
39
  return new Promise((resolve, reject) => {
37
40
  var fulfilled = (value) => {
@@ -373,8 +376,53 @@ var import_react_query_persist_client = require("@tanstack/react-query-persist-c
373
376
  var import_react3 = require("convex/react");
374
377
  var import_react4 = require("react");
375
378
 
376
- // src/client.ts
379
+ // src/auth-convex-client.ts
377
380
  var import_browser = require("convex/browser");
381
+ var AuthAwareConvexHttpClient = class _AuthAwareConvexHttpClient extends import_browser.ConvexHttpClient {
382
+ constructor(address, getAuthToken) {
383
+ super(address);
384
+ this.getAuthToken = getAuthToken;
385
+ }
386
+ /**
387
+ * Pull a fresh token from the fetcher and apply it. A fetcher error
388
+ * keeps the previously-applied token rather than dropping auth
389
+ * mid-session.
390
+ */
391
+ syncAuth() {
392
+ return __async(this, null, function* () {
393
+ if (!this.getAuthToken) {
394
+ return;
395
+ }
396
+ try {
397
+ const token = yield this.getAuthToken();
398
+ if (token) {
399
+ this.setAuth(token);
400
+ } else {
401
+ this.clearAuth();
402
+ }
403
+ } catch (e) {
404
+ }
405
+ });
406
+ }
407
+ query(query, ...args) {
408
+ return __async(this, null, function* () {
409
+ yield this.syncAuth();
410
+ return __superGet(_AuthAwareConvexHttpClient.prototype, this, "query").call(this, query, ...args);
411
+ });
412
+ }
413
+ mutation(mutation, ...args) {
414
+ return __async(this, null, function* () {
415
+ yield this.syncAuth();
416
+ return __superGet(_AuthAwareConvexHttpClient.prototype, this, "mutation").call(this, mutation, ...args);
417
+ });
418
+ }
419
+ action(action, ...args) {
420
+ return __async(this, null, function* () {
421
+ yield this.syncAuth();
422
+ return __superGet(_AuthAwareConvexHttpClient.prototype, this, "action").call(this, action, ...args);
423
+ });
424
+ }
425
+ };
378
426
 
379
427
  // src/resources/appointments.ts
380
428
  var AppointmentResource = class {
@@ -622,22 +670,10 @@ var ConversationTasksSubresource = class {
622
670
  return __async(this, null, function* () {
623
671
  return this.post(
624
672
  `/conversations/tasks/${encodeURIComponent(input.taskId)}/status`,
625
- __spreadValues(__spreadValues({
626
- id: input.taskId,
627
- status: input.status
628
- }, input.resolvedBy ? { resolvedBy: input.resolvedBy } : {}), input.actor ? { actor: input.actor } : {})
629
- );
630
- });
631
- }
632
- /** Archive or un-archive a task (hides it from My Tasks without deleting). */
633
- setArchived(input) {
634
- return __async(this, null, function* () {
635
- return this.post(
636
- `/conversations/tasks/${encodeURIComponent(input.taskId)}/archive`,
637
673
  __spreadValues({
638
674
  id: input.taskId,
639
- archived: input.archived
640
- }, input.actor ? { actor: input.actor } : {})
675
+ status: input.status
676
+ }, input.resolvedBy ? { resolvedBy: input.resolvedBy } : {})
641
677
  );
642
678
  });
643
679
  }
@@ -650,12 +686,12 @@ var ConversationTasksSubresource = class {
650
686
  return __async(this, null, function* () {
651
687
  return this.patch(
652
688
  `/conversations/tasks/${encodeURIComponent(input.taskId)}`,
653
- __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
689
+ __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
654
690
  id: input.taskId,
655
691
  conversationId: input.conversationId,
656
692
  author: input.author,
657
693
  description: input.description
658
- }, input.title !== void 0 ? { title: input.title } : {}), input.priority ? { priority: input.priority } : {}), input.status ? { status: input.status } : {}), input.assignee !== void 0 ? { assignee: input.assignee } : {}), input.type !== void 0 ? { type: input.type } : {}), input.actor ? { actor: input.actor } : {})
694
+ }, input.title !== void 0 ? { title: input.title } : {}), input.priority ? { priority: input.priority } : {}), input.status ? { status: input.status } : {}), input.assignee !== void 0 ? { assignee: input.assignee } : {}), input.type !== void 0 ? { type: input.type } : {})
659
695
  );
660
696
  });
661
697
  }
@@ -2203,7 +2239,7 @@ var TruthClient = class {
2203
2239
  this._webPushReady = null;
2204
2240
  var _a, _b, _c, _d, _e, _f, _g, _h;
2205
2241
  const convexUrl = (_b = (_a = config.convexUrl) != null ? _a : CONVEX_URLS[config.environment]) != null ? _b : CONVEX_URLS.local;
2206
- this.convex = new import_browser.ConvexHttpClient(convexUrl);
2242
+ this.convex = new AuthAwareConvexHttpClient(convexUrl, config.getAuthToken);
2207
2243
  this.tracker = new Tracker({
2208
2244
  apiKey: config.apiKey,
2209
2245
  environment: config.environment,
@@ -2494,6 +2530,7 @@ function TruthProvider({
2494
2530
  source,
2495
2531
  sourceVersion,
2496
2532
  tenantId,
2533
+ getAuthToken,
2497
2534
  offlineStore = NOOP_STORE,
2498
2535
  offlineEnabled = false,
2499
2536
  children
@@ -2503,6 +2540,26 @@ function TruthProvider({
2503
2540
  const resolvedApiBaseUrl = (_a = apiBaseUrl != null ? apiBaseUrl : readEnv("EXPO_PUBLIC_TRUTH_API_BASE_URL")) != null ? _a : resolveApiBaseUrl(environment);
2504
2541
  const resolvedApiKey = (_b = apiKey != null ? apiKey : readEnv("EXPO_PUBLIC_TRUTH_API_KEY")) != null ? _b : "";
2505
2542
  const convexClient = (0, import_react4.useMemo)(() => new import_react3.ConvexReactClient(url), [url]);
2543
+ const getAuthTokenRef = (0, import_react4.useRef)(getAuthToken);
2544
+ getAuthTokenRef.current = getAuthToken;
2545
+ const hasAuthFetcher = Boolean(getAuthToken);
2546
+ const stableGetAuthToken = (0, import_react4.useMemo)(
2547
+ () => hasAuthFetcher ? () => __async(null, null, function* () {
2548
+ var _a2, _b2;
2549
+ return (_b2 = yield (_a2 = getAuthTokenRef.current) == null ? void 0 : _a2.call(getAuthTokenRef)) != null ? _b2 : null;
2550
+ }) : void 0,
2551
+ [hasAuthFetcher]
2552
+ );
2553
+ (0, import_react4.useEffect)(() => {
2554
+ if (stableGetAuthToken) {
2555
+ convexClient.setAuth(() => __async(null, null, function* () {
2556
+ var _a2;
2557
+ return (_a2 = yield stableGetAuthToken()) != null ? _a2 : null;
2558
+ }));
2559
+ } else {
2560
+ convexClient.clearAuth();
2561
+ }
2562
+ }, [convexClient, stableGetAuthToken]);
2506
2563
  const convexQueryClient = (0, import_react4.useMemo)(
2507
2564
  () => new import_react_query3.ConvexQueryClient(convexClient),
2508
2565
  [convexClient]
@@ -2544,7 +2601,8 @@ function TruthProvider({
2544
2601
  source: source != null ? source : "unknown",
2545
2602
  sourceVersion: sourceVersion != null ? sourceVersion : "unknown",
2546
2603
  tenantId: tenantId != null ? tenantId : "",
2547
- autoInitServiceWorker: false
2604
+ autoInitServiceWorker: false,
2605
+ getAuthToken: stableGetAuthToken
2548
2606
  }),
2549
2607
  [
2550
2608
  url,
@@ -2553,7 +2611,8 @@ function TruthProvider({
2553
2611
  environment,
2554
2612
  source,
2555
2613
  sourceVersion,
2556
- tenantId
2614
+ tenantId,
2615
+ stableGetAuthToken
2557
2616
  ]
2558
2617
  );
2559
2618
  (0, import_react4.useEffect)(() => {