File size: 2,246 Bytes
c09f67c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | export const SCOPES = [
"bank-accounts.read",
"bank-accounts.write",
"chat.read",
"chat.write",
"customers.read",
"customers.write",
"documents.read",
"documents.write",
"inbox.read",
"inbox.write",
"insights.read",
"invoices.read",
"invoices.write",
"reports.read",
"search.read",
"tags.read",
"tags.write",
"teams.read",
"teams.write",
"tracker-entries.read",
"tracker-entries.write",
"tracker-projects.read",
"tracker-projects.write",
"transactions.read",
"transactions.write",
"users.read",
"users.write",
"notifications.read",
"notifications.write",
"apis.all", // All API scopes
"apis.read", // All read scopes
] as const;
export type Scope = (typeof SCOPES)[number];
export type ScopePreset = "all_access" | "read_only" | "restricted";
export const scopePresets = [
{
value: "all_access",
label: "All",
description: "full access to all resources",
},
{
value: "read_only",
label: "Read Only",
description: "read-only access to all resources",
},
{
value: "restricted",
label: "Restricted",
description: "restricted access to some resources",
},
];
export const scopesToName = (scopes: string[]) => {
if (scopes.includes("apis.all")) {
return {
name: "All access",
description: "full access to all resources",
preset: "all_access",
};
}
if (scopes.includes("apis.read")) {
return {
name: "Read-only",
description: "read-only access to all resources",
preset: "read_only",
};
}
return {
name: "Restricted",
description: "restricted access to some resources",
preset: "restricted",
};
};
export const expandScopes = (scopes: string[]): string[] => {
if (scopes.includes("apis.all")) {
// Return all scopes except any that start with "apis."
return SCOPES.filter((scope) => !scope.startsWith("apis."));
}
if (scopes.includes("apis.read")) {
// Return all read scopes except any that start with "apis."
return SCOPES.filter(
(scope) => scope.endsWith(".read") && !scope.startsWith("apis."),
);
}
// For custom scopes, filter out any "apis." scopes
return scopes.filter((scope) => !scope.startsWith("apis."));
};
|