@hipnation-truth/sdk 0.26.2 → 0.26.4
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 +14 -0
- package/dist/react.js +301 -280
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -122,259 +122,19 @@ __export(react_exports, {
|
|
|
122
122
|
module.exports = __toCommonJS(react_exports);
|
|
123
123
|
|
|
124
124
|
// src/react/calls.ts
|
|
125
|
-
var
|
|
126
|
-
var import_server = require("convex/server");
|
|
127
|
-
|
|
128
|
-
// src/react/offline/use-persistent-query.ts
|
|
129
|
-
var import_react_query = require("@convex-dev/react-query");
|
|
130
|
-
var import_react_query2 = require("@tanstack/react-query");
|
|
131
|
-
function usePersistentQuery(ref, args) {
|
|
132
|
-
const { data } = (0, import_react_query2.useQuery)(
|
|
133
|
-
(0, import_react_query.convexQuery)(
|
|
134
|
-
ref,
|
|
135
|
-
args
|
|
136
|
-
)
|
|
137
|
-
);
|
|
138
|
-
return data;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// src/react/calls.ts
|
|
142
|
-
var DialpadCallState = {
|
|
143
|
-
Calling: "calling",
|
|
144
|
-
Ringing: "ringing",
|
|
145
|
-
Connected: "connected",
|
|
146
|
-
Hold: "hold",
|
|
147
|
-
Hangup: "hangup",
|
|
148
|
-
Missed: "missed",
|
|
149
|
-
VoicemailUploaded: "voicemail_uploaded"
|
|
150
|
-
};
|
|
151
|
-
var RINGING_CALL_STATES = /* @__PURE__ */ new Set([
|
|
152
|
-
DialpadCallState.Calling,
|
|
153
|
-
DialpadCallState.Ringing
|
|
154
|
-
]);
|
|
155
|
-
var CONNECTED_CALL_STATES = /* @__PURE__ */ new Set([
|
|
156
|
-
DialpadCallState.Connected
|
|
157
|
-
]);
|
|
158
|
-
var ACTIVE_CALL_STATES = /* @__PURE__ */ new Set([
|
|
159
|
-
...RINGING_CALL_STATES,
|
|
160
|
-
...CONNECTED_CALL_STATES
|
|
161
|
-
]);
|
|
162
|
-
var TERMINAL_CALL_STATES = /* @__PURE__ */ new Set([
|
|
163
|
-
DialpadCallState.Hangup,
|
|
164
|
-
DialpadCallState.Missed,
|
|
165
|
-
DialpadCallState.VoicemailUploaded
|
|
166
|
-
]);
|
|
167
|
-
var listActiveRef = (0, import_server.makeFunctionReference)("dialpadCallEvents:listActive");
|
|
168
|
-
var listForConversationRef = (0, import_server.makeFunctionReference)("dialpadCallEvents:listForConversation");
|
|
169
|
-
var getByCallIdRef = (0, import_server.makeFunctionReference)("dialpadCallEvents:getByCallId");
|
|
170
|
-
var listLogForCallIdRef = (0, import_server.makeFunctionReference)("dialpadCallEvents:listLogForCallId");
|
|
171
|
-
var SKIP = "skip";
|
|
172
|
-
function toResult(value, skipped) {
|
|
173
|
-
if (skipped) {
|
|
174
|
-
return { data: void 0, loading: false, error: void 0 };
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
data: value,
|
|
178
|
-
loading: value === void 0,
|
|
179
|
-
error: void 0
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function useActiveCalls(options) {
|
|
183
|
-
const result = (0, import_react.useQuery)(listActiveRef, options != null ? options : {});
|
|
184
|
-
return toResult(result, false);
|
|
185
|
-
}
|
|
186
|
-
function useDialpadCallsForConversation(conversationId, options) {
|
|
187
|
-
const skipped = !conversationId;
|
|
188
|
-
const result = usePersistentQuery(
|
|
189
|
-
listForConversationRef,
|
|
190
|
-
skipped ? SKIP : {
|
|
191
|
-
conversationId,
|
|
192
|
-
limit: options == null ? void 0 : options.limit
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
return toResult(result, skipped);
|
|
196
|
-
}
|
|
197
|
-
function useDialpadCallByCallId(callId) {
|
|
198
|
-
const skipped = !callId;
|
|
199
|
-
const result = usePersistentQuery(
|
|
200
|
-
getByCallIdRef,
|
|
201
|
-
skipped ? SKIP : { callId }
|
|
202
|
-
);
|
|
203
|
-
return toResult(result, skipped);
|
|
204
|
-
}
|
|
205
|
-
function useDialpadCallLog(callId, options) {
|
|
206
|
-
const skipped = !callId;
|
|
207
|
-
const result = usePersistentQuery(
|
|
208
|
-
listLogForCallIdRef,
|
|
209
|
-
skipped ? SKIP : { callId, limit: options == null ? void 0 : options.limit }
|
|
210
|
-
);
|
|
211
|
-
return toResult(result, skipped);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// src/react/conversation-by-id.ts
|
|
125
|
+
var import_react3 = require("convex/react");
|
|
215
126
|
var import_server2 = require("convex/server");
|
|
216
|
-
var conversationsGetByIdRef = (0, import_server2.makeFunctionReference)("conversations:getById");
|
|
217
|
-
function useConversationById(id) {
|
|
218
|
-
const skipped = !id;
|
|
219
|
-
const result = usePersistentQuery(
|
|
220
|
-
conversationsGetByIdRef,
|
|
221
|
-
skipped ? "skip" : { id }
|
|
222
|
-
);
|
|
223
|
-
if (skipped) {
|
|
224
|
-
return { data: void 0, loading: false, error: void 0 };
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
data: result,
|
|
228
|
-
loading: result === void 0,
|
|
229
|
-
error: void 0
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
127
|
|
|
233
|
-
// src/react/
|
|
234
|
-
var import_server3 = require("convex/server");
|
|
235
|
-
var import_react2 = require("react");
|
|
236
|
-
var conversationsListForUserRef = (0, import_server3.makeFunctionReference)("conversations:listForUser");
|
|
237
|
-
var conversationsSearchForUserRef = (0, import_server3.makeFunctionReference)("conversations:searchForUser");
|
|
238
|
-
var conversationsGetUnreadTotalForUserRef = (0, import_server3.makeFunctionReference)("conversations:getUnreadTotalForUser");
|
|
239
|
-
var conversationsGetUnreadAggregateForUserRef = (0, import_server3.makeFunctionReference)("conversations:getUnreadAggregateForUser");
|
|
240
|
-
var conversationsGetByPhonePairRef = (0, import_server3.makeFunctionReference)("conversations:getByPhonePair");
|
|
241
|
-
var conversationMessagesGetByConversationIdRef = (0, import_server3.makeFunctionReference)("conversationMessages:getByConversationId");
|
|
242
|
-
var conversationNotesListForConversationRef = (0, import_server3.makeFunctionReference)("conversationNotes:listForConversation");
|
|
243
|
-
var conversationTasksListForConversationRef = (0, import_server3.makeFunctionReference)("conversationTasks:listForConversation");
|
|
244
|
-
var conversationNotesListByPhonePairRef = (0, import_server3.makeFunctionReference)("conversationNotes:listByPhonePair");
|
|
245
|
-
var conversationTasksListByPhonePairRef = (0, import_server3.makeFunctionReference)("conversationTasks:listByPhonePair");
|
|
246
|
-
var conversationTasksListForUserRef = (0, import_server3.makeFunctionReference)("conversationTasks:listForUser");
|
|
247
|
-
var SKIP2 = "skip";
|
|
248
|
-
function toResult2(value, skipped) {
|
|
249
|
-
if (skipped) {
|
|
250
|
-
return { data: void 0, loading: false, error: void 0 };
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
data: value,
|
|
254
|
-
loading: value === void 0,
|
|
255
|
-
error: void 0
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
function useConversations(filters) {
|
|
259
|
-
var _a, _b;
|
|
260
|
-
const trimmedSearch = (_b = (_a = filters.search) == null ? void 0 : _a.trim()) != null ? _b : "";
|
|
261
|
-
const isSearchMode = trimmedSearch.length > 0;
|
|
262
|
-
const skipped = !filters.userId;
|
|
263
|
-
const listResult = usePersistentQuery(
|
|
264
|
-
conversationsListForUserRef,
|
|
265
|
-
skipped || isSearchMode ? SKIP2 : {
|
|
266
|
-
userId: filters.userId,
|
|
267
|
-
limit: filters.limit
|
|
268
|
-
}
|
|
269
|
-
);
|
|
270
|
-
const searchResult = usePersistentQuery(
|
|
271
|
-
conversationsSearchForUserRef,
|
|
272
|
-
skipped || !isSearchMode ? SKIP2 : {
|
|
273
|
-
userId: filters.userId,
|
|
274
|
-
search: trimmedSearch,
|
|
275
|
-
limit: filters.limit
|
|
276
|
-
}
|
|
277
|
-
);
|
|
278
|
-
return toResult2(isSearchMode ? searchResult : listResult, skipped);
|
|
279
|
-
}
|
|
280
|
-
function useConversationByPhonePair(phonePair) {
|
|
281
|
-
const skipped = !phonePair;
|
|
282
|
-
const result = usePersistentQuery(
|
|
283
|
-
conversationsGetByPhonePairRef,
|
|
284
|
-
skipped ? SKIP2 : { phonePair }
|
|
285
|
-
);
|
|
286
|
-
return toResult2(result, skipped);
|
|
287
|
-
}
|
|
288
|
-
function useMessages(conversationId, options) {
|
|
289
|
-
const skipped = !conversationId;
|
|
290
|
-
const result = usePersistentQuery(
|
|
291
|
-
conversationMessagesGetByConversationIdRef,
|
|
292
|
-
skipped ? SKIP2 : {
|
|
293
|
-
conversationId,
|
|
294
|
-
limit: options == null ? void 0 : options.limit
|
|
295
|
-
}
|
|
296
|
-
);
|
|
297
|
-
return toResult2(result, skipped);
|
|
298
|
-
}
|
|
299
|
-
function useUnreadCount(userId) {
|
|
300
|
-
const skipped = !userId;
|
|
301
|
-
const result = usePersistentQuery(
|
|
302
|
-
conversationsGetUnreadTotalForUserRef,
|
|
303
|
-
skipped ? SKIP2 : { userId }
|
|
304
|
-
);
|
|
305
|
-
return toResult2(result, skipped);
|
|
306
|
-
}
|
|
307
|
-
function useUnreadAggregate(userId, options) {
|
|
308
|
-
const skipped = !userId;
|
|
309
|
-
const phones = options == null ? void 0 : options.providerPhones;
|
|
310
|
-
const stablePhones = useMemoizedPhones(phones);
|
|
311
|
-
const result = usePersistentQuery(
|
|
312
|
-
conversationsGetUnreadAggregateForUserRef,
|
|
313
|
-
skipped ? SKIP2 : {
|
|
314
|
-
userId,
|
|
315
|
-
providerPhones: stablePhones
|
|
316
|
-
}
|
|
317
|
-
);
|
|
318
|
-
return toResult2(result, skipped);
|
|
319
|
-
}
|
|
320
|
-
function useMemoizedPhones(phones) {
|
|
321
|
-
const key = phones ? [...phones].sort().join("|") : "";
|
|
322
|
-
return (0, import_react2.useMemo)(
|
|
323
|
-
() => (phones == null ? void 0 : phones.length) ? [...phones].sort() : void 0,
|
|
324
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
325
|
-
[key]
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
function useConversationNotes(conversationId) {
|
|
329
|
-
const skipped = !conversationId;
|
|
330
|
-
const result = usePersistentQuery(
|
|
331
|
-
conversationNotesListForConversationRef,
|
|
332
|
-
skipped ? SKIP2 : { conversationId }
|
|
333
|
-
);
|
|
334
|
-
return toResult2(result, skipped);
|
|
335
|
-
}
|
|
336
|
-
function useConversationTasks(conversationId) {
|
|
337
|
-
const skipped = !conversationId;
|
|
338
|
-
const result = usePersistentQuery(
|
|
339
|
-
conversationTasksListForConversationRef,
|
|
340
|
-
skipped ? SKIP2 : { conversationId }
|
|
341
|
-
);
|
|
342
|
-
return toResult2(result, skipped);
|
|
343
|
-
}
|
|
344
|
-
function useConversationNotesByPhonePair(phonePair) {
|
|
345
|
-
const skipped = !phonePair;
|
|
346
|
-
const result = usePersistentQuery(
|
|
347
|
-
conversationNotesListByPhonePairRef,
|
|
348
|
-
skipped ? SKIP2 : { phonePair }
|
|
349
|
-
);
|
|
350
|
-
return toResult2(result, skipped);
|
|
351
|
-
}
|
|
352
|
-
function useConversationTasksForUser(userId, options) {
|
|
353
|
-
const skipped = !userId;
|
|
354
|
-
const result = usePersistentQuery(
|
|
355
|
-
conversationTasksListForUserRef,
|
|
356
|
-
skipped ? SKIP2 : { userId, limit: options == null ? void 0 : options.limit }
|
|
357
|
-
);
|
|
358
|
-
return toResult2(result, skipped);
|
|
359
|
-
}
|
|
360
|
-
function useConversationTasksByPhonePair(phonePair) {
|
|
361
|
-
const skipped = !phonePair;
|
|
362
|
-
const result = usePersistentQuery(
|
|
363
|
-
conversationTasksListByPhonePairRef,
|
|
364
|
-
skipped ? SKIP2 : { phonePair }
|
|
365
|
-
);
|
|
366
|
-
return toResult2(result, skipped);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// src/react/hooks.ts
|
|
370
|
-
var import_react5 = require("react");
|
|
371
|
-
|
|
372
|
-
// src/react/provider.ts
|
|
128
|
+
// src/react/offline/use-persistent-query.ts
|
|
373
129
|
var import_react_query3 = require("@convex-dev/react-query");
|
|
374
130
|
var import_react_query4 = require("@tanstack/react-query");
|
|
131
|
+
|
|
132
|
+
// src/react/provider.ts
|
|
133
|
+
var import_react_query = require("@convex-dev/react-query");
|
|
134
|
+
var import_react_query2 = require("@tanstack/react-query");
|
|
375
135
|
var import_react_query_persist_client = require("@tanstack/react-query-persist-client");
|
|
376
|
-
var
|
|
377
|
-
var
|
|
136
|
+
var import_react = require("convex/react");
|
|
137
|
+
var import_react2 = require("react");
|
|
378
138
|
|
|
379
139
|
// src/auth-convex-client.ts
|
|
380
140
|
var import_browser = require("convex/browser");
|
|
@@ -1917,8 +1677,8 @@ var TranslationResource = class {
|
|
|
1917
1677
|
};
|
|
1918
1678
|
|
|
1919
1679
|
// src/resources/user-settings.ts
|
|
1920
|
-
var
|
|
1921
|
-
var upsertNotificationsRef = (0,
|
|
1680
|
+
var import_server = require("convex/server");
|
|
1681
|
+
var upsertNotificationsRef = (0, import_server.makeFunctionReference)("userSettings:upsertNotifications");
|
|
1922
1682
|
var UserSettingsResource = class {
|
|
1923
1683
|
constructor(convex) {
|
|
1924
1684
|
this.convex = convex;
|
|
@@ -2484,20 +2244,20 @@ function readEnv(name) {
|
|
|
2484
2244
|
const v = process.env[name];
|
|
2485
2245
|
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
2486
2246
|
}
|
|
2487
|
-
var TruthSdkContext = (0,
|
|
2247
|
+
var TruthSdkContext = (0, import_react2.createContext)(null);
|
|
2488
2248
|
function useTruthSdkContext() {
|
|
2489
|
-
return (0,
|
|
2249
|
+
return (0, import_react2.useContext)(TruthSdkContext);
|
|
2490
2250
|
}
|
|
2491
2251
|
function useOfflineStore() {
|
|
2492
2252
|
var _a, _b;
|
|
2493
|
-
return (_b = (_a = (0,
|
|
2253
|
+
return (_b = (_a = (0, import_react2.useContext)(TruthSdkContext)) == null ? void 0 : _a.offlineStore) != null ? _b : NOOP_STORE;
|
|
2494
2254
|
}
|
|
2495
2255
|
function useOfflineEnabled() {
|
|
2496
2256
|
var _a, _b;
|
|
2497
|
-
return (_b = (_a = (0,
|
|
2257
|
+
return (_b = (_a = (0, import_react2.useContext)(TruthSdkContext)) == null ? void 0 : _a.offlineEnabled) != null ? _b : false;
|
|
2498
2258
|
}
|
|
2499
2259
|
function useTruthClient() {
|
|
2500
|
-
const ctx = (0,
|
|
2260
|
+
const ctx = (0, import_react2.useContext)(TruthSdkContext);
|
|
2501
2261
|
if (!ctx) {
|
|
2502
2262
|
throw new Error(
|
|
2503
2263
|
"useTruthClient() called outside <TruthProvider>. Wrap your app in <TruthProvider> from @hipnation-truth/sdk/react."
|
|
@@ -2531,33 +2291,38 @@ function TruthProvider({
|
|
|
2531
2291
|
const url = resolveConvexUrl(environment, convexUrl);
|
|
2532
2292
|
const resolvedApiBaseUrl = (_a = apiBaseUrl != null ? apiBaseUrl : readEnv("EXPO_PUBLIC_TRUTH_API_BASE_URL")) != null ? _a : resolveApiBaseUrl(environment);
|
|
2533
2293
|
const resolvedApiKey = (_b = apiKey != null ? apiKey : readEnv("EXPO_PUBLIC_TRUTH_API_KEY")) != null ? _b : "";
|
|
2534
|
-
const convexClient = (0,
|
|
2535
|
-
const getAuthTokenRef = (0,
|
|
2294
|
+
const convexClient = (0, import_react2.useMemo)(() => new import_react.ConvexReactClient(url), [url]);
|
|
2295
|
+
const getAuthTokenRef = (0, import_react2.useRef)(getAuthToken);
|
|
2536
2296
|
getAuthTokenRef.current = getAuthToken;
|
|
2537
2297
|
const hasAuthFetcher = Boolean(getAuthToken);
|
|
2538
|
-
const stableGetAuthToken = (0,
|
|
2298
|
+
const stableGetAuthToken = (0, import_react2.useMemo)(
|
|
2539
2299
|
() => hasAuthFetcher ? () => __async(null, null, function* () {
|
|
2540
2300
|
var _a2, _b2;
|
|
2541
2301
|
return (_b2 = yield (_a2 = getAuthTokenRef.current) == null ? void 0 : _a2.call(getAuthTokenRef)) != null ? _b2 : null;
|
|
2542
2302
|
}) : void 0,
|
|
2543
2303
|
[hasAuthFetcher]
|
|
2544
2304
|
);
|
|
2545
|
-
(0,
|
|
2305
|
+
const [convexAuthed, setConvexAuthed] = (0, import_react2.useState)(false);
|
|
2306
|
+
(0, import_react2.useEffect)(() => {
|
|
2546
2307
|
if (stableGetAuthToken) {
|
|
2547
|
-
convexClient.setAuth(
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2308
|
+
convexClient.setAuth(
|
|
2309
|
+
() => __async(null, null, function* () {
|
|
2310
|
+
var _a2;
|
|
2311
|
+
return (_a2 = yield stableGetAuthToken()) != null ? _a2 : null;
|
|
2312
|
+
}),
|
|
2313
|
+
(isAuthenticated) => setConvexAuthed(isAuthenticated)
|
|
2314
|
+
);
|
|
2551
2315
|
} else {
|
|
2552
2316
|
convexClient.clearAuth();
|
|
2317
|
+
setConvexAuthed(false);
|
|
2553
2318
|
}
|
|
2554
2319
|
}, [convexClient, stableGetAuthToken]);
|
|
2555
|
-
const convexQueryClient = (0,
|
|
2556
|
-
() => new
|
|
2320
|
+
const convexQueryClient = (0, import_react2.useMemo)(
|
|
2321
|
+
() => new import_react_query.ConvexQueryClient(convexClient),
|
|
2557
2322
|
[convexClient]
|
|
2558
2323
|
);
|
|
2559
|
-
const queryClient = (0,
|
|
2560
|
-
return new
|
|
2324
|
+
const queryClient = (0, import_react2.useMemo)(() => {
|
|
2325
|
+
return new import_react_query2.QueryClient({
|
|
2561
2326
|
defaultOptions: {
|
|
2562
2327
|
queries: {
|
|
2563
2328
|
queryKeyHashFn: convexQueryClient.hashFn(),
|
|
@@ -2570,18 +2335,18 @@ function TruthProvider({
|
|
|
2570
2335
|
}
|
|
2571
2336
|
});
|
|
2572
2337
|
}, [convexQueryClient]);
|
|
2573
|
-
const connectedClientRef = (0,
|
|
2574
|
-
(0,
|
|
2338
|
+
const connectedClientRef = (0, import_react2.useRef)(null);
|
|
2339
|
+
(0, import_react2.useEffect)(() => {
|
|
2575
2340
|
if (connectedClientRef.current !== convexQueryClient) {
|
|
2576
2341
|
convexQueryClient.connect(queryClient);
|
|
2577
2342
|
connectedClientRef.current = convexQueryClient;
|
|
2578
2343
|
}
|
|
2579
2344
|
}, [convexQueryClient, queryClient]);
|
|
2580
|
-
const persister = (0,
|
|
2345
|
+
const persister = (0, import_react2.useMemo)(
|
|
2581
2346
|
() => offlineEnabled && !isNoopStore(offlineStore) ? createOfflinePersister(offlineStore) : void 0,
|
|
2582
2347
|
[offlineEnabled, offlineStore]
|
|
2583
2348
|
);
|
|
2584
|
-
const truthClient = (0,
|
|
2349
|
+
const truthClient = (0, import_react2.useMemo)(
|
|
2585
2350
|
() => new TruthClient({
|
|
2586
2351
|
// Pin the resource client to the SAME deployment the React hooks
|
|
2587
2352
|
// use; without this it falls back to CONVEX_URLS[environment] and a
|
|
@@ -2607,7 +2372,7 @@ function TruthProvider({
|
|
|
2607
2372
|
stableGetAuthToken
|
|
2608
2373
|
]
|
|
2609
2374
|
);
|
|
2610
|
-
(0,
|
|
2375
|
+
(0, import_react2.useEffect)(() => {
|
|
2611
2376
|
_activeClient = truthClient;
|
|
2612
2377
|
return () => {
|
|
2613
2378
|
if (_activeClient === truthClient) {
|
|
@@ -2617,14 +2382,16 @@ function TruthProvider({
|
|
|
2617
2382
|
});
|
|
2618
2383
|
};
|
|
2619
2384
|
}, [truthClient]);
|
|
2620
|
-
const sdkContext = (0,
|
|
2385
|
+
const sdkContext = (0, import_react2.useMemo)(
|
|
2621
2386
|
() => ({
|
|
2622
2387
|
apiBaseUrl: resolvedApiBaseUrl,
|
|
2623
2388
|
apiKey: resolvedApiKey,
|
|
2624
2389
|
environment,
|
|
2625
2390
|
client: truthClient,
|
|
2626
2391
|
offlineStore,
|
|
2627
|
-
offlineEnabled
|
|
2392
|
+
offlineEnabled,
|
|
2393
|
+
authGated: hasAuthFetcher,
|
|
2394
|
+
authReady: convexAuthed
|
|
2628
2395
|
}),
|
|
2629
2396
|
[
|
|
2630
2397
|
resolvedApiBaseUrl,
|
|
@@ -2632,15 +2399,17 @@ function TruthProvider({
|
|
|
2632
2399
|
environment,
|
|
2633
2400
|
truthClient,
|
|
2634
2401
|
offlineStore,
|
|
2635
|
-
offlineEnabled
|
|
2402
|
+
offlineEnabled,
|
|
2403
|
+
hasAuthFetcher,
|
|
2404
|
+
convexAuthed
|
|
2636
2405
|
]
|
|
2637
2406
|
);
|
|
2638
|
-
const convexTree = (0,
|
|
2639
|
-
|
|
2407
|
+
const convexTree = (0, import_react2.createElement)(
|
|
2408
|
+
import_react.ConvexProvider,
|
|
2640
2409
|
{ client: convexClient },
|
|
2641
2410
|
children
|
|
2642
2411
|
);
|
|
2643
|
-
const queryTree = persister ? (0,
|
|
2412
|
+
const queryTree = persister ? (0, import_react2.createElement)(
|
|
2644
2413
|
import_react_query_persist_client.PersistQueryClientProvider,
|
|
2645
2414
|
{
|
|
2646
2415
|
client: queryClient,
|
|
@@ -2653,15 +2422,267 @@ function TruthProvider({
|
|
|
2653
2422
|
}
|
|
2654
2423
|
},
|
|
2655
2424
|
convexTree
|
|
2656
|
-
) : (0,
|
|
2657
|
-
return (0,
|
|
2425
|
+
) : (0, import_react2.createElement)(import_react_query2.QueryClientProvider, { client: queryClient }, convexTree);
|
|
2426
|
+
return (0, import_react2.createElement)(
|
|
2658
2427
|
TruthSdkContext.Provider,
|
|
2659
2428
|
{ value: sdkContext },
|
|
2660
2429
|
queryTree
|
|
2661
2430
|
);
|
|
2662
2431
|
}
|
|
2663
2432
|
|
|
2433
|
+
// src/react/queries-ready.ts
|
|
2434
|
+
function useConvexQueriesReady() {
|
|
2435
|
+
const ctx = useTruthSdkContext();
|
|
2436
|
+
if (!(ctx == null ? void 0 : ctx.authGated)) {
|
|
2437
|
+
return true;
|
|
2438
|
+
}
|
|
2439
|
+
return ctx.authReady;
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
// src/react/offline/use-persistent-query.ts
|
|
2443
|
+
function usePersistentQuery(ref, args) {
|
|
2444
|
+
const ready = useConvexQueriesReady();
|
|
2445
|
+
const effectiveArgs = ready ? args : "skip";
|
|
2446
|
+
const { data } = (0, import_react_query4.useQuery)(
|
|
2447
|
+
(0, import_react_query3.convexQuery)(
|
|
2448
|
+
ref,
|
|
2449
|
+
effectiveArgs
|
|
2450
|
+
)
|
|
2451
|
+
);
|
|
2452
|
+
return data;
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
// src/react/calls.ts
|
|
2456
|
+
var DialpadCallState = {
|
|
2457
|
+
Calling: "calling",
|
|
2458
|
+
Ringing: "ringing",
|
|
2459
|
+
Connected: "connected",
|
|
2460
|
+
Hold: "hold",
|
|
2461
|
+
Hangup: "hangup",
|
|
2462
|
+
Missed: "missed",
|
|
2463
|
+
VoicemailUploaded: "voicemail_uploaded"
|
|
2464
|
+
};
|
|
2465
|
+
var RINGING_CALL_STATES = /* @__PURE__ */ new Set([
|
|
2466
|
+
DialpadCallState.Calling,
|
|
2467
|
+
DialpadCallState.Ringing
|
|
2468
|
+
]);
|
|
2469
|
+
var CONNECTED_CALL_STATES = /* @__PURE__ */ new Set([
|
|
2470
|
+
DialpadCallState.Connected
|
|
2471
|
+
]);
|
|
2472
|
+
var ACTIVE_CALL_STATES = /* @__PURE__ */ new Set([
|
|
2473
|
+
...RINGING_CALL_STATES,
|
|
2474
|
+
...CONNECTED_CALL_STATES
|
|
2475
|
+
]);
|
|
2476
|
+
var TERMINAL_CALL_STATES = /* @__PURE__ */ new Set([
|
|
2477
|
+
DialpadCallState.Hangup,
|
|
2478
|
+
DialpadCallState.Missed,
|
|
2479
|
+
DialpadCallState.VoicemailUploaded
|
|
2480
|
+
]);
|
|
2481
|
+
var listActiveRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:listActive");
|
|
2482
|
+
var listForConversationRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:listForConversation");
|
|
2483
|
+
var getByCallIdRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:getByCallId");
|
|
2484
|
+
var listLogForCallIdRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:listLogForCallId");
|
|
2485
|
+
var SKIP = "skip";
|
|
2486
|
+
function toResult(value, skipped) {
|
|
2487
|
+
if (skipped) {
|
|
2488
|
+
return { data: void 0, loading: false, error: void 0 };
|
|
2489
|
+
}
|
|
2490
|
+
return {
|
|
2491
|
+
data: value,
|
|
2492
|
+
loading: value === void 0,
|
|
2493
|
+
error: void 0
|
|
2494
|
+
};
|
|
2495
|
+
}
|
|
2496
|
+
function useActiveCalls(options) {
|
|
2497
|
+
const ready = useConvexQueriesReady();
|
|
2498
|
+
const result = (0, import_react3.useQuery)(listActiveRef, ready ? options != null ? options : {} : "skip");
|
|
2499
|
+
return toResult(result, false);
|
|
2500
|
+
}
|
|
2501
|
+
function useDialpadCallsForConversation(conversationId, options) {
|
|
2502
|
+
const skipped = !conversationId;
|
|
2503
|
+
const result = usePersistentQuery(
|
|
2504
|
+
listForConversationRef,
|
|
2505
|
+
skipped ? SKIP : {
|
|
2506
|
+
conversationId,
|
|
2507
|
+
limit: options == null ? void 0 : options.limit
|
|
2508
|
+
}
|
|
2509
|
+
);
|
|
2510
|
+
return toResult(result, skipped);
|
|
2511
|
+
}
|
|
2512
|
+
function useDialpadCallByCallId(callId) {
|
|
2513
|
+
const skipped = !callId;
|
|
2514
|
+
const result = usePersistentQuery(
|
|
2515
|
+
getByCallIdRef,
|
|
2516
|
+
skipped ? SKIP : { callId }
|
|
2517
|
+
);
|
|
2518
|
+
return toResult(result, skipped);
|
|
2519
|
+
}
|
|
2520
|
+
function useDialpadCallLog(callId, options) {
|
|
2521
|
+
const skipped = !callId;
|
|
2522
|
+
const result = usePersistentQuery(
|
|
2523
|
+
listLogForCallIdRef,
|
|
2524
|
+
skipped ? SKIP : { callId, limit: options == null ? void 0 : options.limit }
|
|
2525
|
+
);
|
|
2526
|
+
return toResult(result, skipped);
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
// src/react/conversation-by-id.ts
|
|
2530
|
+
var import_server3 = require("convex/server");
|
|
2531
|
+
var conversationsGetByIdRef = (0, import_server3.makeFunctionReference)("conversations:getById");
|
|
2532
|
+
function useConversationById(id) {
|
|
2533
|
+
const skipped = !id;
|
|
2534
|
+
const result = usePersistentQuery(
|
|
2535
|
+
conversationsGetByIdRef,
|
|
2536
|
+
skipped ? "skip" : { id }
|
|
2537
|
+
);
|
|
2538
|
+
if (skipped) {
|
|
2539
|
+
return { data: void 0, loading: false, error: void 0 };
|
|
2540
|
+
}
|
|
2541
|
+
return {
|
|
2542
|
+
data: result,
|
|
2543
|
+
loading: result === void 0,
|
|
2544
|
+
error: void 0
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2548
|
+
// src/react/conversations.ts
|
|
2549
|
+
var import_server4 = require("convex/server");
|
|
2550
|
+
var import_react4 = require("react");
|
|
2551
|
+
var conversationsListForUserRef = (0, import_server4.makeFunctionReference)("conversations:listForUser");
|
|
2552
|
+
var conversationsSearchForUserRef = (0, import_server4.makeFunctionReference)("conversations:searchForUser");
|
|
2553
|
+
var conversationsGetUnreadTotalForUserRef = (0, import_server4.makeFunctionReference)("conversations:getUnreadTotalForUser");
|
|
2554
|
+
var conversationsGetUnreadAggregateForUserRef = (0, import_server4.makeFunctionReference)("conversations:getUnreadAggregateForUser");
|
|
2555
|
+
var conversationsGetByPhonePairRef = (0, import_server4.makeFunctionReference)("conversations:getByPhonePair");
|
|
2556
|
+
var conversationMessagesGetByConversationIdRef = (0, import_server4.makeFunctionReference)("conversationMessages:getByConversationId");
|
|
2557
|
+
var conversationNotesListForConversationRef = (0, import_server4.makeFunctionReference)("conversationNotes:listForConversation");
|
|
2558
|
+
var conversationTasksListForConversationRef = (0, import_server4.makeFunctionReference)("conversationTasks:listForConversation");
|
|
2559
|
+
var conversationNotesListByPhonePairRef = (0, import_server4.makeFunctionReference)("conversationNotes:listByPhonePair");
|
|
2560
|
+
var conversationTasksListByPhonePairRef = (0, import_server4.makeFunctionReference)("conversationTasks:listByPhonePair");
|
|
2561
|
+
var conversationTasksListForUserRef = (0, import_server4.makeFunctionReference)("conversationTasks:listForUser");
|
|
2562
|
+
var SKIP2 = "skip";
|
|
2563
|
+
function toResult2(value, skipped) {
|
|
2564
|
+
if (skipped) {
|
|
2565
|
+
return { data: void 0, loading: false, error: void 0 };
|
|
2566
|
+
}
|
|
2567
|
+
return {
|
|
2568
|
+
data: value,
|
|
2569
|
+
loading: value === void 0,
|
|
2570
|
+
error: void 0
|
|
2571
|
+
};
|
|
2572
|
+
}
|
|
2573
|
+
function useConversations(filters) {
|
|
2574
|
+
var _a, _b;
|
|
2575
|
+
const trimmedSearch = (_b = (_a = filters.search) == null ? void 0 : _a.trim()) != null ? _b : "";
|
|
2576
|
+
const isSearchMode = trimmedSearch.length > 0;
|
|
2577
|
+
const skipped = !filters.userId;
|
|
2578
|
+
const listResult = usePersistentQuery(
|
|
2579
|
+
conversationsListForUserRef,
|
|
2580
|
+
skipped || isSearchMode ? SKIP2 : {
|
|
2581
|
+
userId: filters.userId,
|
|
2582
|
+
limit: filters.limit
|
|
2583
|
+
}
|
|
2584
|
+
);
|
|
2585
|
+
const searchResult = usePersistentQuery(
|
|
2586
|
+
conversationsSearchForUserRef,
|
|
2587
|
+
skipped || !isSearchMode ? SKIP2 : {
|
|
2588
|
+
userId: filters.userId,
|
|
2589
|
+
search: trimmedSearch,
|
|
2590
|
+
limit: filters.limit
|
|
2591
|
+
}
|
|
2592
|
+
);
|
|
2593
|
+
return toResult2(isSearchMode ? searchResult : listResult, skipped);
|
|
2594
|
+
}
|
|
2595
|
+
function useConversationByPhonePair(phonePair) {
|
|
2596
|
+
const skipped = !phonePair;
|
|
2597
|
+
const result = usePersistentQuery(
|
|
2598
|
+
conversationsGetByPhonePairRef,
|
|
2599
|
+
skipped ? SKIP2 : { phonePair }
|
|
2600
|
+
);
|
|
2601
|
+
return toResult2(result, skipped);
|
|
2602
|
+
}
|
|
2603
|
+
function useMessages(conversationId, options) {
|
|
2604
|
+
const skipped = !conversationId;
|
|
2605
|
+
const result = usePersistentQuery(
|
|
2606
|
+
conversationMessagesGetByConversationIdRef,
|
|
2607
|
+
skipped ? SKIP2 : {
|
|
2608
|
+
conversationId,
|
|
2609
|
+
limit: options == null ? void 0 : options.limit
|
|
2610
|
+
}
|
|
2611
|
+
);
|
|
2612
|
+
return toResult2(result, skipped);
|
|
2613
|
+
}
|
|
2614
|
+
function useUnreadCount(userId) {
|
|
2615
|
+
const skipped = !userId;
|
|
2616
|
+
const result = usePersistentQuery(
|
|
2617
|
+
conversationsGetUnreadTotalForUserRef,
|
|
2618
|
+
skipped ? SKIP2 : { userId }
|
|
2619
|
+
);
|
|
2620
|
+
return toResult2(result, skipped);
|
|
2621
|
+
}
|
|
2622
|
+
function useUnreadAggregate(userId, options) {
|
|
2623
|
+
const skipped = !userId;
|
|
2624
|
+
const phones = options == null ? void 0 : options.providerPhones;
|
|
2625
|
+
const stablePhones = useMemoizedPhones(phones);
|
|
2626
|
+
const result = usePersistentQuery(
|
|
2627
|
+
conversationsGetUnreadAggregateForUserRef,
|
|
2628
|
+
skipped ? SKIP2 : {
|
|
2629
|
+
userId,
|
|
2630
|
+
providerPhones: stablePhones
|
|
2631
|
+
}
|
|
2632
|
+
);
|
|
2633
|
+
return toResult2(result, skipped);
|
|
2634
|
+
}
|
|
2635
|
+
function useMemoizedPhones(phones) {
|
|
2636
|
+
const key = phones ? [...phones].sort().join("|") : "";
|
|
2637
|
+
return (0, import_react4.useMemo)(
|
|
2638
|
+
() => (phones == null ? void 0 : phones.length) ? [...phones].sort() : void 0,
|
|
2639
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2640
|
+
[key]
|
|
2641
|
+
);
|
|
2642
|
+
}
|
|
2643
|
+
function useConversationNotes(conversationId) {
|
|
2644
|
+
const skipped = !conversationId;
|
|
2645
|
+
const result = usePersistentQuery(
|
|
2646
|
+
conversationNotesListForConversationRef,
|
|
2647
|
+
skipped ? SKIP2 : { conversationId }
|
|
2648
|
+
);
|
|
2649
|
+
return toResult2(result, skipped);
|
|
2650
|
+
}
|
|
2651
|
+
function useConversationTasks(conversationId) {
|
|
2652
|
+
const skipped = !conversationId;
|
|
2653
|
+
const result = usePersistentQuery(
|
|
2654
|
+
conversationTasksListForConversationRef,
|
|
2655
|
+
skipped ? SKIP2 : { conversationId }
|
|
2656
|
+
);
|
|
2657
|
+
return toResult2(result, skipped);
|
|
2658
|
+
}
|
|
2659
|
+
function useConversationNotesByPhonePair(phonePair) {
|
|
2660
|
+
const skipped = !phonePair;
|
|
2661
|
+
const result = usePersistentQuery(
|
|
2662
|
+
conversationNotesListByPhonePairRef,
|
|
2663
|
+
skipped ? SKIP2 : { phonePair }
|
|
2664
|
+
);
|
|
2665
|
+
return toResult2(result, skipped);
|
|
2666
|
+
}
|
|
2667
|
+
function useConversationTasksForUser(userId, options) {
|
|
2668
|
+
const skipped = !userId;
|
|
2669
|
+
const result = usePersistentQuery(
|
|
2670
|
+
conversationTasksListForUserRef,
|
|
2671
|
+
skipped ? SKIP2 : { userId, limit: options == null ? void 0 : options.limit }
|
|
2672
|
+
);
|
|
2673
|
+
return toResult2(result, skipped);
|
|
2674
|
+
}
|
|
2675
|
+
function useConversationTasksByPhonePair(phonePair) {
|
|
2676
|
+
const skipped = !phonePair;
|
|
2677
|
+
const result = usePersistentQuery(
|
|
2678
|
+
conversationTasksListByPhonePairRef,
|
|
2679
|
+
skipped ? SKIP2 : { phonePair }
|
|
2680
|
+
);
|
|
2681
|
+
return toResult2(result, skipped);
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2664
2684
|
// src/react/hooks.ts
|
|
2685
|
+
var import_react5 = require("react");
|
|
2665
2686
|
var import_server5 = require("convex/server");
|
|
2666
2687
|
var patientsListRef = (0, import_server5.makeFunctionReference)("patients:list");
|
|
2667
2688
|
var patientsGetRef = (0, import_server5.makeFunctionReference)("patients:get");
|