@sudobility/raidr_agent_lib 0.0.0-stage → 0.0.3
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/README.md +30 -2
- package/dist/business/agent/captureScript.d.ts +9 -0
- package/dist/business/agent/captureScript.d.ts.map +1 -0
- package/dist/business/agent/captureScript.js +77 -0
- package/dist/business/agent/captureScript.js.map +1 -0
- package/dist/business/agent/index.d.ts +3 -0
- package/dist/business/agent/index.d.ts.map +1 -0
- package/dist/business/agent/index.js +3 -0
- package/dist/business/agent/index.js.map +1 -0
- package/dist/business/agent/tokenWatcher.d.ts +16 -0
- package/dist/business/agent/tokenWatcher.d.ts.map +1 -0
- package/dist/business/agent/tokenWatcher.js +56 -0
- package/dist/business/agent/tokenWatcher.js.map +1 -0
- package/dist/business/hooks/index.d.ts +2 -0
- package/dist/business/hooks/index.d.ts.map +1 -0
- package/dist/business/hooks/index.js +2 -0
- package/dist/business/hooks/index.js.map +1 -0
- package/dist/business/hooks/useApiStatus.d.ts +13 -0
- package/dist/business/hooks/useApiStatus.d.ts.map +1 -0
- package/dist/business/hooks/useApiStatus.js +19 -0
- package/dist/business/hooks/useApiStatus.js.map +1 -0
- package/dist/business/index.d.ts +4 -0
- package/dist/business/index.d.ts.map +1 -0
- package/dist/business/index.js +4 -0
- package/dist/business/index.js.map +1 -0
- package/dist/business/stores/apiStatusStore.d.ts +9 -0
- package/dist/business/stores/apiStatusStore.d.ts.map +1 -0
- package/dist/business/stores/apiStatusStore.js +8 -0
- package/dist/business/stores/apiStatusStore.js.map +1 -0
- package/dist/business/stores/index.d.ts +3 -0
- package/dist/business/stores/index.d.ts.map +1 -0
- package/dist/business/stores/index.js +3 -0
- package/dist/business/stores/index.js.map +1 -0
- package/dist/business/stores/selectionStore.d.ts +10 -0
- package/dist/business/stores/selectionStore.d.ts.map +1 -0
- package/dist/business/stores/selectionStore.js +32 -0
- package/dist/business/stores/selectionStore.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -4
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# raidr_agent_lib
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Business logic shared by the apps: Zustand stores and hooks that compose raidr_agent_client hooks. No direct network calls.
|
|
4
|
+
|
|
5
|
+
Part of **raidr_agent**: a native agent app that turns a user request into an intent (shapeshyft), picks matching raidr MCP servers by label, signs the user in to those sites in a web view (tokens stay on device), calls them through raidr's hosted MCP, and shows the results with the Vercel AI SDK.
|
|
6
|
+
|
|
7
|
+
Layering: `raidr_agent_types` -> `raidr_agent_client` -> `raidr_agent_lib` -> `raidr_agent_api` / `raidr_agent_app_rn`.
|
|
8
|
+
|
|
9
|
+
## Development
|
|
10
|
+
|
|
11
|
+
Bun only.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bun install # see "Local dependency workaround"
|
|
15
|
+
bun run typecheck
|
|
16
|
+
bun run lint
|
|
17
|
+
bun run test:unit # vitest (jsdom)
|
|
18
|
+
bun run build # tsc -p tsconfig.build.json -> dist/
|
|
19
|
+
bun run verify
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Local dependency workaround
|
|
23
|
+
|
|
24
|
+
The `@sudobility/raidr_agent_*` packages are not published yet, so `bun install`
|
|
25
|
+
fails on them. Install everything else, then build the dependency locally and
|
|
26
|
+
copy its `dist/` and `package.json` into
|
|
27
|
+
`node_modules/@sudobility/<name>/`. Build order: types -> client -> lib -> api.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
BUSL-1.1
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ObservedRequest {
|
|
2
|
+
kind: 'raidr-agent/observed-request';
|
|
3
|
+
url: string;
|
|
4
|
+
method: string;
|
|
5
|
+
status: number;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildCaptureScript(apiHost: string): string;
|
|
9
|
+
//# sourceMappingURL=captureScript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureScript.d.ts","sourceRoot":"","sources":["../../../src/business/agent/captureScript.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,8BAA8B,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAMD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA2E1D"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export function buildCaptureScript(apiHost) {
|
|
2
|
+
return `(function () {
|
|
3
|
+
var HOST = ${JSON.stringify(apiHost)};
|
|
4
|
+
var KIND = 'raidr-agent/observed-request';
|
|
5
|
+
function post(payload) {
|
|
6
|
+
try {
|
|
7
|
+
var bridge = window.ReactNativeWebView;
|
|
8
|
+
if (bridge && bridge.postMessage) bridge.postMessage(JSON.stringify(payload));
|
|
9
|
+
} catch (e) {}
|
|
10
|
+
}
|
|
11
|
+
function hostOf(url) {
|
|
12
|
+
try { return new URL(url, window.location.href).host; } catch (e) { return ''; }
|
|
13
|
+
}
|
|
14
|
+
function headerObject(init) {
|
|
15
|
+
var out = {};
|
|
16
|
+
try {
|
|
17
|
+
var h = init && init.headers;
|
|
18
|
+
if (!h) return out;
|
|
19
|
+
if (typeof Headers !== 'undefined' && h instanceof Headers) {
|
|
20
|
+
h.forEach(function (v, k) { out[String(k).toLowerCase()] = v; });
|
|
21
|
+
} else if (Array.isArray(h)) {
|
|
22
|
+
h.forEach(function (pair) { if (pair && pair.length === 2) out[String(pair[0]).toLowerCase()] = pair[1]; });
|
|
23
|
+
} else {
|
|
24
|
+
Object.keys(h).forEach(function (k) { out[k.toLowerCase()] = h[k]; });
|
|
25
|
+
}
|
|
26
|
+
} catch (e) {}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
var origFetch = window.fetch;
|
|
30
|
+
if (origFetch) {
|
|
31
|
+
window.fetch = function (input, init) {
|
|
32
|
+
var url = typeof input === 'string' ? input : (input && input.url) || '';
|
|
33
|
+
var method = (init && init.method) || (input && input.method) || 'GET';
|
|
34
|
+
var headers = headerObject(init);
|
|
35
|
+
// Request objects carry their own headers.
|
|
36
|
+
try {
|
|
37
|
+
if (input && input.headers && typeof input.headers.forEach === 'function') {
|
|
38
|
+
input.headers.forEach(function (v, k) { if (!(k.toLowerCase() in headers)) headers[String(k).toLowerCase()] = v; });
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {}
|
|
41
|
+
var p = origFetch.apply(this, arguments);
|
|
42
|
+
if (hostOf(url) === HOST) {
|
|
43
|
+
p.then(function (res) {
|
|
44
|
+
post({ kind: KIND, url: url, method: String(method).toUpperCase(), status: (res && res.status) || 0, headers: headers });
|
|
45
|
+
}).catch(function () {
|
|
46
|
+
post({ kind: KIND, url: url, method: String(method).toUpperCase(), status: 0, headers: headers });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return p;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var open = XMLHttpRequest.prototype.open;
|
|
53
|
+
var setHeader = XMLHttpRequest.prototype.setRequestHeader;
|
|
54
|
+
var send = XMLHttpRequest.prototype.send;
|
|
55
|
+
XMLHttpRequest.prototype.open = function (method, url) {
|
|
56
|
+
this.__raidr = { method: String(method || 'GET').toUpperCase(), url: url || '', headers: {} };
|
|
57
|
+
return open.apply(this, arguments);
|
|
58
|
+
};
|
|
59
|
+
XMLHttpRequest.prototype.setRequestHeader = function (name, value) {
|
|
60
|
+
if (this.__raidr) this.__raidr.headers[String(name).toLowerCase()] = value;
|
|
61
|
+
return setHeader.apply(this, arguments);
|
|
62
|
+
};
|
|
63
|
+
XMLHttpRequest.prototype.send = function () {
|
|
64
|
+
var self = this;
|
|
65
|
+
var info = this.__raidr;
|
|
66
|
+
if (info && hostOf(info.url) === HOST) {
|
|
67
|
+
this.addEventListener('loadend', function () {
|
|
68
|
+
post({ kind: KIND, url: info.url, method: info.method, status: self.status || 0, headers: info.headers });
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return send.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
post({ kind: 'raidr-agent/capture-ready', host: HOST });
|
|
74
|
+
})();
|
|
75
|
+
true;`;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=captureScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureScript.js","sourceRoot":"","sources":["../../../src/business/agent/captureScript.ts"],"names":[],"mappings":"AA2BA,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO;eACM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwEhC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/business/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/business/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAwB,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CapturedCredential } from '@sudobility/raidr_types';
|
|
2
|
+
import type { SiteAuthInfo } from '@sudobility/raidr_agent_types';
|
|
3
|
+
import type { ObservedRequest } from './captureScript';
|
|
4
|
+
export declare class TokenWatcher {
|
|
5
|
+
private readonly apiHost;
|
|
6
|
+
private readonly userPaths;
|
|
7
|
+
private last;
|
|
8
|
+
private readonly auth;
|
|
9
|
+
constructor(apiHost: string, auth: SiteAuthInfo['auth'], userPaths: string[]);
|
|
10
|
+
private hostOf;
|
|
11
|
+
private pathOf;
|
|
12
|
+
observe(request: ObservedRequest): CapturedCredential | null;
|
|
13
|
+
observeCookieToken(token: string, sawSignedInCall: boolean): CapturedCredential | null;
|
|
14
|
+
onClosed(): CapturedCredential | null;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=tokenWatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenWatcher.d.ts","sourceRoot":"","sources":["../../../src/business/agent/tokenWatcher.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,qBAAa,YAAY;IAMrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAN5B,OAAO,CAAC,IAAI,CAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;gBAGnB,OAAO,EAAE,MAAM,EAChC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,EACT,SAAS,EAAE,MAAM,EAAE;IAUtC,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,MAAM;IAYd,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,GAAG,IAAI;IAkB5D,kBAAkB,CAChB,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,OAAO,GACvB,kBAAkB,GAAG,IAAI;IAW5B,QAAQ,IAAI,kBAAkB,GAAG,IAAI;CAKtC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { extractCredential, matchesPathTemplate, } from '@sudobility/raidr_types';
|
|
2
|
+
export class TokenWatcher {
|
|
3
|
+
constructor(apiHost, auth, userPaths) {
|
|
4
|
+
this.apiHost = apiHost;
|
|
5
|
+
this.userPaths = userPaths;
|
|
6
|
+
this.last = null;
|
|
7
|
+
this.auth = {
|
|
8
|
+
style: auth.style,
|
|
9
|
+
...(auth.headerName ? { headerName: auth.headerName } : {}),
|
|
10
|
+
...(auth.cookieName ? { cookieName: auth.cookieName } : {}),
|
|
11
|
+
...(auth.tokenPrefix ? { tokenPrefix: auth.tokenPrefix } : {}),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
hostOf(url) {
|
|
15
|
+
try {
|
|
16
|
+
return new URL(url).host;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
pathOf(url) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(url).pathname;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
observe(request) {
|
|
31
|
+
if (this.hostOf(request.url) !== this.apiHost)
|
|
32
|
+
return null;
|
|
33
|
+
const token = extractCredential(request.headers, this.auth);
|
|
34
|
+
if (!token)
|
|
35
|
+
return null;
|
|
36
|
+
this.last = token;
|
|
37
|
+
if (request.status < 200 || request.status >= 300)
|
|
38
|
+
return null;
|
|
39
|
+
const path = this.pathOf(request.url);
|
|
40
|
+
const signedInOnly = this.userPaths.length === 0 ||
|
|
41
|
+
this.userPaths.some(template => matchesPathTemplate(template, path));
|
|
42
|
+
return signedInOnly ? { token, verified: true } : null;
|
|
43
|
+
}
|
|
44
|
+
observeCookieToken(token, sawSignedInCall) {
|
|
45
|
+
if (!token)
|
|
46
|
+
return null;
|
|
47
|
+
this.last = token;
|
|
48
|
+
return sawSignedInCall ? { token, verified: true } : null;
|
|
49
|
+
}
|
|
50
|
+
onClosed() {
|
|
51
|
+
return this.userPaths.length === 0 && this.last
|
|
52
|
+
? { token: this.last, verified: false }
|
|
53
|
+
: null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=tokenWatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenWatcher.js","sourceRoot":"","sources":["../../../src/business/agent/tokenWatcher.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAIjC,MAAM,OAAO,YAAY;IAKvB,YACmB,OAAe,EAChC,IAA0B,EACT,SAAmB;QAFnB,YAAO,GAAP,OAAO,CAAQ;QAEf,cAAS,GAAT,SAAS,CAAU;QAN9B,SAAI,GAAkB,IAAI,CAAC;QAQjC,IAAI,CAAC,IAAI,GAAG;YACV,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,GAAW;QACxB,IAAI,CAAC;YACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAA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C,CAAC,IAAI,CAAC;IAC5D,CAAC;IAOD,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI;YAC7C,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;YACvC,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/business/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/business/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA2B,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HealthCheckData, Optional } from '@sudobility/raidr_agent_types';
|
|
2
|
+
import type { NetworkClient } from '@sudobility/types';
|
|
3
|
+
export interface UseApiStatusReturn {
|
|
4
|
+
health: HealthCheckData | null;
|
|
5
|
+
isHealthy: boolean;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
error: Optional<string>;
|
|
8
|
+
refresh: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const useApiStatus: (networkClient: NetworkClient, baseUrl: string, options?: {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
}) => UseApiStatusReturn;
|
|
13
|
+
//# sourceMappingURL=useApiStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApiStatus.d.ts","sourceRoot":"","sources":["../../../src/business/hooks/useApiStatus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAOD,eAAO,MAAM,YAAY,GACvB,eAAe,aAAa,EAC5B,SAAS,MAAM,EACf,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,KAC9B,kBAmBF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useHealth } from '@sudobility/raidr_agent_client';
|
|
3
|
+
import { useApiStatusStore } from '../stores/apiStatusStore';
|
|
4
|
+
export const useApiStatus = (networkClient, baseUrl, options) => {
|
|
5
|
+
const { health, isLoading, error, update } = useHealth(networkClient, baseUrl, options);
|
|
6
|
+
const setHealth = useApiStatusStore(s => s.setHealth);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (health)
|
|
9
|
+
setHealth(health);
|
|
10
|
+
}, [health, setHealth]);
|
|
11
|
+
return {
|
|
12
|
+
health,
|
|
13
|
+
isHealthy: health?.status === 'ok',
|
|
14
|
+
isLoading,
|
|
15
|
+
error,
|
|
16
|
+
refresh: update,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=useApiStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApiStatus.js","sourceRoot":"","sources":["../../../src/business/hooks/useApiStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAG3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAe7D,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,aAA4B,EAC5B,OAAe,EACf,OAA+B,EACX,EAAE;IACtB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CACpD,aAAa,EACb,OAAO,EACP,OAAO,CACR,CAAC;IACF,MAAM,SAAS,GAAG,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,MAAM;YAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAExB,OAAO;QACL,MAAM;QACN,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI;QAClC,SAAS;QACT,KAAK;QACL,OAAO,EAAE,MAAM;KAChB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/business/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/business/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HealthCheckData } from '@sudobility/raidr_agent_types';
|
|
2
|
+
export interface ApiStatusState {
|
|
3
|
+
lastHealth: HealthCheckData | null;
|
|
4
|
+
lastCheckedAt: number | null;
|
|
5
|
+
setHealth: (health: HealthCheckData | null) => void;
|
|
6
|
+
reset: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const useApiStatusStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ApiStatusState>>;
|
|
9
|
+
//# sourceMappingURL=apiStatusStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiStatusStore.d.ts","sourceRoot":"","sources":["../../../src/business/stores/apiStatusStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAQrE,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;IACnC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAC;IACpD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,eAAO,MAAM,iBAAiB,6EAK3B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
export const useApiStatusStore = create(set => ({
|
|
3
|
+
lastHealth: null,
|
|
4
|
+
lastCheckedAt: null,
|
|
5
|
+
setHealth: health => set({ lastHealth: health, lastCheckedAt: Date.now() }),
|
|
6
|
+
reset: () => set({ lastHealth: null, lastCheckedAt: null }),
|
|
7
|
+
}));
|
|
8
|
+
//# sourceMappingURL=apiStatusStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiStatusStore.js","sourceRoot":"","sources":["../../../src/business/stores/apiStatusStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAgBjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAiB,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9D,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAC3E,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;CAC5D,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/business/stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/business/stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAuB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAuB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface SelectionState {
|
|
2
|
+
selected: Set<string>;
|
|
3
|
+
authorized: Set<string>;
|
|
4
|
+
toggle: (apiHost: string) => void;
|
|
5
|
+
select: (apiHost: string, on: boolean) => void;
|
|
6
|
+
setAuthorized: (apiHost: string, on: boolean) => void;
|
|
7
|
+
reset: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const useSelectionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SelectionState>>;
|
|
10
|
+
//# sourceMappingURL=selectionStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectionStore.d.ts","sourceRoot":"","sources":["../../../src/business/stores/selectionStore.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,cAAc;IAE7B,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAEtB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,eAAO,MAAM,iBAAiB,6EA4B3B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
export const useSelectionStore = create(set => ({
|
|
3
|
+
selected: new Set(),
|
|
4
|
+
authorized: new Set(),
|
|
5
|
+
toggle: apiHost => set(state => {
|
|
6
|
+
const selected = new Set(state.selected);
|
|
7
|
+
if (selected.has(apiHost))
|
|
8
|
+
selected.delete(apiHost);
|
|
9
|
+
else
|
|
10
|
+
selected.add(apiHost);
|
|
11
|
+
return { selected };
|
|
12
|
+
}),
|
|
13
|
+
select: (apiHost, on) => set(state => {
|
|
14
|
+
const selected = new Set(state.selected);
|
|
15
|
+
if (on)
|
|
16
|
+
selected.add(apiHost);
|
|
17
|
+
else
|
|
18
|
+
selected.delete(apiHost);
|
|
19
|
+
return { selected };
|
|
20
|
+
}),
|
|
21
|
+
setAuthorized: (apiHost, on) => set(state => {
|
|
22
|
+
const authorized = new Set(state.authorized);
|
|
23
|
+
if (on)
|
|
24
|
+
authorized.add(apiHost);
|
|
25
|
+
else {
|
|
26
|
+
authorized.delete(apiHost);
|
|
27
|
+
}
|
|
28
|
+
return { authorized };
|
|
29
|
+
}),
|
|
30
|
+
reset: () => set({ selected: new Set(), authorized: new Set() }),
|
|
31
|
+
}));
|
|
32
|
+
//# sourceMappingURL=selectionStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectionStore.js","sourceRoot":"","sources":["../../../src/business/stores/selectionStore.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAcj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,CACV,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAU,EAAE,UAAU,EAAE,IAAI,GAAG,EAAU,EAAE,CAAC;CACtE,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/raidr_agent_lib",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Business logic library for RaidrAgent with Zustand stores",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "bunx tsc -p tsconfig.build.json",
|
|
16
|
+
"build:watch": "bunx tsc --watch",
|
|
17
|
+
"clean": "rm -rf dist",
|
|
18
|
+
"prepublishOnly": "bun run clean && bun run build",
|
|
19
|
+
"typecheck": "bunx tsc --noEmit",
|
|
20
|
+
"lint": "bunx eslint src/",
|
|
21
|
+
"lint:fix": "bunx eslint src/ --fix",
|
|
22
|
+
"format": "bunx prettier --write \"src/**/*.ts\"",
|
|
23
|
+
"format:check": "bunx prettier --check \"src/**/*.ts\"",
|
|
24
|
+
"test:unit": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"verify": "bun run typecheck && bun run lint && bun run test:unit && bun run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"raidr_agent",
|
|
30
|
+
"business-logic",
|
|
31
|
+
"zustand",
|
|
32
|
+
"react",
|
|
33
|
+
"typescript"
|
|
34
|
+
],
|
|
35
|
+
"author": "Sudobility",
|
|
36
|
+
"license": "BUSL-1.1",
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@sudobility/raidr_agent_client": "^0.0.3",
|
|
39
|
+
"@sudobility/raidr_agent_types": "^0.0.3",
|
|
40
|
+
"@sudobility/types": "^1.9.68",
|
|
41
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
42
|
+
"react": ">=18.0.0",
|
|
43
|
+
"zustand": ">=5.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@eslint/js": "^9.38.0",
|
|
47
|
+
"@sudobility/raidr_agent_client": "^0.0.3",
|
|
48
|
+
"@sudobility/raidr_agent_types": "^0.0.3",
|
|
49
|
+
"@sudobility/types": "^1.9.68",
|
|
50
|
+
"@tanstack/react-query": "^5.90.5",
|
|
51
|
+
"@testing-library/react": "^16.3.2",
|
|
52
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
53
|
+
"@types/react": "^19.2.2",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
55
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
56
|
+
"eslint": "^9.39.2",
|
|
57
|
+
"eslint-config-prettier": "^10.1.5",
|
|
58
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
59
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
60
|
+
"globals": "^16.4.0",
|
|
61
|
+
"jsdom": "^28.1.0",
|
|
62
|
+
"prettier": "^3.7.4",
|
|
63
|
+
"react": "^19.2.1",
|
|
64
|
+
"react-dom": "^19.2.4",
|
|
65
|
+
"typescript": "~5.9.3",
|
|
66
|
+
"vitest": "^4.0.15",
|
|
67
|
+
"zustand": "^5.0.8"
|
|
68
|
+
},
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "git+https://github.com/johnqh/raidr_agent_lib.git"
|
|
72
|
+
},
|
|
73
|
+
"homepage": "https://github.com/johnqh/raidr_agent_lib#readme",
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/johnqh/raidr_agent_lib/issues"
|
|
76
|
+
},
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"@sudobility/raidr_types": "^0.1.9"
|
|
79
|
+
}
|
|
80
|
+
}
|