mirror of
https://github.com/unraid/api.git
synced 2026-01-06 16:49:49 -06:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * API Key Authorization flow with consent screen, callback support, and a Tools page. * Schema-driven API Key creation UI with permission presets, templates, and Developer Authorization Link. * Effective Permissions preview and a new multi-select permission control. * **UI Improvements** * Mask/toggle API keys, copy-to-clipboard with toasts, improved select labels, new label styles, tab wrapping, and accordionized color controls. * **Documentation** * Public guide for the API Key authorization flow and scopes added. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
import { ref } from 'vue';
|
|
import { defineStore } from 'pinia';
|
|
|
|
import type { ApiKeyFragment } from '~/composables/gql/graphql.js';
|
|
import type { AuthorizationFormData } from '~/utils/authorizationScopes';
|
|
|
|
import '~/store/globalPinia.js';
|
|
|
|
export const useApiKeyStore = defineStore('apiKey', () => {
|
|
const modalVisible = ref(false);
|
|
const editingKey = ref<ApiKeyFragment | null>(null);
|
|
const createdKey = ref<ApiKeyFragment | null>(null);
|
|
|
|
// Authorization mode state
|
|
const isAuthorizationMode = ref(false);
|
|
const authorizationData = ref<{
|
|
name: string;
|
|
description: string;
|
|
scopes: string[];
|
|
formData?: AuthorizationFormData;
|
|
onAuthorize?: (apiKey: string) => void;
|
|
} | null>(null);
|
|
|
|
function showModal(key: ApiKeyFragment | null = null) {
|
|
editingKey.value = key;
|
|
modalVisible.value = true;
|
|
// Reset authorization mode if editing
|
|
if (key) {
|
|
isAuthorizationMode.value = false;
|
|
authorizationData.value = null;
|
|
}
|
|
}
|
|
|
|
function hideModal() {
|
|
modalVisible.value = false;
|
|
editingKey.value = null;
|
|
isAuthorizationMode.value = false;
|
|
authorizationData.value = null;
|
|
}
|
|
|
|
function setAuthorizationMode(
|
|
name: string,
|
|
description: string,
|
|
scopes: string[],
|
|
onAuthorize?: (apiKey: string) => void,
|
|
formData?: AuthorizationFormData
|
|
) {
|
|
isAuthorizationMode.value = true;
|
|
authorizationData.value = {
|
|
name,
|
|
description,
|
|
scopes,
|
|
formData,
|
|
onAuthorize,
|
|
};
|
|
editingKey.value = null;
|
|
}
|
|
|
|
function setCreatedKey(key: ApiKeyFragment | null) {
|
|
createdKey.value = key;
|
|
}
|
|
|
|
function clearCreatedKey() {
|
|
createdKey.value = null;
|
|
}
|
|
|
|
return {
|
|
modalVisible,
|
|
editingKey,
|
|
createdKey,
|
|
isAuthorizationMode,
|
|
authorizationData,
|
|
showModal,
|
|
hideModal,
|
|
setAuthorizationMode,
|
|
setCreatedKey,
|
|
clearCreatedKey,
|
|
};
|
|
});
|