@jeffusion/bungee-core 5.26.0 → 6.0.1
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/config-storage-worker.js +376 -223
- package/dist/main.js +799 -437
- package/dist/observability-worker.js +0 -10
- package/dist/plugins/anthropic-request-sanitizer/index.js.map +2 -2
- package/dist/plugins/anthropic-request-sanitizer/manifest.json +1 -1
- package/dist/plugins/anthropic-tool-name-transformer/index.js.map +2 -2
- package/dist/plugins/anthropic-tool-name-transformer/manifest.json +1 -1
- package/dist/plugins/chatgpt-oauth/control.js.map +1 -1
- package/dist/plugins/chatgpt-oauth/index.js.map +2 -2
- package/dist/plugins/chatgpt-oauth/manifest.json +1 -1
- package/dist/plugins/codex-router/control.js.map +1 -1
- package/dist/plugins/codex-router/index.js +2 -2
- package/dist/plugins/codex-router/index.js.map +3 -3
- package/dist/plugins/codex-router/manifest.json +1 -1
- package/dist/plugins/deepseek-reasoning-fix/index.js.map +2 -2
- package/dist/plugins/deepseek-reasoning-fix/manifest.json +1 -1
- package/dist/plugins/key-access/control.js.map +1 -1
- package/dist/plugins/key-access/index.js.map +2 -2
- package/dist/plugins/key-access/ingress.js.map +1 -1
- package/dist/plugins/key-access/manifest.json +1 -1
- package/dist/plugins/key-rate-limit/index.js.map +2 -2
- package/dist/plugins/key-rate-limit/manifest.json +1 -1
- package/dist/plugins/llm-protocol-adapter/control.js +2 -2
- package/dist/plugins/llm-protocol-adapter/control.js.map +4 -4
- package/dist/plugins/llm-protocol-adapter/index.js +2 -2
- package/dist/plugins/llm-protocol-adapter/index.js.map +3 -3
- package/dist/plugins/llm-protocol-adapter/manifest.json +1 -1
- package/dist/plugins/model-mapping/index.js.map +2 -2
- package/dist/plugins/model-mapping/manifest.json +1 -1
- package/dist/plugins/models-dev/index.js.map +2 -2
- package/dist/plugins/models-dev/manifest.json +1 -1
- package/dist/plugins/signature-repair/index.js.map +2 -2
- package/dist/plugins/signature-repair/manifest.json +1 -1
- package/dist/plugins/token-budget/control.js.map +1 -1
- package/dist/plugins/token-budget/index.js.map +2 -2
- package/dist/plugins/token-budget/manifest.json +1 -1
- package/dist/plugins/token-metering/index.js.map +2 -2
- package/dist/plugins/token-metering/manifest.json +1 -1
- package/dist/plugins/token-stats/control.js.map +1 -1
- package/dist/plugins/token-stats/index.js.map +2 -2
- package/dist/plugins/token-stats/manifest.json +1 -1
- package/dist/plugins/user-auth/control.js +3911 -0
- package/dist/plugins/{local-accounts → user-auth}/control.js.map +8 -5
- package/dist/plugins/{local-accounts → user-auth}/index.js +6 -6
- package/dist/plugins/{local-accounts → user-auth}/index.js.map +6 -6
- package/dist/plugins/user-auth/manifest.json +735 -0
- package/dist/plugins/user-auth/ui/ConnectionEditor.svelte +137 -0
- package/dist/plugins/user-auth/ui/Login.svelte +87 -0
- package/dist/plugins/user-auth/ui/LoginProviderIcon.svelte +19 -0
- package/dist/plugins/user-auth/ui/LoginSettings.svelte +141 -0
- package/dist/plugins/user-auth/ui/Profile.svelte +185 -0
- package/dist/plugins/{local-accounts → user-auth}/ui/RecoveryHelp.svelte +3 -3
- package/dist/plugins/user-auth/ui/SessionPolicy.svelte +104 -0
- package/dist/plugins/user-auth/ui/Settings.svelte +14 -0
- package/dist/plugins/user-auth/ui/SettingsSection.svelte +32 -0
- package/dist/plugins/user-auth/ui/Setup.svelte +38 -0
- package/dist/plugins/user-auth/ui/TurnstileChallenge.svelte +26 -0
- package/dist/plugins/user-auth/ui/TurnstileSettings.svelte +81 -0
- package/dist/plugins/user-auth/ui/Users.svelte +95 -0
- package/dist/plugins/user-auth/ui/assets/LICENSE.txt +30 -0
- package/dist/plugins/user-auth/ui/assets/github.svg +1 -0
- package/dist/plugins/user-auth/ui/assets/google.svg +1 -0
- package/dist/plugins/user-auth/ui/assets/microsoft.svg +1 -0
- package/dist/plugins/user-auth/ui/contracts.ts +16 -0
- package/dist/plugins/{local-accounts → user-auth}/ui/login-errors.ts +4 -1
- package/dist/plugins/user-auth/ui/turnstile.ts +21 -0
- package/package.json +2 -2
- package/dist/plugins/local-accounts/control.js +0 -715
- package/dist/plugins/local-accounts/manifest.json +0 -223
- package/dist/plugins/local-accounts/ui/Login.svelte +0 -47
- package/dist/plugins/local-accounts/ui/Settings.svelte +0 -117
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, tick } from 'svelte';
|
|
3
|
+
import { _, isLoading } from 'svelte-i18n';
|
|
4
|
+
import { requestPluginControl } from '$api/client';
|
|
5
|
+
import { IndustrialDialog, BSelect } from '$components/industrial';
|
|
6
|
+
import { NumberInput } from '$components/ui/number-input';
|
|
7
|
+
import { Button } from '$components/ui/button';
|
|
8
|
+
import * as Dialog from '$components/ui/dialog';
|
|
9
|
+
import SettingsSection from './SettingsSection.svelte';
|
|
10
|
+
let { pluginName }: { pluginName: string } = $props();
|
|
11
|
+
const t = (key: string) => $isLoading ? '' : $_(`plugins.user-auth.${key}`);
|
|
12
|
+
type SessionPolicy = {idleTimeoutMinutes: number; absoluteTimeoutMinutes: number};
|
|
13
|
+
type PolicyResult = {version: number; policy: SessionPolicy};
|
|
14
|
+
const factors: Record<string, number> = {minutes: 1, hours: 60, days: 1440};
|
|
15
|
+
const maxMinutes = 43200;
|
|
16
|
+
const id = $props.id();
|
|
17
|
+
let returnFocus = $state<HTMLElement | null>(null);
|
|
18
|
+
let open = $state(false);
|
|
19
|
+
let durations = $state<{key: keyof SessionPolicy; label: string; value: number | undefined; unit: string}[]>([
|
|
20
|
+
{key: 'idleTimeoutMinutes', label: 'session.idle', value: 30, unit: 'minutes'},
|
|
21
|
+
{key: 'absoluteTimeoutMinutes', label: 'session.absolute', value: 8, unit: 'hours'},
|
|
22
|
+
]);
|
|
23
|
+
let policyVersion = $state<number | null>(null), savedPolicy = $state<SessionPolicy | null>(null);
|
|
24
|
+
let policyLoading = $state(true), policyBusy = $state(false), policyError = $state(''), policyDetail = $state(''), policySaved = $state(false);
|
|
25
|
+
let units = $derived(['minutes', 'hours', 'days'].map(unit => ({value: unit, label: t('session.' + unit)})));
|
|
26
|
+
let draftPolicy = $derived(Object.fromEntries(durations.map(field => [field.key, field.value === undefined ? NaN : field.value * factors[field.unit]!])) as SessionPolicy);
|
|
27
|
+
let validPolicy = $derived(durations.every(field => Number.isSafeInteger(field.value) && field.value! >= 0)
|
|
28
|
+
&& Object.values(draftPolicy).every(value => Number.isSafeInteger(value) && value >= 0 && value <= maxMinutes) && draftPolicy.absoluteTimeoutMinutes > 0);
|
|
29
|
+
let policyDirty = $derived(savedPolicy !== null && (draftPolicy.idleTimeoutMinutes !== savedPolicy.idleTimeoutMinutes || draftPolicy.absoluteTimeoutMinutes !== savedPolicy.absoluteTimeoutMinutes));
|
|
30
|
+
function applyPolicy(result: PolicyResult) {
|
|
31
|
+
policyVersion = result.version; savedPolicy = result.policy;
|
|
32
|
+
for (const field of durations) {
|
|
33
|
+
const minutes = result.policy[field.key];
|
|
34
|
+
field.unit = minutes > 0 && minutes % 1440 === 0 ? 'days' : minutes > 0 && minutes % 60 === 0 ? 'hours' : 'minutes';
|
|
35
|
+
field.value = minutes / factors[field.unit]!;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function policyFailure(e: unknown) {
|
|
39
|
+
const detail = e instanceof Error ? e.message : String(e); const result = {detail}; policyDetail = detail;
|
|
40
|
+
policyError = result.detail === 'version_conflict' ? 'session.conflict' : result.detail === 'invalid_session_policy' ? 'session.invalid' : 'session.failed';
|
|
41
|
+
}
|
|
42
|
+
async function loadPolicy() {
|
|
43
|
+
if (policyBusy) return;
|
|
44
|
+
policyLoading = true; policyError = ''; policyDetail = ''; policySaved = false;
|
|
45
|
+
try { applyPolicy(await requestPluginControl<PolicyResult>(pluginName, '/session-policy', 'GET')); }
|
|
46
|
+
catch (e) { policyFailure(e); }
|
|
47
|
+
finally { policyLoading = false; await tick(); if (open) document.getElementById('session-idleTimeoutMinutes')?.focus(); }
|
|
48
|
+
}
|
|
49
|
+
async function savePolicy(event: SubmitEvent) {
|
|
50
|
+
event.preventDefault(); if (policyBusy || policyLoading || policyVersion === null) return;
|
|
51
|
+
if (!validPolicy) { policyError = 'session.invalid'; return; }
|
|
52
|
+
policyBusy = true; policyError = ''; policyDetail = ''; policySaved = false;
|
|
53
|
+
try {
|
|
54
|
+
applyPolicy(await requestPluginControl<PolicyResult>(pluginName, '/session-policy', 'PUT', {version: policyVersion, policy: draftPolicy}));
|
|
55
|
+
policySaved = true; open = false; await tick(); returnFocus?.focus();
|
|
56
|
+
} catch (e) { policyFailure(e); }
|
|
57
|
+
finally { policyBusy = false; await tick(); if (open) document.getElementById('session-idleTimeoutMinutes')?.focus(); }
|
|
58
|
+
}
|
|
59
|
+
function edit() {
|
|
60
|
+
returnFocus = document.getElementById(id + '-edit');
|
|
61
|
+
if (!savedPolicy || policyVersion === null) return;
|
|
62
|
+
applyPolicy({version: policyVersion, policy: savedPolicy});
|
|
63
|
+
policyError = ''; policyDetail = ''; policySaved = false; open = true;
|
|
64
|
+
}
|
|
65
|
+
function close() {
|
|
66
|
+
open = false; policyError = ''; policyDetail = '';
|
|
67
|
+
if (savedPolicy && policyVersion !== null) applyPolicy({version: policyVersion, policy: savedPolicy});
|
|
68
|
+
}
|
|
69
|
+
function formatDuration(minutes: number) {
|
|
70
|
+
if (!minutes) return t('session.noIdleTimeout');
|
|
71
|
+
const unit = minutes % 1440 === 0 ? 'days' : minutes % 60 === 0 ? 'hours' : 'minutes';
|
|
72
|
+
return `${minutes / factors[unit]!} ${t('session.' + unit)}`;
|
|
73
|
+
}
|
|
74
|
+
onMount(() => { void loadPolicy(); });
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
{#snippet actions()}<Button id={id + '-edit'} variant="ghost" disabled={policyLoading || !savedPolicy} onclick={edit}>{t('admin.edit')}</Button>{/snippet}
|
|
78
|
+
<SettingsSection title={t('session.title')} {actions}>
|
|
79
|
+
{#if policyLoading}<p class="text-sm text-zinc-400">{t('session.loading')}</p>
|
|
80
|
+
{:else if savedPolicy}<p class="text-sm text-zinc-400" data-testid="session-policy-summary">{t('session.idle')} {formatDuration(savedPolicy.idleTimeoutMinutes)} · {t('session.absolute')} {formatDuration(savedPolicy.absoluteTimeoutMinutes)}</p>{/if}
|
|
81
|
+
{#if policySaved && !open}<p role="status" class="mt-2 text-sm text-emerald-400">{t('session.saved')}</p>{/if}
|
|
82
|
+
{#if policyError && !open}<p role="alert" class="text-sm text-red-400">{t(policyError)}</p><Button variant="ghost" onclick={loadPolicy} disabled={policyLoading}>{t('session.reload')}</Button>{/if}
|
|
83
|
+
</SettingsSection>
|
|
84
|
+
|
|
85
|
+
{#snippet body()}
|
|
86
|
+
<form id={id + '-policy'} class="space-y-4" onsubmit={savePolicy} aria-busy={policyBusy} data-testid="session-policy-form">
|
|
87
|
+
{#each durations as field (field.key)}
|
|
88
|
+
<div class="grid gap-1 min-w-0">
|
|
89
|
+
<label class="nx-field-label" for={'session-' + field.key}>{t(field.label)}</label>
|
|
90
|
+
<div class="flex items-center gap-2">
|
|
91
|
+
<NumberInput id={'session-' + field.key} min={field.key === 'absoluteTimeoutMinutes' ? 1 : 0} max={Math.floor(maxMinutes / factors[field.unit]!)} increaseLabel={t('session.increase')} decreaseLabel={t('session.decrease')} invalidMessage={t('session.invalid')} required bind:value={field.value} disabled={policyBusy || policyLoading || policyVersion === null} class="min-w-0 flex-1" />
|
|
92
|
+
<BSelect bind:value={field.unit} options={units} ariaLabel={t(field.label) + ' · ' + t('session.unit')} width="w-28 shrink-0" disabled={policyBusy || policyLoading || policyVersion === null} />
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
{/each}
|
|
96
|
+
{#if policyError}<p role="alert" class="text-sm text-red-400">{t(policyError)}</p><details class="text-sm text-zinc-400"><summary>{t('login.technicalDetails')}</summary><pre class="whitespace-pre-wrap break-all">{policyDetail}</pre></details>{/if}
|
|
97
|
+
</form>
|
|
98
|
+
{/snippet}
|
|
99
|
+
{#snippet footer()}
|
|
100
|
+
{#if policyError}<Button variant="ghost" onclick={loadPolicy} disabled={policyBusy || policyLoading}>{t('session.reload')}</Button>{/if}
|
|
101
|
+
<Dialog.Close asChild let:builder><Button builders={[builder]} variant="ghost" disabled={policyBusy || policyLoading}>{t('admin.cancel')}</Button></Dialog.Close>
|
|
102
|
+
<Button type="submit" form={id + '-policy'} disabled={policyBusy || policyLoading || policyVersion === null || !policyDirty || !validPolicy}>{policyBusy ? t('session.saving') : t('session.save')}</Button>
|
|
103
|
+
{/snippet}
|
|
104
|
+
<IndustrialDialog bind:open {returnFocus} title={t('session.title')} description={t('session.description')} busy={policyBusy || policyLoading} closeLabel={t('admin.close')} {body} {footer} onOpenChange={value => {if (!value) close();}} />
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { _, isLoading } from 'svelte-i18n';
|
|
3
|
+
import LoginSettings from './LoginSettings.svelte';
|
|
4
|
+
import SessionPolicy from './SessionPolicy.svelte';
|
|
5
|
+
let { pluginName = 'user-auth' }: { pluginName?: string; apiBase?: string } = $props();
|
|
6
|
+
const t = (key: string) => $isLoading ? '' : $_(`plugins.user-auth.${key}`);
|
|
7
|
+
</script>
|
|
8
|
+
<div class="border-b border-carbon-600" data-testid="auth-login-management">
|
|
9
|
+
<div class="space-y-2">
|
|
10
|
+
<h1 class="nx-display text-xl text-zinc-50">{t('settings.title')}</h1>
|
|
11
|
+
</div>
|
|
12
|
+
<LoginSettings {pluginName} />
|
|
13
|
+
<SessionPolicy {pluginName} />
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
let {title, description, status, actions, children}: {
|
|
4
|
+
title: string; description?: string; status?: Snippet; actions?: Snippet; children?: Snippet;
|
|
5
|
+
} = $props();
|
|
6
|
+
const id = $props.id();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<section class="border-t border-carbon-600 py-5" aria-labelledby={id}>
|
|
10
|
+
<header class="nx-panel-head settings-section-header">
|
|
11
|
+
<div class="min-w-0 flex-1 space-y-2">
|
|
12
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
13
|
+
<span class="nx-stripe shrink-0" aria-hidden="true"></span>
|
|
14
|
+
<h2 {id} class="text-lg font-semibold text-zinc-100">{title}</h2>
|
|
15
|
+
{#if status}{@render status()}{/if}
|
|
16
|
+
</div>
|
|
17
|
+
{#if description}<p class="max-w-3xl text-sm text-zinc-400">{description}</p>{/if}
|
|
18
|
+
</div>
|
|
19
|
+
{#if actions}<div class="shrink-0">{@render actions()}</div>{/if}
|
|
20
|
+
</header>
|
|
21
|
+
{#if children}<div class="mt-4">{@render children()}</div>{/if}
|
|
22
|
+
</section>
|
|
23
|
+
|
|
24
|
+
<style>
|
|
25
|
+
.settings-section-header {
|
|
26
|
+
padding: 0;
|
|
27
|
+
border: 0;
|
|
28
|
+
background: transparent;
|
|
29
|
+
gap: 1rem;
|
|
30
|
+
flex-wrap: wrap;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy } from 'svelte';
|
|
3
|
+
import { isLoading } from 'svelte-i18n';
|
|
4
|
+
import { _ } from '@bungee/plugin-sdk';
|
|
5
|
+
import type { ManagementSetupContext } from '@bungee/plugin-sdk';
|
|
6
|
+
let { context }: { context: ManagementSetupContext } = $props();
|
|
7
|
+
const t = (key: string) => $isLoading ? '' : $_(`plugins.user-auth.${key}`);
|
|
8
|
+
let setupCode = $state(''), username = $state(''), password = $state(''), passwordConfirmation = $state('');
|
|
9
|
+
let busy = $state(false), error = $state(''), detail = $state('');
|
|
10
|
+
let destroyed = false;
|
|
11
|
+
onDestroy(() => { destroyed = true; });
|
|
12
|
+
async function initialize(event: SubmitEvent) {
|
|
13
|
+
event.preventDefault(); if (busy) return;
|
|
14
|
+
const active = context; error = ''; detail = '';
|
|
15
|
+
if (password !== passwordConfirmation) { error = 'setup.password_confirmation'; return; }
|
|
16
|
+
if ([...password].length < 5 || [...password].length > 32) { error = 'setup.invalid_password'; return; }
|
|
17
|
+
busy = true;
|
|
18
|
+
try { await active.initialize({setupCode, username, password, passwordConfirmation}); }
|
|
19
|
+
catch (cause) {
|
|
20
|
+
if (destroyed || context !== active) return;
|
|
21
|
+
detail = cause instanceof Error ? cause.message : String(cause);
|
|
22
|
+
error = ['invalid_setup_code', 'password_confirmation', 'invalid_password', 'already_initialized'].includes(detail) ? `setup.${detail}` : 'setup.failed';
|
|
23
|
+
} finally {
|
|
24
|
+
password = ''; passwordConfirmation = ''; setupCode = '';
|
|
25
|
+
if (!destroyed && context === active) busy = false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<form onsubmit={initialize} aria-label={t('setup.title')} aria-busy={busy} class="space-y-4">
|
|
31
|
+
<p class="text-sm text-zinc-400">{t('setup.description')}</p>
|
|
32
|
+
<label class="grid gap-1"><span class="nx-field-label">{t('setup.code')}</span><input class="nx-input font-mono" bind:value={setupCode} autocomplete="off" required disabled={busy} /></label>
|
|
33
|
+
<label class="grid gap-1"><span class="nx-field-label">{t('login.username')}</span><input class="nx-input" bind:value={username} autocomplete="username" required maxlength="64" disabled={busy} /></label>
|
|
34
|
+
<label class="grid gap-1"><span class="nx-field-label">{t('setup.password')}</span><input class="nx-input" type="password" bind:value={password} autocomplete="new-password" required disabled={busy} /></label>
|
|
35
|
+
<label class="grid gap-1"><span class="nx-field-label">{t('setup.confirmation')}</span><input class="nx-input" type="password" bind:value={passwordConfirmation} autocomplete="new-password" required disabled={busy} /></label>
|
|
36
|
+
{#if error}<p role="alert" class="text-sm text-red-400">{t(error)}</p>{#if detail}<details class="text-sm text-zinc-400"><summary>{t('login.technicalDetails')}</summary><pre class="whitespace-pre-wrap break-all">{detail}</pre></details>{/if}{/if}
|
|
37
|
+
<button class="nx-btn-primary w-full justify-center" disabled={busy}>{busy ? t('setup.busy') : t('setup.submit')}</button>
|
|
38
|
+
</form>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import { loadTurnstile, type TurnstileApi } from './turnstile';
|
|
4
|
+
import { Button } from '$components/ui/button';
|
|
5
|
+
let { siteKey, resetKey = 0, onToken, retryLabel, failureLabel }: { siteKey: string; resetKey?: number; onToken(token: string): void; retryLabel: string; failureLabel: string } = $props();
|
|
6
|
+
let container: HTMLDivElement, api: TurnstileApi | undefined, widget: string | undefined;
|
|
7
|
+
let failed = $state(false), mounted = false, active = true;
|
|
8
|
+
async function render() {
|
|
9
|
+
failed = false; onToken('');
|
|
10
|
+
try {
|
|
11
|
+
const loaded = await loadTurnstile();
|
|
12
|
+
if (!active) return;
|
|
13
|
+
api = loaded;
|
|
14
|
+
widget = loaded.render(container, { sitekey: siteKey, action: 'local-login', size: 'flexible',
|
|
15
|
+
callback: token => { if (active) onToken(token); },
|
|
16
|
+
'expired-callback': () => { if (active) { onToken(''); if (widget !== undefined) loaded.reset(widget); } },
|
|
17
|
+
'error-callback': () => { if (active) { onToken(''); failed = true; if (widget !== undefined) loaded.reset(widget); } },
|
|
18
|
+
});
|
|
19
|
+
} catch { if (active) failed = true; }
|
|
20
|
+
}
|
|
21
|
+
function retry() { if (widget !== undefined) { api?.remove(widget); widget = undefined; } void render(); }
|
|
22
|
+
$effect(() => { void resetKey; if (mounted && widget !== undefined) { onToken(''); api?.reset(widget); } });
|
|
23
|
+
onMount(() => { mounted = true; void render(); return () => { active = false; if (widget !== undefined) api?.remove(widget); onToken(''); }; });
|
|
24
|
+
</script>
|
|
25
|
+
<div class="min-w-0" data-testid="turnstile-challenge"><div bind:this={container}></div></div>
|
|
26
|
+
{#if failed}<p role="alert" class="text-sm text-red-400">{failureLabel}</p><Button variant="ghost" type="button" onclick={retry}>{retryLabel}</Button>{/if}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy, tick } from 'svelte';
|
|
3
|
+
import { _, isLoading } from 'svelte-i18n';
|
|
4
|
+
import { requestPluginControl } from '$api/client';
|
|
5
|
+
import { IndustrialDialog, IndustrialToggle, StatusBadge } from '$components/industrial';
|
|
6
|
+
import { Button } from '$components/ui/button';
|
|
7
|
+
import * as Dialog from '$components/ui/dialog';
|
|
8
|
+
import SettingsSection from './SettingsSection.svelte';
|
|
9
|
+
|
|
10
|
+
let {pluginName}: {pluginName: string} = $props();
|
|
11
|
+
const id = $props.id();
|
|
12
|
+
let returnFocus = $state<HTMLElement | null>(null);
|
|
13
|
+
const t = (key: string) => $isLoading ? '' : $_(`plugins.user-auth.${key}`);
|
|
14
|
+
type Turnstile = {version: number; enabled: boolean; siteKey: string; hostnames: string[]; hasSecret: boolean};
|
|
15
|
+
let saved = $state<Turnstile | null>(null), draft = $state<Turnstile | null>(null);
|
|
16
|
+
let open = $state(false), busy = $state(false), loading = $state(true);
|
|
17
|
+
let secret = $state(''), hostnames = $state(''), error = $state('');
|
|
18
|
+
let configured = $derived(!!saved?.siteKey && !!saved?.hasSecret && !!saved?.hostnames.length);
|
|
19
|
+
let enabledChanged = $derived(!!saved && !!draft && saved.enabled !== draft.enabled);
|
|
20
|
+
let dirty = $derived(!!saved && !!draft && (enabledChanged || saved.siteKey !== draft.siteKey || hostnames !== saved.hostnames.join('\n') || !!secret));
|
|
21
|
+
|
|
22
|
+
function resetDraft() {
|
|
23
|
+
draft = saved ? {...saved, hostnames: [...saved.hostnames]} : null;
|
|
24
|
+
hostnames = saved?.hostnames.join('\n') ?? ''; secret = '';
|
|
25
|
+
}
|
|
26
|
+
async function load() {
|
|
27
|
+
loading = true;
|
|
28
|
+
try { saved = await requestPluginControl<Turnstile>(pluginName, '/turnstile', 'GET'); resetDraft(); }
|
|
29
|
+
finally { loading = false; }
|
|
30
|
+
}
|
|
31
|
+
function edit() {
|
|
32
|
+
returnFocus = document.getElementById(id + '-edit'); resetDraft(); error = ''; open = true; }
|
|
33
|
+
function close() { open = false; draft = null; hostnames = ''; secret = ''; error = ''; }
|
|
34
|
+
async function reload() {
|
|
35
|
+
if (busy || loading) return;
|
|
36
|
+
error = '';
|
|
37
|
+
try { await load(); } catch { error = t('settings.errors.failed'); }
|
|
38
|
+
}
|
|
39
|
+
async function save(event: SubmitEvent) {
|
|
40
|
+
event.preventDefault(); if (busy || loading || !draft) return;
|
|
41
|
+
busy = true; error = '';
|
|
42
|
+
try {
|
|
43
|
+
const result = await requestPluginControl<Turnstile>(pluginName, '/turnstile', 'PUT', {
|
|
44
|
+
version: draft.version, enabled: draft.enabled, siteKey: draft.siteKey,
|
|
45
|
+
hostnames: hostnames.split(/[\s,]+/).filter(Boolean), ...(secret ? {secret} : {}),
|
|
46
|
+
});
|
|
47
|
+
saved = result; close(); await tick(); returnFocus?.focus();
|
|
48
|
+
} catch (cause) {
|
|
49
|
+
const code = cause instanceof Error ? cause.message : '';
|
|
50
|
+
if (code === 'version_conflict') { try { await load(); } catch {} }
|
|
51
|
+
error = ['version_conflict', 'turnstile_incomplete', 'invalid_input', 'invalid_origin'].includes(code) ? t(`admin.errors.${code}`) : t('settings.errors.failed');
|
|
52
|
+
} finally { busy = false; await tick(); if (open) document.getElementById(id + '-enabled')?.focus(); }
|
|
53
|
+
}
|
|
54
|
+
onMount(() => { void load().catch(() => { error = t('settings.errors.failed'); }); });
|
|
55
|
+
onDestroy(() => { secret = ''; });
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
{#snippet status()}
|
|
59
|
+
{#if saved}<span role="status" data-testid="turnstile-saved-status"><StatusBadge variant={saved.enabled ? 'active' : configured ? 'standby' : 'muted'}>{t(saved.enabled ? 'turnstile.active' : configured ? 'turnstile.configuredDisabled' : 'turnstile.inactive')}</StatusBadge></span>{/if}
|
|
60
|
+
{/snippet}
|
|
61
|
+
{#snippet actions()}<Button id={id + '-edit'} variant="ghost" disabled={loading || !saved} onclick={edit}>{t('turnstile.configure')}</Button>{/snippet}
|
|
62
|
+
<SettingsSection title={t('turnstile.title')} description={t('turnstile.description')} {status} {actions}>
|
|
63
|
+
{#if loading}<p class="text-sm text-zinc-400">{t('settings.loading')}</p>{/if}
|
|
64
|
+
{#if error && !open}<p role="alert" class="text-sm text-red-400">{error}</p><Button variant="ghost" disabled={loading} onclick={reload}>{t('session.reload')}</Button>{/if}
|
|
65
|
+
</SettingsSection>
|
|
66
|
+
|
|
67
|
+
{#snippet body()}
|
|
68
|
+
{#if draft}<form id={id + '-turnstile'} class="space-y-4" onsubmit={save} aria-label={t('turnstile.title')}>
|
|
69
|
+
<div class="flex items-center gap-3"><IndustrialToggle id={id + '-enabled'} bind:checked={draft.enabled} disabled={busy || loading} label={t('turnstile.enabled')} /><label for={id + '-enabled'} class="nx-field-label cursor-pointer">{t('turnstile.enabled')}</label></div>
|
|
70
|
+
<label class="grid gap-1"><span class="nx-field-label">{t('turnstile.siteKey')}</span><input class="nx-input" bind:value={draft.siteKey} required={draft.enabled} disabled={busy || loading} /></label>
|
|
71
|
+
<label class="grid gap-1"><span class="nx-field-label">{t('turnstile.secret')}</span><input class="nx-input" type="password" autocomplete="new-password" bind:value={secret} required={draft.enabled && !draft.hasSecret} placeholder={draft.hasSecret ? t('admin.secretRetained') : ''} disabled={busy || loading} /></label>
|
|
72
|
+
<label class="grid gap-1"><span class="nx-field-label">{t('turnstile.hostnames')}</span><textarea class="nx-input h-24" bind:value={hostnames} required={draft.enabled} disabled={busy || loading}></textarea></label>
|
|
73
|
+
{#if dirty}<p role="status" class="text-sm text-amber-400">{t('turnstile.pending')}</p>{/if}
|
|
74
|
+
{#if error}<p role="alert" class="text-sm text-red-400">{error}</p>{/if}
|
|
75
|
+
</form>{/if}
|
|
76
|
+
{/snippet}
|
|
77
|
+
{#snippet footer()}
|
|
78
|
+
<Dialog.Close asChild let:builder><Button builders={[builder]} variant="ghost" disabled={busy || loading}>{t('admin.cancel')}</Button></Dialog.Close>
|
|
79
|
+
<Button type="submit" form={id + '-turnstile'} disabled={busy || loading || !draft}>{t(enabledChanged ? (draft?.enabled ? 'turnstile.saveEnable' : 'turnstile.saveDisable') : 'turnstile.save')}</Button>
|
|
80
|
+
{/snippet}
|
|
81
|
+
<IndustrialDialog bind:open {returnFocus} title={t('turnstile.title')} description={t('turnstile.description')} {busy} closeLabel={t('admin.close')} {body} {footer} scrollBody onOpenChange={value => {if (!value) close();}} />
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy } from 'svelte';
|
|
3
|
+
import { _, isLoading } from 'svelte-i18n';
|
|
4
|
+
import { requestPluginControl } from '$api/client';
|
|
5
|
+
import { logout, getAuthStateRevision, isAuthenticationStateCurrent, subject } from '$stores/auth';
|
|
6
|
+
import { PanelCard, IndustrialToggle, IndustrialDialog } from '$components/industrial';
|
|
7
|
+
import { Button } from '$components/ui/button';
|
|
8
|
+
import { validPassword, type User } from './contracts';
|
|
9
|
+
|
|
10
|
+
let {pluginName = 'user-auth'}: {pluginName?: string; apiBase?: string} = $props();
|
|
11
|
+
const id = $props.id();
|
|
12
|
+
const selfId = $derived($subject?.id);
|
|
13
|
+
const t = (key: string) => $isLoading ? '' : $_(`plugins.user-auth.${key}`);
|
|
14
|
+
const lifetime = new AbortController(), ownerRevision = getAuthStateRevision();
|
|
15
|
+
const current = () => !lifetime.signal.aborted && isAuthenticationStateCurrent(ownerRevision);
|
|
16
|
+
const call = <T,>(path: string, method: 'GET' | 'POST' | 'PUT', body?: unknown) => requestPluginControl<T>(pluginName, path, method, body, lifetime.signal);
|
|
17
|
+
let users = $state<User[]>([]), loading = $state(true), busy = $state(false), error = $state('');
|
|
18
|
+
let open = $state(false), operation = $state<'edit' | 'reset'>('edit');
|
|
19
|
+
let draft = $state({id: '', username: '', displayName: '', disabled: false}), password = $state(''), confirmation = $state('');
|
|
20
|
+
let returnFocus = $state<HTMLElement | null>(null);
|
|
21
|
+
let title = $derived(t(operation === 'reset' ? 'users.reset' : draft.id ? 'users.edit' : 'users.new'));
|
|
22
|
+
function fail(cause: unknown) { const code = cause instanceof Error ? cause.message : ''; error = t(`admin.errors.${code}`) === `plugins.user-auth.admin.errors.${code}` ? t('settings.errors.failed') : t(`admin.errors.${code}`); }
|
|
23
|
+
async function load() {
|
|
24
|
+
loading = true;
|
|
25
|
+
try { const result = await call<{users: User[]}>('/users', 'GET'); if (current()) users = result.users; }
|
|
26
|
+
catch (cause) { if (current()) fail(cause); } finally { if (current()) loading = false; }
|
|
27
|
+
}
|
|
28
|
+
function signedOut() { if (current()) { logout(); window.location.hash = '#/login'; } }
|
|
29
|
+
function clearSecrets() { password = ''; confirmation = ''; }
|
|
30
|
+
function edit(user?: User, reset = false) {
|
|
31
|
+
operation = reset ? 'reset' : 'edit';
|
|
32
|
+
draft = user ? {id: user.id, username: user.username, displayName: user.displayName, disabled: user.disabled} : {id: '', username: '', displayName: '', disabled: false};
|
|
33
|
+
clearSecrets(); error = ''; open = true;
|
|
34
|
+
returnFocus = document.getElementById(id + '-create');
|
|
35
|
+
}
|
|
36
|
+
async function mutate(work: () => Promise<void>) {
|
|
37
|
+
if (busy || !current()) return;
|
|
38
|
+
busy = true; error = '';
|
|
39
|
+
try { await work(); } catch (cause) { if (current()) fail(cause); }
|
|
40
|
+
finally { if (current()) busy = false; }
|
|
41
|
+
}
|
|
42
|
+
async function save(event: SubmitEvent) { event.preventDefault(); await mutate(async () => {
|
|
43
|
+
if (operation === 'reset') { validPassword(password, confirmation); await call('/users/password', 'POST', {id: draft.id, password, passwordConfirmation: confirmation}); }
|
|
44
|
+
else if (draft.id) await call('/users/update', 'PUT', {id: draft.id, username: draft.username, displayName: draft.displayName, disabled: draft.disabled});
|
|
45
|
+
else { if (password || confirmation) validPassword(password, confirmation); await call('/users', 'POST', {username: draft.username, displayName: draft.displayName, ...(password ? {password, passwordConfirmation: confirmation} : {})}); }
|
|
46
|
+
clearSecrets();
|
|
47
|
+
if (operation === 'reset' && draft.id === selfId) signedOut();
|
|
48
|
+
else { await load(); if (current()) open = false; }
|
|
49
|
+
}); }
|
|
50
|
+
async function toggle(user: User) { await mutate(async () => {
|
|
51
|
+
await call('/users/update', 'PUT', {id: user.id, username: user.username, displayName: user.displayName, disabled: !user.disabled});
|
|
52
|
+
if (selfId === user.id) signedOut(); else await load();
|
|
53
|
+
}); }
|
|
54
|
+
onMount(() => { void load(); });
|
|
55
|
+
onDestroy(() => { lifetime.abort(); clearSecrets(); });
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<div class="space-y-4" data-testid="auth-users">
|
|
59
|
+
<div class="flex flex-wrap items-center justify-between gap-3">
|
|
60
|
+
<div class="space-y-2"><h1 class="nx-display text-xl text-zinc-50">{t('users.title')}</h1></div>
|
|
61
|
+
<Button id={id + '-create'} disabled={busy || loading} onclick={() => edit()}>{t('users.new')}</Button>
|
|
62
|
+
</div>
|
|
63
|
+
<PanelCard title={t('users.title')} tag="USERS">
|
|
64
|
+
<div class="space-y-4">
|
|
65
|
+
<p class="text-sm text-zinc-400">{t('users.access')}</p>
|
|
66
|
+
{#if loading}<p class="text-sm text-zinc-400">{t('settings.loading')}</p>
|
|
67
|
+
{:else if !users.length}<p class="text-sm text-zinc-400">{t('users.empty')}</p>
|
|
68
|
+
{:else}
|
|
69
|
+
<div class="space-y-2">{#each users as user (user.id)}
|
|
70
|
+
<div class="flex flex-col gap-2 border-b border-carbon-600 pb-3 sm:flex-row sm:items-center sm:justify-between" data-testid="auth-user-row">
|
|
71
|
+
<div class="min-w-0"><p class="break-words text-zinc-200">{user.displayName || user.username}</p><p class="text-sm text-zinc-400 break-all">{user.username} · {user.disabled ? t('users.disabled') : t('users.enabled')} · {user.hasLocalPassword ? t('users.local') : t('users.sso')}</p></div>
|
|
72
|
+
<div class="flex flex-wrap items-center gap-2"><Button variant="ghost" disabled={busy} onclick={() => edit(user)}>{t('admin.edit')}</Button><Button variant="ghost" disabled={busy} onclick={() => edit(user, true)}>{t('users.reset')}</Button><IndustrialToggle checked={!user.disabled} disabled={busy} label={t('users.toggle') + ' ' + user.username} onchange={() => toggle(user)} /></div>
|
|
73
|
+
</div>
|
|
74
|
+
{/each}</div>
|
|
75
|
+
{/if}
|
|
76
|
+
{#if error && !open}<p class="text-sm text-red-400" role="alert">{error}</p><Button variant="ghost" disabled={busy} onclick={() => {error = ''; void load();}}>{t('session.reload')}</Button>{/if}
|
|
77
|
+
</div>
|
|
78
|
+
</PanelCard>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
{#snippet editorBody()}
|
|
82
|
+
<form id={id + '-form'} onsubmit={save} class="space-y-3" aria-label={title} aria-busy={busy}>
|
|
83
|
+
{#if operation === 'reset'}<p class="text-sm text-zinc-200 break-all">{draft.username}</p>
|
|
84
|
+
{:else}
|
|
85
|
+
<div class="grid gap-3"><label class="grid gap-1"><span class="nx-field-label">{t('login.username')}</span><input class="nx-input" required maxlength="64" bind:value={draft.username} disabled={busy} /></label><label class="grid gap-1"><span class="nx-field-label">{t('users.displayName')}</span><input class="nx-input" maxlength="256" bind:value={draft.displayName} disabled={busy} /></label></div>
|
|
86
|
+
{/if}
|
|
87
|
+
{#if operation === 'reset' || !draft.id}
|
|
88
|
+
{#if operation !== 'reset'}<p class="text-sm text-zinc-400">{t('users.optionalPassword')}</p>{/if}
|
|
89
|
+
<div class="grid gap-3"><label class="grid gap-1"><span class="nx-field-label">{t('users.password')}</span><input class="nx-input" type="password" autocomplete="new-password" required={operation === 'reset'} bind:value={password} disabled={busy} /></label><label class="grid gap-1"><span class="nx-field-label">{t('users.confirmation')}</span><input class="nx-input" type="password" autocomplete="new-password" required={operation === 'reset'} bind:value={confirmation} disabled={busy} /></label></div>
|
|
90
|
+
{/if}
|
|
91
|
+
{#if error}<p class="text-sm text-red-400" role="alert">{error}</p>{/if}
|
|
92
|
+
</form>
|
|
93
|
+
{/snippet}
|
|
94
|
+
{#snippet editorFooter()}<Button type="submit" form={id + '-form'} disabled={busy}>{t(operation === 'reset' ? 'users.reset' : 'admin.save')}</Button>{/snippet}
|
|
95
|
+
<IndustrialDialog bind:open {title} description={t(operation === 'reset' ? 'users.revokes' : 'users.editDescription')} {busy} {returnFocus} closeLabel={t('admin.close')} body={editorBody} footer={editorFooter} scrollBody onOpenChange={value => {if (!value) {clearSecrets(); error = '';}}} />
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
## Statement of Purpose
|
|
4
|
+
|
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an “owner”) of an original work of authorship and/or a database (each, a “Work”).
|
|
6
|
+
|
|
7
|
+
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works (“Commons”) that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
|
|
8
|
+
|
|
9
|
+
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the “Affirmer”), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
|
|
10
|
+
|
|
11
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights (“Copyright and Related Rights”). Copyright and Related Rights include, but are not limited to, the following:
|
|
12
|
+
1. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
|
|
13
|
+
2. moral rights retained by the original author(s) and/or performer(s);
|
|
14
|
+
3. publicity and privacy rights pertaining to a person’s image or likeness depicted in a Work;
|
|
15
|
+
4. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(i), below;
|
|
16
|
+
5. rights protecting the extraction, dissemination, use and reuse of data in a Work;
|
|
17
|
+
6. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
|
|
18
|
+
7. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
|
|
19
|
+
|
|
20
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the “Waiver”). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer’s heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer’s express Statement of Purpose.
|
|
21
|
+
|
|
22
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer’s express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer’s Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the “License”). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer’s express Statement of Purpose.
|
|
23
|
+
|
|
24
|
+
4. Limitations and Disclaimers.
|
|
25
|
+
1. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
|
|
26
|
+
2. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
|
|
27
|
+
3. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person’s Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
|
|
28
|
+
4. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
|
|
29
|
+
|
|
30
|
+
For more information, please see https://creativecommons.org/publicdomain/zero/1.0/.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Google</title><path d="M12.48 10.92v3.28h7.84c-.24 1.84-.853 3.187-1.787 4.133-1.147 1.147-2.933 2.4-6.053 2.4-4.827 0-8.6-3.893-8.6-8.72s3.773-8.72 8.6-8.72c2.6 0 4.507 1.027 5.907 2.347l2.307-2.307C18.747 1.44 16.133 0 12.48 0 5.867 0 .307 5.387.307 12s5.56 12 12.173 12c3.573 0 6.267-1.173 8.373-3.36 2.16-2.16 2.84-5.213 2.84-7.667 0-.76-.053-1.467-.173-2.053H12.48z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Microsoft</title><path d="M0 0v11.408h11.408V0zm12.594 0v11.408H24V0zM0 12.594V24h11.408V12.594zm12.594 0V24H24V12.594z"/></svg>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type User = {id: string; username: string; displayName: string; disabled: boolean; hasLocalPassword: boolean; requiresPasswordChange: boolean};
|
|
2
|
+
import type { LoginProvider, MicrosoftConfiguration, OidcConfiguration } from '../shared/login-connections';
|
|
3
|
+
export type { LoginProvider, MicrosoftConfiguration, OidcConfiguration } from '../shared/login-connections';
|
|
4
|
+
export type Connection = {id: string; label: string; enabled: boolean; provider: LoginProvider; issuer: string; clientId: string; scopes: string[]; hasSecret: boolean; version: number; configuration: Record<string, never> | MicrosoftConfiguration | OidcConfiguration};
|
|
5
|
+
export type ConnectionInput = {id: string; label: string; enabled: boolean; provider: LoginProvider; clientId: string; clientSecret?: string; configuration: Connection['configuration']; scopes?: string[]; version?: number};
|
|
6
|
+
export type DiscoveryMetadata = {issuer: string; discoveryUrl: string; authorizationEndpoint: string; tokenEndpoint: string; jwksUri: string; tokenEndpointAuthMethods: string[]; idTokenSigningAlgs: string[]};
|
|
7
|
+
export type Identity = {id: string; userId: string; connectionId: string; issuer: string; subject: string};
|
|
8
|
+
export function validPassword(password: string, confirmation: string) {
|
|
9
|
+
if (password !== confirmation) throw new Error('password_confirmation');
|
|
10
|
+
if ([...password].length < 5 || [...password].length > 32) throw new Error('invalid_password');
|
|
11
|
+
}
|
|
12
|
+
export function authorizationUrl(value: string): string {
|
|
13
|
+
const url = new URL(value);
|
|
14
|
+
if (!['https:', 'http:'].includes(url.protocol)) throw new Error('oidc_failed');
|
|
15
|
+
return url.href;
|
|
16
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const loginCodes = new Set([
|
|
2
2
|
'invalid_credentials', 'invalid_input', 'forbidden', 'unauthorized', 'invalid_origin',
|
|
3
3
|
'invalid_csrf', 'login_limited', 'session_limit', 'management_provider_unavailable',
|
|
4
|
-
'provider_unavailable', 'control_recovering',
|
|
4
|
+
'provider_unavailable', 'control_recovering', 'turnstile_required', 'turnstile_failed',
|
|
5
|
+
'invalid_provider', 'invalid_microsoft_configuration', 'invalid_microsoft_tenant', 'microsoft_account_scope', 'microsoft_signing_key_issuer', 'invalid_oidc_configuration', 'invalid_oauth_identity', 'oidc_metadata_failed', 'oidc_metadata_invalid', 'oidc_metadata_limit', 'oidc_network_failed', 'oidc_pkce_unsupported', 'oidc_signing_alg_unsupported', 'preset_scopes_fixed', 'verified_identity_required', 'invalid_oidc_url', 'oidc_issuer_mismatch', 'oidc_auth_method_unsupported', 'oidc_secret_required',
|
|
6
|
+
'oauth_client_rejected', 'oauth_callback_mismatch', 'oauth_code_rejected', 'oauth_email_unverified', 'oauth_token_failed',
|
|
7
|
+
'unknown_identity', 'disabled_user', 'invalid_oidc_flow', 'oidc_failed', 'identity_connection_mismatch',
|
|
5
8
|
]);
|
|
6
9
|
|
|
7
10
|
/** Only the local account provider interprets its credential result. */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface TurnstileApi {
|
|
2
|
+
render(container: HTMLElement, options: { sitekey: string; action: string; size: 'flexible'; callback(token: string): void; 'expired-callback'(): void; 'error-callback'(): void }): string;
|
|
3
|
+
reset(id: string): void;
|
|
4
|
+
remove(id: string): void;
|
|
5
|
+
}
|
|
6
|
+
declare global { interface Window { turnstile?: TurnstileApi } }
|
|
7
|
+
let loading: Promise<TurnstileApi> | undefined;
|
|
8
|
+
/** One external script per page; rejected loads can be retried explicitly. */
|
|
9
|
+
export function loadTurnstile(): Promise<TurnstileApi> {
|
|
10
|
+
if (window.turnstile) return Promise.resolve(window.turnstile);
|
|
11
|
+
return loading ??= new Promise<TurnstileApi>((resolve, reject) => {
|
|
12
|
+
const script = document.createElement('script');
|
|
13
|
+
script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
|
|
14
|
+
script.async = true;
|
|
15
|
+
const timer = setTimeout(() => fail(), 15_000);
|
|
16
|
+
const fail = () => { clearTimeout(timer); script.remove(); loading = undefined; reject(new Error('turnstile_unavailable')); };
|
|
17
|
+
script.onload = () => { clearTimeout(timer); if (window.turnstile) resolve(window.turnstile); else fail(); };
|
|
18
|
+
script.onerror = fail;
|
|
19
|
+
document.head.appendChild(script);
|
|
20
|
+
});
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffusion/bungee-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Bungee reverse proxy core engine",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"types": "./dist/main.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@iconify-json/lucide": "^1.2.145",
|
|
17
17
|
"@iconify-json/tabler": "^1.2.42",
|
|
18
18
|
"@iconify/utils": "^3.1.7",
|
|
19
|
-
"@jeffusion/bungee-types": "^
|
|
19
|
+
"@jeffusion/bungee-types": "^6.0.1",
|
|
20
20
|
"@types/lodash-es": "^4.17.12",
|
|
21
21
|
"@types/ws": "^8.18.1",
|
|
22
22
|
"acorn": "^8.15.0",
|