Skip to content

Instantly share code, notes, and snippets.

@urbushey
Last active November 22, 2024 18:24
Show Gist options
  • Save urbushey/cb093b57aa8f57e25cde316a6dd68091 to your computer and use it in GitHub Desktop.
Save urbushey/cb093b57aa8f57e25cde316a6dd68091 to your computer and use it in GitHub Desktop.
type GeneralCollaboratorType = "all" | "none";
type SpecificCollaboratorType = "inclusion" | "exclusion";
type NonAuthenticatedCollaborator = {
type: "anonymous";
};
type CollaboratorList = {
type: SpecificCollaboratorType,
company_ids: number[]
}
type GeneralCollaborator = {
type: GeneralCollaboratorType
}
type QueryCollaborator = CollaboratorList | GeneralCollaborator; // non-authenticated-users not allowed here
type ViewCollaborator = CollaboratorList | GeneralCollaborator | NonAuthenticatedCollaborator; // non-authenticated-users only allowed here
type QueryAccess = QueryCollaborator;
type ViewAccess = ViewCollaborator;
type CollaboratorConfig = {
query: QueryAccess;
view: ViewAccess;
}
// example type usage
const exampleConfig: CollaboratorConfig = {
query: {
type: "inclusion",
company_ids: [1, 2, 3] // Specific companies can query
},
view: {
type: "anonymous" // Anyone, even unauthenticated users, can view
}
};
const anotherConfig: CollaboratorConfig = {
query: {
type: "none" // No one can query
},
view: {
type: "all" // All authenticated users can view
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment