@package-broker/ui 2.0.0-rc.4 → 2.0.0-rc.5
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/.tsbuildinfo +1 -1
- package/dist/api-types.d.ts +848 -22
- package/dist/api-types.d.ts.map +1 -1
- package/dist/assets/{access.62e9484517a0.js → access.def9a17dc4a8.js} +1 -1
- package/dist/assets/app.ec678c27ec0a.css +2 -0
- package/dist/assets/{app.c064670cdc0d.js → app.fba0d059b40b.js} +2 -2
- package/dist/assets/{audit.b7c40b9dc998.js → audit.453367b59daf.js} +1 -1
- package/dist/assets/{chunk.56d473a1587d.js → chunk.2c3648a5bad1.js} +1 -1
- package/dist/assets/{chunk.a6d755a9789f.js → chunk.304a2b5d1663.js} +1 -1
- package/dist/assets/{chunk.741aec8d1ff9.js → chunk.3f077ff17cea.js} +1 -1
- package/dist/assets/{chunk.d18497920e4d.js → chunk.4721d4544d48.js} +1 -1
- package/dist/assets/{chunk.6ea6bdcaa465.js → chunk.4acf8fa7653f.js} +1 -1
- package/dist/assets/{chunk.28a4d8aab337.js → chunk.53134c7df4e5.js} +1 -1
- package/dist/assets/{chunk.965b76812604.js → chunk.56e058d97e0f.js} +1 -1
- package/dist/assets/{chunk.3fcd6998795a.js → chunk.75e1357175af.js} +1 -1
- package/dist/assets/chunk.837eb41f53ef.js +1 -0
- package/dist/assets/{chunk.f54ea1378c8c.js → chunk.ab1a14143dc6.js} +1 -1
- package/dist/assets/{chunk.d813fefb410d.js → chunk.dc41ee9219cf.js} +1 -1
- package/dist/assets/{chunk.8442124f6802.js → chunk.f0fd799728ef.js} +1 -1
- package/dist/assets/chunk.fac952720b72.js +4 -0
- package/dist/assets/{import.e7a1e5834631.js → import.4275bbce08ac.js} +1 -1
- package/dist/assets/index.html +7 -7
- package/dist/assets/manifest.json +30 -30
- package/dist/assets/{notifications.19225fe12044.js → notifications.bd7d4c3f9882.js} +1 -1
- package/dist/assets/{npm-login.e059678af13d.js → npm-login.d8b60e11fe87.js} +1 -1
- package/dist/assets/packages.bdd474bcfc11.js +2 -0
- package/dist/assets/{projects.927fe18c785c.js → projects.44006a838c67.js} +1 -1
- package/dist/assets/{setup.8e977608d413.js → setup.7bc86366227c.js} +1 -1
- package/dist/assets/setup.html +2 -2
- package/dist/assets/sources.d95aabfbec73.js +1 -0
- package/dist/assets/{tokens.6b86d8d97e07.js → tokens.4ee13a722abb.js} +1 -1
- package/dist/auth.d.ts +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +13 -2
- package/dist/auth.js.map +1 -1
- package/dist/pages/audit.d.ts.map +1 -1
- package/dist/pages/packages/discovery-labels.d.ts +8 -0
- package/dist/pages/packages/discovery-labels.d.ts.map +1 -0
- package/dist/pages/packages/discovery-labels.js +25 -0
- package/dist/pages/packages/discovery-labels.js.map +1 -0
- package/dist/pages/packages/discovery-picker-view.d.ts +8 -0
- package/dist/pages/packages/discovery-picker-view.d.ts.map +1 -0
- package/dist/pages/packages/discovery-picker-view.js +109 -0
- package/dist/pages/packages/discovery-picker-view.js.map +1 -0
- package/dist/pages/packages/discovery-picker.d.ts +67 -0
- package/dist/pages/packages/discovery-picker.d.ts.map +1 -0
- package/dist/pages/packages/discovery-picker.js +238 -0
- package/dist/pages/packages/discovery-picker.js.map +1 -0
- package/dist/pages/packages/source-actions.d.ts +3 -1
- package/dist/pages/packages/source-actions.d.ts.map +1 -1
- package/dist/pages/packages/source-actions.js +19 -9
- package/dist/pages/packages/source-actions.js.map +1 -1
- package/dist/pages/sources/discovery-rule-prefill.d.ts +13 -0
- package/dist/pages/sources/discovery-rule-prefill.d.ts.map +1 -0
- package/dist/pages/sources/discovery-rule-prefill.js +9 -0
- package/dist/pages/sources/discovery-rule-prefill.js.map +1 -0
- package/dist/pages/sources/discovery-rules-view.d.ts +9 -0
- package/dist/pages/sources/discovery-rules-view.d.ts.map +1 -0
- package/dist/pages/sources/discovery-rules-view.js +144 -0
- package/dist/pages/sources/discovery-rules-view.js.map +1 -0
- package/dist/pages/sources/discovery-rules.d.ts +57 -0
- package/dist/pages/sources/discovery-rules.d.ts.map +1 -0
- package/dist/pages/sources/discovery-rules.js +383 -0
- package/dist/pages/sources/discovery-rules.js.map +1 -0
- package/dist/pages/sources.d.ts.map +1 -1
- package/dist/pages/sources.js +4 -1
- package/dist/pages/sources.js.map +1 -1
- package/dist/pending.d.ts +6 -1
- package/dist/pending.d.ts.map +1 -1
- package/dist/pending.js +1 -1
- package/dist/pending.js.map +1 -1
- package/package.json +3 -3
- package/dist/assets/app.45b156168495.css +0 -2
- package/dist/assets/chunk.51497edc7697.js +0 -4
- package/dist/assets/chunk.fd375c54b526.js +0 -1
- package/dist/assets/packages.ab5ab25b1c75.js +0 -2
- package/dist/assets/sources.ae50f239f80f.js +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { Button } from '../../components/ui/button.js';
|
|
4
|
+
import { Input } from '../../components/ui/input.js';
|
|
5
|
+
import { Label } from '../../components/ui/label.js';
|
|
6
|
+
import { Select } from '../../components/ui/select.js';
|
|
7
|
+
import { RowActions } from '../../components/ui/row-actions.js';
|
|
8
|
+
import { Dialog, DialogContent, DialogTitle, DialogDescription, DialogFooter, } from '../../components/ui/dialog.js';
|
|
9
|
+
import { connectionLabel, discoveryReason, PATTERN_HELP } from '../packages/discovery-labels.js';
|
|
10
|
+
import { createDiscoveryRules, ruleState, runFailure, scheduleWords, } from './discovery-rules.js';
|
|
11
|
+
function Instant({ value }) {
|
|
12
|
+
if (!value)
|
|
13
|
+
return _jsx(_Fragment, { children: "Not yet" });
|
|
14
|
+
const date = new Date(value);
|
|
15
|
+
return Number.isNaN(date.valueOf()) ? (_jsx(_Fragment, { children: "Time unavailable" })) : (_jsxs("time", { dateTime: value, children: [date.toLocaleString(), " (", Intl.DateTimeFormat().resolvedOptions().timeZone, ")"] }));
|
|
16
|
+
}
|
|
17
|
+
function CompletedRun({ rule }) {
|
|
18
|
+
const completed = rule.completed;
|
|
19
|
+
return (_jsxs("div", { className: "space-y-2", children: [_jsx("h4", { className: "font-semibold", children: "Last completed run" }), !completed?.lastRunAt ? (_jsx("p", { children: "No completed run yet." })) : (_jsxs(_Fragment, { children: [_jsx("p", { children: _jsx(Instant, { value: completed.lastRunAt }) }), _jsxs("p", { children: [completed.created, " created \u00B7 ", completed.existing, " existing \u00B7 ", completed.skipped, ' ', "skipped \u00B7 ", completed.failed, " failed"] }), _jsxs("details", { children: [_jsx("summary", { className: "min-h-11 cursor-pointer", children: "Last-run details" }), completed.outcome === 'failed' ? (_jsx("p", { children: runFailure(completed.failureReason, completed.failed) })) : null, completed.skips.length ? (_jsxs(_Fragment, { children: [_jsx("h4", { className: "font-semibold", children: "Skipped repositories" }), _jsx("ul", { children: completed.skips.map((skip, index) => (_jsxs("li", { className: "break-words", children: [skip.repository, ": ", discoveryReason(skip.reason)] }, index))) }), _jsx("p", { children: "Up to 50 skipped repositories are retained." })] })) : (_jsx("p", { children: "No retained skip details." })), completed.failed > 0 ? (_jsx("p", { children: "Repository failure details are not retained for completed runs. Check the connection and run the rule again." })) : null] })] }))] }));
|
|
20
|
+
}
|
|
21
|
+
function RuleForm({ model }) {
|
|
22
|
+
const state = useSyncExternalStore(model.subscribe, model.snapshot, model.snapshot);
|
|
23
|
+
const draft = state.draft;
|
|
24
|
+
const original = state.items.find((r) => r.id === state.editing);
|
|
25
|
+
const restart = original &&
|
|
26
|
+
(original.ecosystem !== draft.ecosystem ||
|
|
27
|
+
original.pattern !== draft.pattern ||
|
|
28
|
+
original.includeForks !== draft.includeForks ||
|
|
29
|
+
('credentialId' in original &&
|
|
30
|
+
(original.credentialId !== draft.credentialId ||
|
|
31
|
+
original.installationId !== draft.installationId)));
|
|
32
|
+
const pattern = useRef(null);
|
|
33
|
+
const name = useRef(null);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
name.current?.focus();
|
|
36
|
+
}, []);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (state.patternError)
|
|
39
|
+
pattern.current?.focus();
|
|
40
|
+
}, [state.patternError]);
|
|
41
|
+
const currentBinding = original &&
|
|
42
|
+
'credentialId' in original &&
|
|
43
|
+
original.credentialId === draft.credentialId &&
|
|
44
|
+
original.installationId === draft.installationId;
|
|
45
|
+
const disabled = state.busy || state.reauthPending;
|
|
46
|
+
const selected = state.connections.findIndex((c) => c.credentialId === draft.credentialId && c.installationId === draft.installationId);
|
|
47
|
+
return (_jsxs("form", { className: "grid max-w-5xl items-start gap-x-6 gap-y-4 rounded border p-4 lg:grid-cols-2", "aria-label": state.editing ? 'Edit discovery rule' : 'New discovery rule', "aria-busy": disabled, onSubmit: (event) => {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
void model.save();
|
|
50
|
+
}, children: [_jsxs("p", { className: "lg:col-span-2", children: [state.editing ? 'Edit discovery rule' : 'New discovery rule', " \u00B7 Organization sources. Matching repositories become shared sources. Projects attach these sources to use their packages."] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "rule-name", children: "Name (required)" }), _jsx(Input, { id: "rule-name", ref: name, className: "min-h-11", required: true, maxLength: 80, value: draft.name, disabled: disabled, onChange: (e) => model.configure({ name: e.target.value }) })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "rule-connection", children: "GitHub connection (required)" }), _jsxs(Select, { id: "rule-connection", className: "min-h-11 max-w-full", disabled: disabled || !state.connections.length, value: selected < 0 ? '' : String(selected), onChange: (e) => {
|
|
51
|
+
const c = state.connections[Number(e.target.value)];
|
|
52
|
+
if (c)
|
|
53
|
+
model.configure({ credentialId: c.credentialId, installationId: c.installationId });
|
|
54
|
+
}, children: [_jsx("option", { value: "", disabled: true, children: currentBinding
|
|
55
|
+
? 'Current connection (no longer used by any source)'
|
|
56
|
+
: 'Choose a connection' }), state.connections.map((c, i) => (_jsx("option", { value: String(i), children: connectionLabel(c) }, i)))] }), selected < 0 && !currentBinding ? (_jsx("p", { children: "The saved connection is unavailable. Choose an available GitHub connection." })) : null] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "rule-ecosystem", children: "Package ecosystem" }), _jsxs(Select, { id: "rule-ecosystem", className: "min-h-11", disabled: disabled, value: draft.ecosystem, onChange: (e) => model.configure({ ecosystem: e.target.value }), children: [_jsx("option", { value: "npm", children: "npm" }), _jsx("option", { value: "composer", children: "Composer" }), _jsx("option", { value: "both", children: "Composer and npm" })] })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "rule-pattern", children: "Repository name pattern (optional)" }), _jsx(Input, { id: "rule-pattern", ref: pattern, className: "min-h-11", maxLength: 100, value: draft.pattern, disabled: disabled, "aria-invalid": !!state.patternError, "aria-describedby": `rule-pattern-help${state.patternError ? ' rule-pattern-error' : ''}`, onChange: (e) => model.configure({ pattern: e.target.value }) }), _jsx("p", { id: "rule-pattern-help", children: PATTERN_HELP }), state.patternError ? (_jsx("p", { id: "rule-pattern-error", role: "alert", children: state.patternError })) : null] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "rule-interval", children: "Scan interval in hours (required)" }), _jsx(Input, { id: "rule-interval", className: "min-h-11", type: "number", required: true, min: 1, max: 720, step: 1, value: (draft.intervalSeconds ?? 86400) / 3600, disabled: disabled, "aria-describedby": "rule-interval-help", onChange: (e) => model.configure({ intervalSeconds: Math.round(Number(e.target.value) * 3600) }) }), _jsx("p", { id: "rule-interval-help", children: "From one hour to 30 days. GitHub limits may delay a scan." })] }), _jsxs("fieldset", { children: [_jsx("legend", { children: "Scan settings" }), _jsxs("label", { className: "flex min-h-11 items-center gap-2", children: [_jsx("input", { type: "checkbox", checked: draft.includeForks ?? false, disabled: disabled, onChange: (e) => model.configure({ includeForks: e.target.checked }) }), "Include forks"] }), _jsxs("label", { className: "flex min-h-11 items-center gap-2", children: [_jsx("input", { type: "checkbox", checked: draft.enabled ?? true, disabled: disabled, onChange: (e) => model.configure({ enabled: e.target.checked }) }), "Enabled"] })] }), restart ? (_jsx("p", { className: "lg:col-span-2", children: "Changing the connection, ecosystem, pattern or forks restarts the scan. Imported sources stay." })) : null, state.stale ? (_jsxs("div", { className: "lg:col-span-2", children: [_jsx("p", { children: "Your draft is retained above. The newer rule is shown in the list below." }), _jsx(Button, { type: "button", className: "min-h-11", onClick: () => model.reviewLatest(), children: "Use latest settings and review" })] })) : null, _jsxs("div", { className: "flex flex-wrap gap-2 lg:col-span-2", children: [_jsx(Button, { type: "submit", className: "min-h-11 w-full sm:w-auto", disabled: disabled || state.loading || state.stale || (selected < 0 && !currentBinding), children: state.busy ? 'Saving rule…' : 'Save rule' }), _jsx(Button, { type: "button", variant: "outline", className: "min-h-11 w-full sm:w-auto", disabled: disabled, onClick: () => model.close(), children: "Cancel" })] })] }));
|
|
57
|
+
}
|
|
58
|
+
export function DiscoveryRules({ services }) {
|
|
59
|
+
const model = useMemo(() => createDiscoveryRules(services), [services]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
void model.load().then(() => {
|
|
62
|
+
if (new URLSearchParams(window.location.hash.split('?')[1]).get('discovery') === 'new' &&
|
|
63
|
+
!model.snapshot().draft)
|
|
64
|
+
model.edit();
|
|
65
|
+
});
|
|
66
|
+
const unsubscribe = services.subscribeReplay?.((result) => {
|
|
67
|
+
if (result.path.startsWith('/_pb/sources/discovery/rules')) {
|
|
68
|
+
void model.replayed(result);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
unsubscribe?.();
|
|
73
|
+
model.dispose();
|
|
74
|
+
};
|
|
75
|
+
}, [model, services]);
|
|
76
|
+
return _jsx(DiscoveryRulesView, { model: model });
|
|
77
|
+
}
|
|
78
|
+
export function DiscoveryRulesView({ model }) {
|
|
79
|
+
const state = useSyncExternalStore(model.subscribe, model.snapshot, model.snapshot);
|
|
80
|
+
const [deleting, setDeleting] = useState(null);
|
|
81
|
+
const heading = useRef(null);
|
|
82
|
+
const notice = useRef(null);
|
|
83
|
+
const focusHeadingAfterDelete = useRef(false);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (state.notice && !state.loading && !state.draft)
|
|
86
|
+
notice.current?.focus();
|
|
87
|
+
}, [state.notice, state.loading, state.draft]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (deleting || !focusHeadingAfterDelete.current)
|
|
90
|
+
return;
|
|
91
|
+
focusHeadingAfterDelete.current = false;
|
|
92
|
+
heading.current?.focus();
|
|
93
|
+
}, [deleting]);
|
|
94
|
+
if (!state.visible && !state.loading && !state.error)
|
|
95
|
+
return null;
|
|
96
|
+
return (_jsxs("section", { "aria-labelledby": "discovery-rules-heading", className: "mt-8 grid min-w-0 gap-4", children: [_jsx("h2", { ref: heading, tabIndex: -1, id: "discovery-rules-heading", className: "text-lg font-semibold", children: "Discovery rules" }), _jsx("p", { children: "Organization rules keep matching GitHub repositories available as shared sources. Existing sources are counted, never duplicated. Deleting a rule leaves imported sources in place." }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { className: "min-h-11", variant: "outline", disabled: state.loading || state.busy, onClick: () => void model.load(), children: "Reload rules" }), state.manager ? (_jsx(Button, { className: "min-h-11", disabled: state.loading || state.busy || !!state.draft, onClick: () => model.edit(), children: "Create discovery rule" })) : null] }), _jsx("p", { role: "status", "aria-live": "polite", ref: notice, tabIndex: -1, children: state.notice }), state.error && !deleting ? _jsx("p", { role: "alert", children: state.error }) : null, state.connectionsError ? (_jsx("p", { children: "GitHub connections could not be loaded. Reload rules to try again." })) : state.manager && !state.loading && !state.connections.length ? (_jsxs("p", { children: ["No GitHub App connections yet. Add an organization GitHub source with GitHub App authentication first.", ' ', _jsx("a", { className: "underline", href: "#/sources?create=vcs&provider=github", children: "Add a GitHub source" })] })) : null, state.draft && state.manager ? _jsx(RuleForm, { model: model }) : null, !state.loading && !state.items.length && !state.error ? (_jsx("p", { children: "No discovery rules yet." })) : null, _jsx("ul", { className: "grid min-w-0 gap-4", children: state.items.map((rule) => (_jsxs("li", { className: "min-w-0 space-y-2 rounded border p-4", children: [_jsx("h3", { className: "break-words font-semibold", children: rule.name }), _jsxs("dl", { className: "grid gap-2 sm:grid-cols-2", children: [_jsxs("div", { children: [_jsx("dt", { children: "Ecosystem" }), _jsx("dd", { children: rule.ecosystem === 'both'
|
|
97
|
+
? 'Composer and npm'
|
|
98
|
+
: rule.ecosystem === 'composer'
|
|
99
|
+
? 'Composer'
|
|
100
|
+
: 'npm' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Repository pattern" }), _jsx("dd", { className: "break-words", children: rule.pattern })] }), _jsxs("div", { children: [_jsx("dt", { children: "Forks" }), _jsx("dd", { children: rule.includeForks ? 'Included' : 'Excluded' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Schedule" }), _jsx("dd", { children: scheduleWords(rule.intervalSeconds) })] }), _jsxs("div", { children: [_jsx("dt", { children: "Enabled" }), _jsx("dd", { children: rule.enabled ? 'Enabled' : 'Disabled' })] }), _jsxs("div", { children: [_jsx("dt", { children: "State" }), _jsxs("dd", { children: [!rule.enabled ? 'Scheduled scans stopped' : ruleState(rule), 'outcome' in rule && rule.outcome === 'rate_limited' ? (_jsxs(_Fragment, { children: [' ', "until ", _jsx(Instant, { value: rule.nextRunAt })] })) : null] })] })] }), _jsx(CompletedRun, { rule: rule }), state.manager && 'created' in rule ? (_jsxs("p", { children: ["Current run: ", rule.created, " created \u00B7 ", rule.existing, " existing \u00B7 ", rule.skipped, ' ', "skipped \u00B7 ", rule.failed, " failed \u00B7 ", rule.remaining.length, " repositories remaining in the current page", rule.cursor ? '; more pages to scan' : '', "."] })) : null, state.manager ? (_jsx(RowActions, { entityLabel: rule.name, actions: [
|
|
101
|
+
{
|
|
102
|
+
id: 'run',
|
|
103
|
+
label: 'Run now',
|
|
104
|
+
disabled: state.busy ||
|
|
105
|
+
state.reauthPending ||
|
|
106
|
+
state.loading ||
|
|
107
|
+
state.stale ||
|
|
108
|
+
!rule.enabled,
|
|
109
|
+
onSelect: () => void model.run(rule),
|
|
110
|
+
},
|
|
111
|
+
], overflow: [
|
|
112
|
+
{
|
|
113
|
+
id: 'edit',
|
|
114
|
+
label: 'Edit',
|
|
115
|
+
disabled: state.busy || state.reauthPending || state.loading || !!state.draft,
|
|
116
|
+
onSelect: () => model.edit(rule),
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: 'toggle',
|
|
120
|
+
label: rule.enabled ? 'Disable' : 'Enable',
|
|
121
|
+
disabled: state.busy || state.reauthPending || state.loading || state.stale,
|
|
122
|
+
onSelect: () => void model.toggle(rule),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: 'delete',
|
|
126
|
+
label: 'Delete',
|
|
127
|
+
variant: 'destructive',
|
|
128
|
+
disabled: state.busy || state.reauthPending || state.loading || state.stale,
|
|
129
|
+
onSelect: () => setDeleting(rule),
|
|
130
|
+
},
|
|
131
|
+
] })) : null, state.manager && !rule.enabled ? (_jsx("p", { children: "Enable this rule before requesting a scan." })) : null] }, rule.id))) }), state.next ? (_jsx(Button, { className: "min-h-11", disabled: state.loading || state.busy, onClick: () => void model.load(true), children: "Load more rules" })) : null, _jsx(Dialog, { open: deleting !== null, onOpenChange: (open) => {
|
|
132
|
+
if (!open && !state.busy)
|
|
133
|
+
setDeleting(null);
|
|
134
|
+
}, children: _jsxs(DialogContent, { children: [_jsx(DialogTitle, { children: "Delete discovery rule" }), _jsxs(DialogDescription, { children: ["Remove the rule ", deleting?.name, " in this organization? Scheduled scans stop. Imported sources stay. This cannot be undone."] }), state.error && deleting ? _jsx("p", { role: "alert", children: state.error }) : null, _jsxs(DialogFooter, { children: [_jsx(Button, { className: "min-h-11", variant: "outline", disabled: state.busy, onClick: () => setDeleting(null), children: "Cancel" }), _jsx(Button, { className: "min-h-11", variant: "destructive", disabled: state.busy, onClick: () => {
|
|
135
|
+
if (deleting)
|
|
136
|
+
void model.remove(deleting).then((ok) => {
|
|
137
|
+
if (ok) {
|
|
138
|
+
focusHeadingAfterDelete.current = true;
|
|
139
|
+
setDeleting(null);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}, children: state.busy ? 'Deleting rule…' : _jsx(_Fragment, { children: "Delete rule" }) })] })] }) })] }));
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=discovery-rules-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery-rules-view.js","sourceRoot":"","sources":["../../../src/pages/sources/discovery-rules-view.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEnF,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EACL,MAAM,EACN,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,YAAY,GACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACjG,OAAO,EACL,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,aAAa,GAGd,MAAM,sBAAsB,CAAC;AAE9B,SAAS,OAAO,CAAC,EAAE,KAAK,EAAwC;IAC9D,IAAI,CAAC,KAAK;QAAE,OAAO,wCAAY,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CACpC,iDAAqB,CACtB,CAAC,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@@
|
|
|
1
|
+
import type { ReplayResult, ShellServices } from '../../auth.js';
|
|
2
|
+
import type { operations } from '../../api-types.js';
|
|
3
|
+
import { type DiscoveryConnection } from '../packages/discovery-labels.js';
|
|
4
|
+
type List = operations['listDiscoveryRules']['responses'][200]['content']['application/json'];
|
|
5
|
+
export type Rule = List['items'][number];
|
|
6
|
+
export type RuleOptions = operations['createDiscoveryRule']['requestBody']['content']['application/json'];
|
|
7
|
+
export declare function ruleFailure(result: {
|
|
8
|
+
status: number;
|
|
9
|
+
code?: string;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function runFailure(reason: string | null | undefined, failed?: number): string;
|
|
12
|
+
export declare function ruleState(rule: Rule): string;
|
|
13
|
+
export declare function scheduleWords(seconds: number): string;
|
|
14
|
+
export declare function createDiscoveryRules(services: ShellServices): {
|
|
15
|
+
snapshot: () => {
|
|
16
|
+
visible: boolean;
|
|
17
|
+
manager: boolean;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
busy: boolean;
|
|
20
|
+
reauthPending: boolean;
|
|
21
|
+
items: Rule[];
|
|
22
|
+
next: string | null;
|
|
23
|
+
connections: DiscoveryConnection[];
|
|
24
|
+
connectionsError: boolean;
|
|
25
|
+
draft: {
|
|
26
|
+
credentialId: string;
|
|
27
|
+
ecosystem?: "composer" | "npm" | "both";
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
includeForks?: boolean;
|
|
30
|
+
installationId: number;
|
|
31
|
+
intervalSeconds?: number;
|
|
32
|
+
name: string & (unknown & unknown);
|
|
33
|
+
pattern: string;
|
|
34
|
+
} | null;
|
|
35
|
+
editing: string | null;
|
|
36
|
+
revision: number | null;
|
|
37
|
+
stale: boolean;
|
|
38
|
+
error: string | null;
|
|
39
|
+
notice: string | null;
|
|
40
|
+
patternError: string | null;
|
|
41
|
+
};
|
|
42
|
+
subscribe(fn: () => void): () => void;
|
|
43
|
+
load: (more?: boolean, announce?: boolean) => Promise<void>;
|
|
44
|
+
dispose(): void;
|
|
45
|
+
edit: (rule?: Rule, prefill?: Partial<RuleOptions>) => void;
|
|
46
|
+
configure(patch: Partial<RuleOptions>): void;
|
|
47
|
+
close(): void;
|
|
48
|
+
reviewLatest(): void;
|
|
49
|
+
save(): Promise<void>;
|
|
50
|
+
run: (rule: Rule) => Promise<boolean | undefined>;
|
|
51
|
+
toggle: (rule: Rule) => Promise<boolean | undefined>;
|
|
52
|
+
remove: (selected: Rule) => Promise<boolean | undefined>;
|
|
53
|
+
replayed(result: ReplayResult): Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
export type DiscoveryRulesModel = ReturnType<typeof createDiscoveryRules>;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=discovery-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery-rules.d.ts","sourceRoot":"","sources":["../../../src/pages/sources/discovery-rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,KAAK,IAAI,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAC9F,MAAM,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AACzC,MAAM,MAAM,WAAW,GACrB,UAAU,CAAC,qBAAqB,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAElF,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAe7E;AACD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,SAAI,GAAG,MAAM,CAMhF;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAO5C;AACD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQrD;AACD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa;;;;;;;eAQ3C,IAAI,EAAE;cACL,MAAM,GAAG,IAAI;qBACR,mBAAmB,EAAE;;;;;;;;;;;;;;;eAMzB,MAAM,GAAG,IAAI;gBACZ,MAAM,GAAG,IAAI;sBACP,MAAM,GAAG,IAAI;;kBAmKrB,MAAM,IAAI;;;kBArCL,IAAI,YAAY,OAAO,CAAC,WAAW,CAAC;qBAgDtC,OAAO,CAAC,WAAW,CAAC;;;;gBA+FzB,IAAI;mBAcD,IAAI;uBAYM,IAAI;qBAkBN,YAAY;EAsCtC;AACD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { revisionTag } from '../management.js';
|
|
2
|
+
import { PATTERN_ERROR, validDiscoveryPattern, } from '../packages/discovery-labels.js';
|
|
3
|
+
import { drafts } from './discovery-rule-prefill.js';
|
|
4
|
+
export function ruleFailure(result) {
|
|
5
|
+
if (result.status === 412)
|
|
6
|
+
return 'This rule changed while you were editing. The newer rule is shown. Review the latest settings before saving.';
|
|
7
|
+
if (result.status === 404)
|
|
8
|
+
return 'This discovery rule is no longer available. Reload the rules.';
|
|
9
|
+
if (result.code === 'duplicate')
|
|
10
|
+
return 'A discovery rule with this name already exists. Choose another name.';
|
|
11
|
+
if (result.code === 'reauth_required')
|
|
12
|
+
return 'Sign in again, then confirm the discovery rule settings.';
|
|
13
|
+
if (result.status === 429)
|
|
14
|
+
return 'GitHub is rate limiting requests. Try again later.';
|
|
15
|
+
if (result.status === 409 && result.code === 'discovery_rule_disabled')
|
|
16
|
+
return 'Enable this rule before requesting a scan.';
|
|
17
|
+
if (result.status === 409)
|
|
18
|
+
return 'The rule conflicts with its current state. Reload and try again.';
|
|
19
|
+
if (result.status === 403)
|
|
20
|
+
return 'You do not have permission to change discovery rules.';
|
|
21
|
+
return 'Discovery rules could not be updated. Check the settings and try again.';
|
|
22
|
+
}
|
|
23
|
+
export function runFailure(reason, failed = 0) {
|
|
24
|
+
if (reason !== 'disabled' && reason !== 'discovery_failed')
|
|
25
|
+
return `Finished with ${failed} failed repositories`;
|
|
26
|
+
return reason === 'disabled'
|
|
27
|
+
? 'The rule was disabled before the scan finished.'
|
|
28
|
+
: 'The scan could not finish. Check the GitHub connection and try again.';
|
|
29
|
+
}
|
|
30
|
+
export function ruleState(rule) {
|
|
31
|
+
if (!rule.enabled)
|
|
32
|
+
return 'Disabled';
|
|
33
|
+
if (!('outcome' in rule))
|
|
34
|
+
return 'Current run information is available to source managers.';
|
|
35
|
+
if (rule.outcome === 'running')
|
|
36
|
+
return 'Running';
|
|
37
|
+
if (rule.outcome === 'rate_limited')
|
|
38
|
+
return 'Waiting for GitHub rate limit';
|
|
39
|
+
if (rule.outcome === 'failed')
|
|
40
|
+
return runFailure(rule.failureReason, rule.failed);
|
|
41
|
+
return 'Waiting for the next scheduled scan';
|
|
42
|
+
}
|
|
43
|
+
export function scheduleWords(seconds) {
|
|
44
|
+
if (seconds % 86400 === 0)
|
|
45
|
+
return seconds === 86400 ? 'Every day' : `Every ${seconds / 86400} days`;
|
|
46
|
+
if (seconds % 3600 === 0)
|
|
47
|
+
return seconds === 3600 ? 'Every hour' : `Every ${seconds / 3600} hours`;
|
|
48
|
+
const hours = Math.floor(seconds / 3600);
|
|
49
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
50
|
+
return `Every ${hours ? `${hours} ${hours === 1 ? 'hour' : 'hours'} and ` : ''}${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`;
|
|
51
|
+
}
|
|
52
|
+
export function createDiscoveryRules(services) {
|
|
53
|
+
const restored = drafts.get(services);
|
|
54
|
+
let state = {
|
|
55
|
+
visible: false,
|
|
56
|
+
manager: false,
|
|
57
|
+
loading: true,
|
|
58
|
+
busy: false,
|
|
59
|
+
reauthPending: restored?.reauthPending ?? false,
|
|
60
|
+
items: [],
|
|
61
|
+
next: null,
|
|
62
|
+
connections: [],
|
|
63
|
+
connectionsError: false,
|
|
64
|
+
draft: restored?.options ?? null,
|
|
65
|
+
editing: restored?.id ?? null,
|
|
66
|
+
revision: restored?.revision ?? null,
|
|
67
|
+
stale: false,
|
|
68
|
+
error: null,
|
|
69
|
+
notice: null,
|
|
70
|
+
patternError: null,
|
|
71
|
+
};
|
|
72
|
+
let generation = 0;
|
|
73
|
+
const listeners = new Set();
|
|
74
|
+
const set = (patch) => {
|
|
75
|
+
state = { ...state, ...patch };
|
|
76
|
+
listeners.forEach((fn) => fn());
|
|
77
|
+
};
|
|
78
|
+
const remember = () => {
|
|
79
|
+
if (state.draft)
|
|
80
|
+
drafts.set(services, {
|
|
81
|
+
options: state.draft,
|
|
82
|
+
id: state.editing,
|
|
83
|
+
revision: state.revision,
|
|
84
|
+
reauthPending: state.reauthPending,
|
|
85
|
+
});
|
|
86
|
+
else
|
|
87
|
+
drafts.delete(services);
|
|
88
|
+
};
|
|
89
|
+
async function load(more = false, announce = true) {
|
|
90
|
+
if (state.busy || (more && !state.next))
|
|
91
|
+
return;
|
|
92
|
+
const request = ++generation;
|
|
93
|
+
set({
|
|
94
|
+
loading: true,
|
|
95
|
+
error: null,
|
|
96
|
+
...(announce ? { notice: 'Loading discovery rules…' } : {}),
|
|
97
|
+
});
|
|
98
|
+
const permissions = await services.client.request('get', '/_pb/me/permissions');
|
|
99
|
+
if (request !== generation)
|
|
100
|
+
return;
|
|
101
|
+
const manager = permissions.ok && permissions.data.organization.includes('org:sources:write');
|
|
102
|
+
const visible = manager || (permissions.ok && permissions.data.organization.includes('org:sources:read'));
|
|
103
|
+
set({ manager, visible });
|
|
104
|
+
if (!visible) {
|
|
105
|
+
set({
|
|
106
|
+
loading: false,
|
|
107
|
+
items: [],
|
|
108
|
+
draft: null,
|
|
109
|
+
error: permissions.ok ? null : 'Discovery rule permissions could not be loaded. Try again.',
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const [rules, connections] = await Promise.all([
|
|
114
|
+
services.client.request('get', '/_pb/sources/discovery/rules', more ? { query: { after: state.next } } : {}),
|
|
115
|
+
manager ? services.client.request('get', '/_pb/sources/discovery/connections') : null,
|
|
116
|
+
]);
|
|
117
|
+
if (request !== generation)
|
|
118
|
+
return;
|
|
119
|
+
set({
|
|
120
|
+
loading: false,
|
|
121
|
+
...(announce ? { notice: null } : {}),
|
|
122
|
+
connections: connections?.ok ? connections.data.items : [],
|
|
123
|
+
connectionsError: manager && !connections?.ok,
|
|
124
|
+
...(rules.ok
|
|
125
|
+
? {
|
|
126
|
+
items: more
|
|
127
|
+
? [...new Map([...state.items, ...rules.data.items].map((r) => [r.id, r])).values()]
|
|
128
|
+
: rules.data.items,
|
|
129
|
+
next: rules.data.next,
|
|
130
|
+
}
|
|
131
|
+
: { error: 'Discovery rules could not be loaded. Try again.' }),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async function failed(result, rule, effect = 'The scan restarts.') {
|
|
135
|
+
set({ error: ruleFailure(result) });
|
|
136
|
+
if (result.code === 'reauth_required') {
|
|
137
|
+
set({ reauthPending: true });
|
|
138
|
+
remember();
|
|
139
|
+
services.requireReauth(result.request, {
|
|
140
|
+
credential: false,
|
|
141
|
+
secretFields: [],
|
|
142
|
+
display: {
|
|
143
|
+
label: `Change discovery rule ${rule?.name ?? state.draft?.name ?? 'New rule'}`,
|
|
144
|
+
effect,
|
|
145
|
+
scope: 'Organization sources',
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (result.status === 412 && rule) {
|
|
150
|
+
set({ stale: state.editing === rule.id && state.draft !== null });
|
|
151
|
+
const request = generation;
|
|
152
|
+
const latest = await services.client.request('get', '/_pb/sources/discovery/rules/{id}', {
|
|
153
|
+
params: { id: rule.id },
|
|
154
|
+
});
|
|
155
|
+
if (request !== generation)
|
|
156
|
+
return;
|
|
157
|
+
if (latest.ok)
|
|
158
|
+
set({
|
|
159
|
+
items: state.items.some((r) => r.id === rule.id)
|
|
160
|
+
? state.items.map((r) => (r.id === rule.id ? latest.data : r))
|
|
161
|
+
: [...state.items, latest.data],
|
|
162
|
+
});
|
|
163
|
+
else
|
|
164
|
+
set({ error: ruleFailure(latest) });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function mutate(action, notice, rule, effect = 'The scan restarts.') {
|
|
168
|
+
if (!state.manager || state.busy || state.reauthPending || state.loading || state.stale)
|
|
169
|
+
return;
|
|
170
|
+
set({ busy: true, error: null, notice: null });
|
|
171
|
+
const result = await action();
|
|
172
|
+
if (!result.ok)
|
|
173
|
+
await failed(result, rule, effect);
|
|
174
|
+
set({ busy: false });
|
|
175
|
+
if (result.ok) {
|
|
176
|
+
await load(false, false);
|
|
177
|
+
set({ notice });
|
|
178
|
+
}
|
|
179
|
+
if (!result.ok && result.status === 404) {
|
|
180
|
+
await load(false, false);
|
|
181
|
+
set({ error: ruleFailure(result) });
|
|
182
|
+
}
|
|
183
|
+
return result.ok;
|
|
184
|
+
}
|
|
185
|
+
const edit = (rule, prefill) => {
|
|
186
|
+
if (!state.manager || state.busy || state.reauthPending || state.loading || state.draft)
|
|
187
|
+
return;
|
|
188
|
+
const c = state.connections[0];
|
|
189
|
+
const options = rule
|
|
190
|
+
? {
|
|
191
|
+
name: rule.name,
|
|
192
|
+
pattern: rule.pattern,
|
|
193
|
+
ecosystem: rule.ecosystem,
|
|
194
|
+
includeForks: rule.includeForks,
|
|
195
|
+
enabled: rule.enabled,
|
|
196
|
+
intervalSeconds: rule.intervalSeconds,
|
|
197
|
+
credentialId: 'credentialId' in rule ? rule.credentialId : '',
|
|
198
|
+
installationId: 'installationId' in rule ? rule.installationId : 0,
|
|
199
|
+
}
|
|
200
|
+
: {
|
|
201
|
+
name: '',
|
|
202
|
+
credentialId: c?.credentialId ?? '',
|
|
203
|
+
installationId: c?.installationId ?? 0,
|
|
204
|
+
ecosystem: 'both',
|
|
205
|
+
pattern: '*',
|
|
206
|
+
includeForks: false,
|
|
207
|
+
intervalSeconds: 86400,
|
|
208
|
+
enabled: true,
|
|
209
|
+
...prefill,
|
|
210
|
+
};
|
|
211
|
+
set({
|
|
212
|
+
draft: options,
|
|
213
|
+
editing: rule?.id ?? null,
|
|
214
|
+
revision: rule?.revision ?? null,
|
|
215
|
+
stale: false,
|
|
216
|
+
error: null,
|
|
217
|
+
patternError: null,
|
|
218
|
+
});
|
|
219
|
+
remember();
|
|
220
|
+
};
|
|
221
|
+
return {
|
|
222
|
+
snapshot: () => state,
|
|
223
|
+
subscribe(fn) {
|
|
224
|
+
listeners.add(fn);
|
|
225
|
+
return () => {
|
|
226
|
+
listeners.delete(fn);
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
load,
|
|
230
|
+
dispose() {
|
|
231
|
+
generation++;
|
|
232
|
+
},
|
|
233
|
+
edit,
|
|
234
|
+
configure(patch) {
|
|
235
|
+
if (state.busy || state.reauthPending || !state.draft)
|
|
236
|
+
return;
|
|
237
|
+
set({ draft: { ...state.draft, ...patch }, patternError: null });
|
|
238
|
+
remember();
|
|
239
|
+
},
|
|
240
|
+
close() {
|
|
241
|
+
if (state.busy || state.reauthPending)
|
|
242
|
+
return;
|
|
243
|
+
set({ draft: null, editing: null, stale: false, error: null });
|
|
244
|
+
remember();
|
|
245
|
+
},
|
|
246
|
+
reviewLatest() {
|
|
247
|
+
const latest = state.items.find((r) => r.id === state.editing);
|
|
248
|
+
if (latest) {
|
|
249
|
+
set({ draft: null });
|
|
250
|
+
edit(latest);
|
|
251
|
+
}
|
|
252
|
+
else
|
|
253
|
+
set({ stale: false });
|
|
254
|
+
},
|
|
255
|
+
async save() {
|
|
256
|
+
if (!state.manager || !state.draft || state.stale || state.busy || state.reauthPending)
|
|
257
|
+
return;
|
|
258
|
+
const options = {
|
|
259
|
+
...state.draft,
|
|
260
|
+
name: state.draft.name.trim(),
|
|
261
|
+
pattern: state.draft.pattern || '*',
|
|
262
|
+
};
|
|
263
|
+
if (!validDiscoveryPattern(options.pattern)) {
|
|
264
|
+
set({ patternError: PATTERN_ERROR });
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const prior = state.items.find((r) => r.id === state.editing);
|
|
268
|
+
const unchanged = prior &&
|
|
269
|
+
'credentialId' in prior &&
|
|
270
|
+
prior.credentialId === options.credentialId &&
|
|
271
|
+
prior.installationId === options.installationId;
|
|
272
|
+
if (!Number.isInteger(options.intervalSeconds / 3600) ||
|
|
273
|
+
options.intervalSeconds < 3600 ||
|
|
274
|
+
options.intervalSeconds > 2592000) {
|
|
275
|
+
set({ error: 'Enter a whole number of hours from 1 to 720.' });
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!options.name ||
|
|
279
|
+
options.name.length > 80 ||
|
|
280
|
+
(!unchanged &&
|
|
281
|
+
!state.connections.some((c) => c.credentialId === options.credentialId &&
|
|
282
|
+
c.installationId === options.installationId))) {
|
|
283
|
+
set({
|
|
284
|
+
error: 'Enter a name of up to 80 characters and choose an available GitHub connection.',
|
|
285
|
+
});
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const body = { ...options };
|
|
289
|
+
if (prior &&
|
|
290
|
+
'credentialId' in prior &&
|
|
291
|
+
prior.credentialId === options.credentialId &&
|
|
292
|
+
prior.installationId === options.installationId) {
|
|
293
|
+
delete body.credentialId;
|
|
294
|
+
delete body.installationId;
|
|
295
|
+
}
|
|
296
|
+
const ok = await mutate(() => state.editing === null
|
|
297
|
+
? services.client.request('post', '/_pb/sources/discovery/rules', {
|
|
298
|
+
body: options,
|
|
299
|
+
idempotencyKey: crypto.randomUUID(),
|
|
300
|
+
})
|
|
301
|
+
: services.client.request('patch', '/_pb/sources/discovery/rules/{id}', {
|
|
302
|
+
params: { id: state.editing },
|
|
303
|
+
headers: { 'If-Match': revisionTag(state.revision) },
|
|
304
|
+
body,
|
|
305
|
+
}), 'Discovery rule saved.', prior ?? (state.editing ? { id: state.editing, name: options.name } : undefined), !prior ||
|
|
306
|
+
!unchanged ||
|
|
307
|
+
prior.ecosystem !== options.ecosystem ||
|
|
308
|
+
prior.pattern !== options.pattern ||
|
|
309
|
+
prior.includeForks !== options.includeForks
|
|
310
|
+
? 'The scan restarts. Imported sources stay.'
|
|
311
|
+
: 'Save the settings. The scan keeps its progress.');
|
|
312
|
+
if (ok) {
|
|
313
|
+
set({ draft: null, editing: null });
|
|
314
|
+
remember();
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
run: (rule) => !rule.enabled
|
|
318
|
+
? Promise.resolve(false)
|
|
319
|
+
: mutate(() => services.client.request('post', '/_pb/sources/discovery/rules/{id}/run', {
|
|
320
|
+
params: { id: rule.id },
|
|
321
|
+
body: {},
|
|
322
|
+
idempotencyKey: crypto.randomUUID(),
|
|
323
|
+
}), 'Scan requested. It will start on a scheduler tick when GitHub is available.', rule, 'Request a scan on the next scheduler tick.'),
|
|
324
|
+
toggle: (rule) => mutate(() => services.client.request('patch', '/_pb/sources/discovery/rules/{id}', {
|
|
325
|
+
params: { id: rule.id },
|
|
326
|
+
headers: { 'If-Match': revisionTag(rule.revision) },
|
|
327
|
+
body: { enabled: !rule.enabled },
|
|
328
|
+
}), 'Discovery rule updated.', rule, rule.enabled ? 'Scheduled scans stop.' : 'Scheduled scans resume.'),
|
|
329
|
+
remove: async (selected) => {
|
|
330
|
+
const rule = state.items.find((r) => r.id === selected.id);
|
|
331
|
+
if (!rule) {
|
|
332
|
+
await load(false, false);
|
|
333
|
+
set({ error: ruleFailure({ status: 404 }) });
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
return mutate(() => services.client.request('delete', '/_pb/sources/discovery/rules/{id}', {
|
|
337
|
+
params: { id: rule.id },
|
|
338
|
+
headers: { 'If-Match': revisionTag(rule.revision) },
|
|
339
|
+
}), 'Discovery rule deleted. Imported sources stay.', rule, 'Scheduled scans stop. Imported sources stay.');
|
|
340
|
+
},
|
|
341
|
+
async replayed(result) {
|
|
342
|
+
set({ reauthPending: false });
|
|
343
|
+
remember();
|
|
344
|
+
if (!result.ok && result.cancelled) {
|
|
345
|
+
set({
|
|
346
|
+
error: null,
|
|
347
|
+
notice: 'Discovery rule was not sent. Review the settings before trying again.',
|
|
348
|
+
});
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (result.ok) {
|
|
352
|
+
set({ draft: null, editing: null });
|
|
353
|
+
remember();
|
|
354
|
+
}
|
|
355
|
+
const loading = load(false, false);
|
|
356
|
+
const replayGeneration = generation;
|
|
357
|
+
await loading;
|
|
358
|
+
if (replayGeneration !== generation)
|
|
359
|
+
return;
|
|
360
|
+
if (result.ok)
|
|
361
|
+
set({ notice: 'Discovery rule saved.' });
|
|
362
|
+
if (!result.ok) {
|
|
363
|
+
set({ error: ruleFailure(result), stale: result.status === 412 && state.draft !== null });
|
|
364
|
+
if (result.status === 412 && state.editing) {
|
|
365
|
+
const request = generation;
|
|
366
|
+
const editing = state.editing;
|
|
367
|
+
const latest = await services.client.request('get', '/_pb/sources/discovery/rules/{id}', {
|
|
368
|
+
params: { id: state.editing },
|
|
369
|
+
});
|
|
370
|
+
if (request !== generation || editing !== state.editing)
|
|
371
|
+
return;
|
|
372
|
+
if (latest.ok)
|
|
373
|
+
set({
|
|
374
|
+
items: state.items.some((r) => r.id === state.editing)
|
|
375
|
+
? state.items.map((r) => (r.id === state.editing ? latest.data : r))
|
|
376
|
+
: [...state.items, latest.data],
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=discovery-rules.js.map
|