1
1
import { type Rivet , RivetClient } from "@rivetkit/engine-api-full" ;
2
2
import { infiniteQueryOptions , queryOptions } from "@tanstack/react-query" ;
3
+ import { getConfig , ls } from "@/components" ;
3
4
import {
4
5
type Actor ,
5
6
ActorFeature ,
@@ -15,11 +16,11 @@ import {
15
16
type DefaultDataProvider ,
16
17
RECORDS_PER_PAGE ,
17
18
} from "./default-data-provider" ;
18
- import { getConfig } from "@/components/lib/config" ;
19
+
20
+ const mightRequireAuth = __APP_TYPE__ === "engine" ;
19
21
20
22
export type CreateNamespace = {
21
23
displayName : string ;
22
- name ?: string ;
23
24
} ;
24
25
25
26
export type Namespace = {
@@ -30,8 +31,8 @@ export type Namespace = {
30
31
} ;
31
32
32
33
export function createClient (
33
- baseUrl = getConfig ( ) . apiUrl ,
34
- opts : { token : ( ( ) => string ) | string } ,
34
+ baseUrl = engineEnv ( ) . VITE_APP_API_URL ,
35
+ opts : { token : ( ( ) => string ) | string | ( ( ) => Promise < string > ) } ,
35
36
) {
36
37
return new RivetClient ( {
37
38
baseUrl : ( ) => baseUrl ,
@@ -43,7 +44,7 @@ export function createClient(
43
44
export const createGlobalContext = ( opts : {
44
45
engineToken : ( ( ) => string ) | string ;
45
46
} ) => {
46
- const client = createClient ( getConfig ( ) . apiUrl , {
47
+ const client = createClient ( engineEnv ( ) . VITE_APP_API_URL , {
47
48
token : opts . engineToken ,
48
49
} ) ;
49
50
return {
@@ -88,7 +89,7 @@ export const createGlobalContext = (opts: {
88
89
mutationFn : async ( data : CreateNamespace ) => {
89
90
const response = await client . namespaces . create ( {
90
91
displayName : data . displayName ,
91
- name : data . name || convertStringToId ( data . displayName ) ,
92
+ name : convertStringToId ( data . displayName ) ,
92
93
} ) ;
93
94
94
95
return {
@@ -133,7 +134,7 @@ export const createNamespaceContext = ({
133
134
retry : shouldRetryAllExpect403 ,
134
135
throwOnError : noThrow ,
135
136
meta : {
136
- mightRequireAuth : true ,
137
+ mightRequireAuth,
137
138
} ,
138
139
} ) ;
139
140
} ,
@@ -158,7 +159,7 @@ export const createNamespaceContext = ({
158
159
retry : shouldRetryAllExpect403 ,
159
160
throwOnError : noThrow ,
160
161
meta : {
161
- mightRequireAuth : true ,
162
+ mightRequireAuth,
162
163
} ,
163
164
} ) ;
164
165
} ,
@@ -187,7 +188,7 @@ export const createNamespaceContext = ({
187
188
retry : shouldRetryAllExpect403 ,
188
189
throwOnError : noThrow ,
189
190
meta : {
190
- mightRequireAuth : true ,
191
+ mightRequireAuth,
191
192
} ,
192
193
} ) ;
193
194
} ,
@@ -214,7 +215,7 @@ export const createNamespaceContext = ({
214
215
retry : shouldRetryAllExpect403 ,
215
216
throwOnError : noThrow ,
216
217
meta : {
217
- mightRequireAuth : true ,
218
+ mightRequireAuth,
218
219
} ,
219
220
} ) ;
220
221
} ,
@@ -289,7 +290,7 @@ export const createNamespaceContext = ({
289
290
retry : shouldRetryAllExpect403 ,
290
291
throwOnError : noThrow ,
291
292
meta : {
292
- mightRequireAuth : true ,
293
+ mightRequireAuth,
293
294
} ,
294
295
} ) ;
295
296
} ,
@@ -330,7 +331,7 @@ export const createNamespaceContext = ({
330
331
retry : shouldRetryAllExpect403 ,
331
332
throwOnError : noThrow ,
332
333
meta : {
333
- mightRequireAuth : true ,
334
+ mightRequireAuth,
334
335
} ,
335
336
} ) ;
336
337
} ,
@@ -354,7 +355,7 @@ export const createNamespaceContext = ({
354
355
throwOnError : noThrow ,
355
356
retry : shouldRetryAllExpect403 ,
356
357
meta : {
357
- mightRequireAuth : true ,
358
+ mightRequireAuth,
358
359
} ,
359
360
} ;
360
361
} ,
@@ -364,7 +365,7 @@ export const createNamespaceContext = ({
364
365
throwOnError : noThrow ,
365
366
retry : shouldRetryAllExpect403 ,
366
367
meta : {
367
- mightRequireAuth : true ,
368
+ mightRequireAuth,
368
369
} ,
369
370
mutationFn : async ( ) => {
370
371
await client . actorsDelete ( actorId ) ;
@@ -375,14 +376,14 @@ export const createNamespaceContext = ({
375
376
376
377
return {
377
378
...dataProvider ,
378
- runnersQueryOptions ( opts : { namespace : string } ) {
379
+ runnersQueryOptions ( ) {
379
380
return infiniteQueryOptions ( {
380
- queryKey : [ opts . namespace , "runners" ] ,
381
+ queryKey : [ { namespace } , "runners" ] ,
381
382
initialPageParam : undefined as string | undefined ,
382
383
queryFn : async ( { pageParam, signal : abortSignal } ) => {
383
384
const data = await client . runners . list (
384
385
{
385
- namespace : opts . namespace ,
386
+ namespace,
386
387
cursor : pageParam ?? undefined ,
387
388
limit : RECORDS_PER_PAGE ,
388
389
} ,
@@ -399,7 +400,7 @@ export const createNamespaceContext = ({
399
400
select : ( data ) => data . pages . flatMap ( ( page ) => page . runners ) ,
400
401
retry : shouldRetryAllExpect403 ,
401
402
meta : {
402
- mightRequireAuth : true ,
403
+ mightRequireAuth,
403
404
} ,
404
405
} ) ;
405
406
} ,
@@ -430,7 +431,7 @@ export const createNamespaceContext = ({
430
431
retry : shouldRetryAllExpect403 ,
431
432
throwOnError : noThrow ,
432
433
meta : {
433
- mightRequireAuth : true ,
434
+ mightRequireAuth,
434
435
} ,
435
436
} ) ;
436
437
} ,
@@ -457,7 +458,7 @@ export const createNamespaceContext = ({
457
458
throwOnError : noThrow ,
458
459
retry : shouldRetryAllExpect403 ,
459
460
meta : {
460
- mightRequireAuth : true ,
461
+ mightRequireAuth,
461
462
} ,
462
463
} ) ;
463
464
} ,
@@ -482,7 +483,7 @@ export const createNamespaceContext = ({
482
483
} ,
483
484
retry : shouldRetryAllExpect403 ,
484
485
meta : {
485
- mightRequireAuth : true ,
486
+ mightRequireAuth,
486
487
} ,
487
488
} ) ;
488
489
} ,
@@ -507,6 +508,10 @@ export const createNamespaceContext = ({
507
508
} ) ;
508
509
return response ;
509
510
} ,
511
+ retry : shouldRetryAllExpect403 ,
512
+ meta : {
513
+ mightRequireAuth,
514
+ } ,
510
515
} ;
511
516
} ,
512
517
runnerConfigsQueryOptions ( ) {
@@ -539,6 +544,25 @@ export const createNamespaceContext = ({
539
544
}
540
545
return lastPage . pagination . cursor ;
541
546
} ,
547
+
548
+ retryDelay : 50_000 ,
549
+ retry : shouldRetryAllExpect403 ,
550
+ meta : {
551
+ mightRequireAuth,
552
+ } ,
553
+ } ) ;
554
+ } ,
555
+ connectRunnerTokenQueryOptions ( ) {
556
+ return queryOptions ( {
557
+ staleTime : 1000 ,
558
+ gcTime : 1000 ,
559
+ queryKey : [ { namespace } , "runners" , "connect" ] ,
560
+ queryFn : async ( ) => {
561
+ return ls . engineCredentials . get ( getConfig ( ) . apiUrl ) || "" ;
562
+ } ,
563
+ meta : {
564
+ mightRequireAuth,
565
+ } ,
542
566
} ) ;
543
567
} ,
544
568
} ;
0 commit comments