@serve.zone/dcrouter 15.0.2 → 15.0.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/deno.json +1 -1
- package/dist_serve/bundle.js +768 -768
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.dcrouter.js +9 -1
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/appstate/acme.d.ts +17 -0
- package/dist_ts_web/appstate/acme.js +64 -0
- package/dist_ts_web/appstate/certificates.d.ts +37 -0
- package/dist_ts_web/appstate/certificates.js +107 -0
- package/dist_ts_web/appstate/config.d.ts +9 -0
- package/dist_ts_web/appstate/config.js +35 -0
- package/dist_ts_web/appstate/domains.d.ts +80 -0
- package/dist_ts_web/appstate/domains.js +324 -0
- package/dist_ts_web/appstate/email-domains.d.ts +25 -0
- package/dist_ts_web/appstate/email-domains.js +104 -0
- package/dist_ts_web/appstate/email-ops.d.ts +10 -0
- package/dist_ts_web/appstate/email-ops.js +40 -0
- package/dist_ts_web/appstate/login.d.ts +30 -0
- package/dist_ts_web/appstate/login.js +83 -0
- package/dist_ts_web/appstate/logs.d.ts +16 -0
- package/dist_ts_web/appstate/logs.js +27 -0
- package/dist_ts_web/appstate/network.d.ts +50 -0
- package/dist_ts_web/appstate/network.js +122 -0
- package/dist_ts_web/appstate/profiles-targets.d.ts +45 -0
- package/dist_ts_web/appstate/profiles-targets.js +173 -0
- package/dist_ts_web/appstate/remoteingress.d.ts +47 -0
- package/dist_ts_web/appstate/remoteingress.js +204 -0
- package/dist_ts_web/appstate/routes.d.ts +76 -0
- package/dist_ts_web/appstate/routes.js +316 -0
- package/dist_ts_web/appstate/runtime.d.ts +1 -0
- package/dist_ts_web/appstate/runtime.js +276 -0
- package/dist_ts_web/appstate/security.d.ts +29 -0
- package/dist_ts_web/appstate/security.js +167 -0
- package/dist_ts_web/appstate/shared.d.ts +3 -0
- package/dist_ts_web/appstate/shared.js +13 -0
- package/dist_ts_web/appstate/stats.d.ts +15 -0
- package/dist_ts_web/appstate/stats.js +59 -0
- package/dist_ts_web/appstate/target-profiles.d.ts +37 -0
- package/dist_ts_web/appstate/target-profiles.js +118 -0
- package/dist_ts_web/appstate/ui.d.ts +11 -0
- package/dist_ts_web/appstate/ui.js +55 -0
- package/dist_ts_web/appstate/users.d.ts +27 -0
- package/dist_ts_web/appstate/users.js +85 -0
- package/dist_ts_web/appstate/vpn.d.ts +44 -0
- package/dist_ts_web/appstate/vpn.js +148 -0
- package/dist_ts_web/appstate.d.ts +20 -568
- package/dist_ts_web/appstate.js +24 -2418
- package/package.json +3 -3
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.dcrouter.ts +10 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/appstate/acme.ts +93 -0
- package/ts_web/appstate/certificates.ts +159 -0
- package/ts_web/appstate/config.ts +49 -0
- package/ts_web/appstate/domains.ts +429 -0
- package/ts_web/appstate/email-domains.ts +155 -0
- package/ts_web/appstate/email-ops.ts +57 -0
- package/ts_web/appstate/login.ts +128 -0
- package/ts_web/appstate/logs.ts +50 -0
- package/ts_web/appstate/network.ts +161 -0
- package/ts_web/appstate/profiles-targets.ts +240 -0
- package/ts_web/appstate/remoteingress.ts +300 -0
- package/ts_web/appstate/routes.ts +447 -0
- package/ts_web/appstate/runtime.ts +308 -0
- package/ts_web/appstate/security.ts +229 -0
- package/ts_web/appstate/shared.ts +15 -0
- package/ts_web/appstate/stats.ts +79 -0
- package/ts_web/appstate/target-profiles.ts +164 -0
- package/ts_web/appstate/ui.ts +75 -0
- package/ts_web/appstate/users.ts +133 -0
- package/ts_web/appstate/vpn.ts +234 -0
- package/ts_web/appstate.ts +24 -3403
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
import * as interfaces from '../../ts_interfaces/index.js';
|
|
3
|
+
import { appState } from './shared.js';
|
|
4
|
+
import { getActionContext } from './login.js';
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Route Management State
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
export interface IRouteManagementState {
|
|
11
|
+
mergedRoutes: interfaces.data.IMergedRoute[];
|
|
12
|
+
warnings: interfaces.data.IRouteWarning[];
|
|
13
|
+
httpRedirects: interfaces.data.IHttpRedirectInfo[];
|
|
14
|
+
apiTokens: interfaces.data.IApiTokenInfo[];
|
|
15
|
+
gatewayClients: interfaces.data.IGatewayClient[];
|
|
16
|
+
isLoading: boolean;
|
|
17
|
+
error: string | null;
|
|
18
|
+
lastUpdated: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const routeManagementStatePart = await appState.getStatePart<IRouteManagementState>(
|
|
22
|
+
'routeManagement',
|
|
23
|
+
{
|
|
24
|
+
mergedRoutes: [],
|
|
25
|
+
warnings: [],
|
|
26
|
+
httpRedirects: [],
|
|
27
|
+
apiTokens: [],
|
|
28
|
+
gatewayClients: [],
|
|
29
|
+
isLoading: false,
|
|
30
|
+
error: null,
|
|
31
|
+
lastUpdated: 0,
|
|
32
|
+
},
|
|
33
|
+
'soft'
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Route Management Actions
|
|
37
|
+
// ============================================================================
|
|
38
|
+
|
|
39
|
+
export const fetchMergedRoutesAction = routeManagementStatePart.createAction(async (statePartArg): Promise<IRouteManagementState> => {
|
|
40
|
+
const context = getActionContext();
|
|
41
|
+
const currentState = statePartArg.getState()!;
|
|
42
|
+
if (!context.identity) return currentState;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
46
|
+
interfaces.requests.IReq_GetMergedRoutes
|
|
47
|
+
>('/typedrequest', 'getMergedRoutes');
|
|
48
|
+
|
|
49
|
+
const response = await request.fire({
|
|
50
|
+
identity: context.identity,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
...currentState,
|
|
55
|
+
mergedRoutes: response.routes,
|
|
56
|
+
warnings: response.warnings,
|
|
57
|
+
isLoading: false,
|
|
58
|
+
error: null,
|
|
59
|
+
lastUpdated: Date.now(),
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
...currentState,
|
|
64
|
+
isLoading: false,
|
|
65
|
+
error: error instanceof Error ? error.message : 'Failed to fetch routes',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const fetchHttpRedirectsAction = routeManagementStatePart.createAction(async (statePartArg): Promise<IRouteManagementState> => {
|
|
71
|
+
const context = getActionContext();
|
|
72
|
+
const currentState = statePartArg.getState()!;
|
|
73
|
+
if (!context.identity) return currentState;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
77
|
+
interfaces.requests.IReq_GetHttpRedirects
|
|
78
|
+
>('/typedrequest', 'getHttpRedirects');
|
|
79
|
+
|
|
80
|
+
const response = await request.fire({
|
|
81
|
+
identity: context.identity,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...currentState,
|
|
86
|
+
httpRedirects: response.redirects,
|
|
87
|
+
isLoading: false,
|
|
88
|
+
error: null,
|
|
89
|
+
lastUpdated: Date.now(),
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return {
|
|
93
|
+
...currentState,
|
|
94
|
+
isLoading: false,
|
|
95
|
+
error: error instanceof Error ? error.message : 'Failed to fetch HTTP redirects',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export const createRouteAction = routeManagementStatePart.createAction<{
|
|
101
|
+
route: any;
|
|
102
|
+
enabled?: boolean;
|
|
103
|
+
metadata?: any;
|
|
104
|
+
}>(async (statePartArg, dataArg, actionContext): Promise<IRouteManagementState> => {
|
|
105
|
+
const context = getActionContext();
|
|
106
|
+
const currentState = statePartArg.getState()!;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
110
|
+
interfaces.requests.IReq_CreateRoute
|
|
111
|
+
>('/typedrequest', 'createRoute');
|
|
112
|
+
|
|
113
|
+
await request.fire({
|
|
114
|
+
identity: context.identity!,
|
|
115
|
+
route: dataArg.route,
|
|
116
|
+
enabled: dataArg.enabled,
|
|
117
|
+
metadata: dataArg.metadata,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return await actionContext!.dispatch(fetchMergedRoutesAction, null);
|
|
121
|
+
} catch (error: unknown) {
|
|
122
|
+
return {
|
|
123
|
+
...currentState,
|
|
124
|
+
error: error instanceof Error ? error.message : 'Failed to create route',
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export const updateRouteAction = routeManagementStatePart.createAction<{
|
|
130
|
+
id: string;
|
|
131
|
+
route?: any;
|
|
132
|
+
enabled?: boolean;
|
|
133
|
+
metadata?: any;
|
|
134
|
+
}>(async (statePartArg, dataArg, actionContext): Promise<IRouteManagementState> => {
|
|
135
|
+
const context = getActionContext();
|
|
136
|
+
const currentState = statePartArg.getState()!;
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
140
|
+
interfaces.requests.IReq_UpdateRoute
|
|
141
|
+
>('/typedrequest', 'updateRoute');
|
|
142
|
+
|
|
143
|
+
const response = await request.fire({
|
|
144
|
+
identity: context.identity!,
|
|
145
|
+
id: dataArg.id,
|
|
146
|
+
route: dataArg.route,
|
|
147
|
+
enabled: dataArg.enabled,
|
|
148
|
+
metadata: dataArg.metadata,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
if (!response.success) {
|
|
152
|
+
throw new Error(response.message || 'Failed to update route');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return await actionContext!.dispatch(fetchMergedRoutesAction, null);
|
|
156
|
+
} catch (error: unknown) {
|
|
157
|
+
return {
|
|
158
|
+
...currentState,
|
|
159
|
+
error: error instanceof Error ? error.message : 'Failed to update route',
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
export const deleteRouteAction = routeManagementStatePart.createAction<string>(
|
|
165
|
+
async (statePartArg, routeId, actionContext): Promise<IRouteManagementState> => {
|
|
166
|
+
const context = getActionContext();
|
|
167
|
+
const currentState = statePartArg.getState()!;
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
171
|
+
interfaces.requests.IReq_DeleteRoute
|
|
172
|
+
>('/typedrequest', 'deleteRoute');
|
|
173
|
+
|
|
174
|
+
const response = await request.fire({
|
|
175
|
+
identity: context.identity!,
|
|
176
|
+
id: routeId,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (!response.success) {
|
|
180
|
+
throw new Error(response.message || 'Failed to delete route');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return await actionContext!.dispatch(fetchMergedRoutesAction, null);
|
|
184
|
+
} catch (error: unknown) {
|
|
185
|
+
return {
|
|
186
|
+
...currentState,
|
|
187
|
+
error: error instanceof Error ? error.message : 'Failed to delete route',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
export const toggleRouteAction = routeManagementStatePart.createAction<{
|
|
194
|
+
id: string;
|
|
195
|
+
enabled: boolean;
|
|
196
|
+
}>(async (statePartArg, dataArg, actionContext): Promise<IRouteManagementState> => {
|
|
197
|
+
const context = getActionContext();
|
|
198
|
+
const currentState = statePartArg.getState()!;
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
202
|
+
interfaces.requests.IReq_ToggleRoute
|
|
203
|
+
>('/typedrequest', 'toggleRoute');
|
|
204
|
+
|
|
205
|
+
const response = await request.fire({
|
|
206
|
+
identity: context.identity!,
|
|
207
|
+
id: dataArg.id,
|
|
208
|
+
enabled: dataArg.enabled,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (!response.success) {
|
|
212
|
+
throw new Error(response.message || 'Failed to toggle route');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return await actionContext!.dispatch(fetchMergedRoutesAction, null);
|
|
216
|
+
} catch (error: unknown) {
|
|
217
|
+
return {
|
|
218
|
+
...currentState,
|
|
219
|
+
error: error instanceof Error ? error.message : 'Failed to toggle route',
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// ============================================================================
|
|
225
|
+
// API Token Actions
|
|
226
|
+
// ============================================================================
|
|
227
|
+
|
|
228
|
+
export const fetchApiTokensAction = routeManagementStatePart.createAction(async (statePartArg): Promise<IRouteManagementState> => {
|
|
229
|
+
const context = getActionContext();
|
|
230
|
+
const currentState = statePartArg.getState()!;
|
|
231
|
+
if (!context.identity) return currentState;
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
235
|
+
interfaces.requests.IReq_ListApiTokens
|
|
236
|
+
>('/typedrequest', 'listApiTokens');
|
|
237
|
+
|
|
238
|
+
const response = await request.fire({
|
|
239
|
+
identity: context.identity,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
...currentState,
|
|
244
|
+
apiTokens: response.tokens,
|
|
245
|
+
};
|
|
246
|
+
} catch (error) {
|
|
247
|
+
return {
|
|
248
|
+
...currentState,
|
|
249
|
+
error: error instanceof Error ? error.message : 'Failed to fetch tokens',
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
export const fetchGatewayClientsAction = routeManagementStatePart.createAction(async (statePartArg): Promise<IRouteManagementState> => {
|
|
255
|
+
const context = getActionContext();
|
|
256
|
+
const currentState = statePartArg.getState()!;
|
|
257
|
+
if (!context.identity) return currentState;
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
261
|
+
interfaces.requests.IReq_ListGatewayClients
|
|
262
|
+
>('/typedrequest', 'listGatewayClients');
|
|
263
|
+
const response = await request.fire({ identity: context.identity });
|
|
264
|
+
return {
|
|
265
|
+
...currentState,
|
|
266
|
+
gatewayClients: response.gatewayClients,
|
|
267
|
+
error: null,
|
|
268
|
+
lastUpdated: Date.now(),
|
|
269
|
+
};
|
|
270
|
+
} catch (error) {
|
|
271
|
+
return {
|
|
272
|
+
...currentState,
|
|
273
|
+
error: error instanceof Error ? error.message : 'Failed to fetch gateway clients',
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
export async function createGatewayClient(data: {
|
|
279
|
+
id?: string;
|
|
280
|
+
type: interfaces.data.IGatewayClient['type'];
|
|
281
|
+
name: string;
|
|
282
|
+
description?: string;
|
|
283
|
+
hostnamePatterns?: string[];
|
|
284
|
+
allowedRouteTargets?: interfaces.data.IGatewayClient['allowedRouteTargets'];
|
|
285
|
+
}) {
|
|
286
|
+
const context = getActionContext();
|
|
287
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
288
|
+
interfaces.requests.IReq_CreateGatewayClient
|
|
289
|
+
>('/typedrequest', 'createGatewayClient');
|
|
290
|
+
return request.fire({
|
|
291
|
+
identity: context.identity!,
|
|
292
|
+
capabilities: {
|
|
293
|
+
readDomains: true,
|
|
294
|
+
readDnsRecords: true,
|
|
295
|
+
syncRoutes: true,
|
|
296
|
+
syncDnsRecords: false,
|
|
297
|
+
requestCertificates: false,
|
|
298
|
+
},
|
|
299
|
+
...data,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export const updateGatewayClientAction = routeManagementStatePart.createAction<{
|
|
304
|
+
id: string;
|
|
305
|
+
name?: string;
|
|
306
|
+
description?: string;
|
|
307
|
+
hostnamePatterns?: string[];
|
|
308
|
+
allowedRouteTargets?: interfaces.data.IGatewayClient['allowedRouteTargets'];
|
|
309
|
+
enabled?: boolean;
|
|
310
|
+
}>(async (statePartArg, dataArg, actionContext): Promise<IRouteManagementState> => {
|
|
311
|
+
const context = getActionContext();
|
|
312
|
+
const currentState = statePartArg.getState()!;
|
|
313
|
+
try {
|
|
314
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
315
|
+
interfaces.requests.IReq_UpdateGatewayClient
|
|
316
|
+
>('/typedrequest', 'updateGatewayClient');
|
|
317
|
+
await request.fire({ identity: context.identity!, ...dataArg });
|
|
318
|
+
return await actionContext!.dispatch(fetchGatewayClientsAction, null);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
return {
|
|
321
|
+
...currentState,
|
|
322
|
+
error: error instanceof Error ? error.message : 'Failed to update gateway client',
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
export const deleteGatewayClientAction = routeManagementStatePart.createAction<string>(
|
|
328
|
+
async (statePartArg, gatewayClientId, actionContext): Promise<IRouteManagementState> => {
|
|
329
|
+
const context = getActionContext();
|
|
330
|
+
const currentState = statePartArg.getState()!;
|
|
331
|
+
try {
|
|
332
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
333
|
+
interfaces.requests.IReq_DeleteGatewayClient
|
|
334
|
+
>('/typedrequest', 'deleteGatewayClient');
|
|
335
|
+
await request.fire({ identity: context.identity!, id: gatewayClientId });
|
|
336
|
+
return await actionContext!.dispatch(fetchGatewayClientsAction, null);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
return {
|
|
339
|
+
...currentState,
|
|
340
|
+
error: error instanceof Error ? error.message : 'Failed to delete gateway client',
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
export async function createGatewayClientToken(
|
|
347
|
+
gatewayClientId: string,
|
|
348
|
+
name?: string,
|
|
349
|
+
expiresInDays?: number | null,
|
|
350
|
+
) {
|
|
351
|
+
const context = getActionContext();
|
|
352
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
353
|
+
interfaces.requests.IReq_CreateGatewayClientToken
|
|
354
|
+
>('/typedrequest', 'createGatewayClientToken');
|
|
355
|
+
return request.fire({
|
|
356
|
+
identity: context.identity!,
|
|
357
|
+
gatewayClientId,
|
|
358
|
+
name,
|
|
359
|
+
expiresInDays,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Users
|
|
364
|
+
|
|
365
|
+
export async function createApiToken(
|
|
366
|
+
name: string,
|
|
367
|
+
scopes: interfaces.data.TApiTokenScope[],
|
|
368
|
+
expiresInDays?: number | null,
|
|
369
|
+
policy?: any,
|
|
370
|
+
) {
|
|
371
|
+
const context = getActionContext();
|
|
372
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
373
|
+
interfaces.requests.IReq_CreateApiToken
|
|
374
|
+
>('/typedrequest', 'createApiToken');
|
|
375
|
+
|
|
376
|
+
return request.fire({
|
|
377
|
+
identity: context.identity!,
|
|
378
|
+
name,
|
|
379
|
+
scopes,
|
|
380
|
+
policy,
|
|
381
|
+
expiresInDays,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export async function rollApiToken(id: string) {
|
|
386
|
+
const context = getActionContext();
|
|
387
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
388
|
+
interfaces.requests.IReq_RollApiToken
|
|
389
|
+
>('/typedrequest', 'rollApiToken');
|
|
390
|
+
|
|
391
|
+
return request.fire({
|
|
392
|
+
identity: context.identity!,
|
|
393
|
+
id,
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export const revokeApiTokenAction = routeManagementStatePart.createAction<string>(
|
|
398
|
+
async (statePartArg, tokenId, actionContext): Promise<IRouteManagementState> => {
|
|
399
|
+
const context = getActionContext();
|
|
400
|
+
const currentState = statePartArg.getState()!;
|
|
401
|
+
|
|
402
|
+
try {
|
|
403
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
404
|
+
interfaces.requests.IReq_RevokeApiToken
|
|
405
|
+
>('/typedrequest', 'revokeApiToken');
|
|
406
|
+
|
|
407
|
+
await request.fire({
|
|
408
|
+
identity: context.identity!,
|
|
409
|
+
id: tokenId,
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
return await actionContext!.dispatch(fetchApiTokensAction, null);
|
|
413
|
+
} catch (error: unknown) {
|
|
414
|
+
return {
|
|
415
|
+
...currentState,
|
|
416
|
+
error: error instanceof Error ? error.message : 'Failed to revoke token',
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
export const toggleApiTokenAction = routeManagementStatePart.createAction<{
|
|
423
|
+
id: string;
|
|
424
|
+
enabled: boolean;
|
|
425
|
+
}>(async (statePartArg, dataArg, actionContext): Promise<IRouteManagementState> => {
|
|
426
|
+
const context = getActionContext();
|
|
427
|
+
const currentState = statePartArg.getState()!;
|
|
428
|
+
|
|
429
|
+
try {
|
|
430
|
+
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
|
431
|
+
interfaces.requests.IReq_ToggleApiToken
|
|
432
|
+
>('/typedrequest', 'toggleApiToken');
|
|
433
|
+
|
|
434
|
+
await request.fire({
|
|
435
|
+
identity: context.identity!,
|
|
436
|
+
id: dataArg.id,
|
|
437
|
+
enabled: dataArg.enabled,
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
return await actionContext!.dispatch(fetchApiTokensAction, null);
|
|
441
|
+
} catch (error: unknown) {
|
|
442
|
+
return {
|
|
443
|
+
...currentState,
|
|
444
|
+
error: error instanceof Error ? error.message : 'Failed to toggle token',
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
});
|