mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 06:47:39 +00:00
refactor(device-auth): share store types + normalization
This commit is contained in:
30
src/shared/device-auth.ts
Normal file
30
src/shared/device-auth.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export type DeviceAuthEntry = {
|
||||
token: string;
|
||||
role: string;
|
||||
scopes: string[];
|
||||
updatedAtMs: number;
|
||||
};
|
||||
|
||||
export type DeviceAuthStore = {
|
||||
version: 1;
|
||||
deviceId: string;
|
||||
tokens: Record<string, DeviceAuthEntry>;
|
||||
};
|
||||
|
||||
export function normalizeDeviceAuthRole(role: string): string {
|
||||
return role.trim();
|
||||
}
|
||||
|
||||
export function normalizeDeviceAuthScopes(scopes: string[] | undefined): string[] {
|
||||
if (!Array.isArray(scopes)) {
|
||||
return [];
|
||||
}
|
||||
const out = new Set<string>();
|
||||
for (const scope of scopes) {
|
||||
const trimmed = scope.trim();
|
||||
if (trimmed) {
|
||||
out.add(trimmed);
|
||||
}
|
||||
}
|
||||
return [...out].toSorted();
|
||||
}
|
||||
Reference in New Issue
Block a user