chore: test deploy snapshot
This commit is contained in:
@@ -19,6 +19,25 @@ export type TokenSettingRecord = {
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type TokenSettingActivityRecord = {
|
||||
id: number;
|
||||
settingId: string;
|
||||
activityType: 'created' | 'updated' | 'deleted';
|
||||
actorLabel: string | null;
|
||||
summary: string;
|
||||
detail: string | null;
|
||||
clientIp: string | null;
|
||||
externalIp: string | null;
|
||||
forwardedFor: string | null;
|
||||
realIp: string | null;
|
||||
host: string | null;
|
||||
origin: string | null;
|
||||
referer: string | null;
|
||||
userAgent: string | null;
|
||||
clientId: string | null;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
export type TokenSettingInput = {
|
||||
originalId?: string;
|
||||
id?: string;
|
||||
@@ -40,6 +59,7 @@ const TOKEN_SETTINGS_REQUEST_TIMEOUT_MS = 8000;
|
||||
|
||||
type TokenSettingsRequestOptions = {
|
||||
shareToken?: string | null;
|
||||
path?: string | null;
|
||||
};
|
||||
|
||||
class TokenSettingApiError extends Error {
|
||||
@@ -209,7 +229,7 @@ async function requestOnce<T>(baseUrl: string, init?: RequestInit, options?: Tok
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${baseUrl}${TOKEN_SETTINGS_API_PATH}`, {
|
||||
const response = await fetch(`${baseUrl}${options?.path?.trim() || TOKEN_SETTINGS_API_PATH}`, {
|
||||
...init,
|
||||
headers,
|
||||
signal: controller.signal,
|
||||
@@ -262,6 +282,27 @@ async function requestTokenSettings<T>(init?: RequestInit, options?: TokenSettin
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeActivityRecord(record: Partial<TokenSettingActivityRecord>): TokenSettingActivityRecord {
|
||||
return {
|
||||
id: Number(record.id ?? 0),
|
||||
settingId: normalizeSettingId(record.settingId),
|
||||
activityType: record.activityType === 'created' || record.activityType === 'deleted' ? record.activityType : 'updated',
|
||||
actorLabel: normalizeText(record.actorLabel) || null,
|
||||
summary: normalizeText(record.summary),
|
||||
detail: normalizeText(record.detail) || null,
|
||||
clientIp: normalizeText(record.clientIp) || null,
|
||||
externalIp: normalizeText(record.externalIp) || null,
|
||||
forwardedFor: normalizeText(record.forwardedFor) || null,
|
||||
realIp: normalizeText(record.realIp) || null,
|
||||
host: normalizeText(record.host) || null,
|
||||
origin: normalizeText(record.origin) || null,
|
||||
referer: normalizeText(record.referer) || null,
|
||||
userAgent: normalizeText(record.userAgent) || null,
|
||||
clientId: normalizeText(record.clientId) || null,
|
||||
createdAt: normalizeText(record.createdAt) || new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
async function loadTokenSettingsFromServer(options?: TokenSettingsRequestOptions) {
|
||||
const response = await requestTokenSettings<{ ok: boolean; tokenSettings: Partial<TokenSettingRecord>[] | null }>({
|
||||
method: 'GET',
|
||||
@@ -280,6 +321,20 @@ async function saveTokenSettingsToServer(items: TokenSettingRecord[], options?:
|
||||
return sanitizeTokenSettings(response.tokenSettings);
|
||||
}
|
||||
|
||||
export async function fetchTokenSettingActivities(settingId: string, options?: TokenSettingsRequestOptions) {
|
||||
const normalizedSettingId = normalizeSettingId(settingId);
|
||||
if (!normalizedSettingId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const response = await requestTokenSettings<{ ok: boolean; activities: Partial<TokenSettingActivityRecord>[] | null }>(
|
||||
{ method: 'GET' },
|
||||
{ shareToken: options?.shareToken, path: `${TOKEN_SETTINGS_API_PATH}/${encodeURIComponent(normalizedSettingId)}/activities` },
|
||||
);
|
||||
|
||||
return Array.isArray(response.activities) ? response.activities.map((item) => normalizeActivityRecord(item)) : [];
|
||||
}
|
||||
|
||||
export function upsertTokenSetting(items: TokenSettingRecord[], input: TokenSettingInput) {
|
||||
const nextItem = normalizeTokenSetting({
|
||||
...input,
|
||||
|
||||
Reference in New Issue
Block a user