Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_identities_getIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const registerV1IdentitiesGetIdentity = (app: App) =>
const { identityId, externalId } = c.req.valid("query");
const { db } = c.get("services");

if (!identityId && !externalId) {
if (!(identityId || externalId)) {
throw new UnkeyApiError({
code: "BAD_REQUEST",
message: "Provide either identityId or externalId",
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/routes/v1_identities_updateIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const registerV1IdentitiesUpdateIdentity = (app: App) =>

const { db, cache } = c.get("services");

if (!req.identityId && !req.externalId) {
if (!(req.identityId || req.externalId)) {
throw new UnkeyApiError({
code: "BAD_REQUEST",
message: "Provide either identityId or externalId",
Expand Down Expand Up @@ -234,14 +234,14 @@ export const registerV1IdentitiesUpdateIdentity = (app: App) =>
const updateRatelimits: Ratelimit[] = [];
for (const rl of identity.ratelimits) {
const newRl = req.ratelimits.find((r) => r.name === rl.name);
if (!newRl) {
deleteRatelimits.push(rl);
} else {
if (newRl) {
updateRatelimits.push({
...rl,
limit: newRl.limit,
duration: newRl.duration,
});
} else {
deleteRatelimits.push(rl);
}
}
for (const newRl of req.ratelimits) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_keys_getVerifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export const registerV1KeysGetVerifications = (app: App) =>
function transformData(
data: VerificationTimeseriesDataPoint[] | undefined,
): CacheNamespaces["verificationsByKeyId"] {
if (!data || !data.length) {
if (!data?.length) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_migrations_createKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export const registerV1MigrationsCreateKeys = (app: App) =>
});
}

if (!key.hash && !key.plaintext) {
if (!(key.hash || key.plaintext)) {
throw new UnkeyApiError({
code: "BAD_REQUEST",
message: "provide either `hash` or `plaintext`",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_ratelimits_deleteOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const registerV1RatelimitDeleteOverride = (app: App) =>
c,
buildUnkeyQuery(({ or }) => or("*", "ratelimit.*.delete_override")),
);
if (!namespaceId && !namespaceName) {
if (!(namespaceId || namespaceName)) {
throw new UnkeyApiError({
code: "BAD_REQUEST",
message: "You must provide a namespaceId or a namespaceName",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_ratelimits_getOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const registerV1RatelimitGetOverride = (app: App) =>
message: "Missing required permission: ratelimit.*.read_override",
});
}
if (!namespaceId && !namespaceName) {
if (!(namespaceId || namespaceName)) {
throw new UnkeyApiError({
code: "BAD_REQUEST",
message: "You must provide a namespaceId or a namespaceName",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_ratelimits_listOverrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const registerV1RatelimitListOverrides = (app: App) =>
app.openapi(route, async (c) => {
const { namespaceId, namespaceName, limit, cursor } = c.req.valid("query");
const { db } = c.get("services");
if (!namespaceId && !namespaceName) {
if (!(namespaceId || namespaceName)) {
throw new UnkeyApiError({
code: "BAD_REQUEST",
message: "You must provide a namespaceId or a namespaceName",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/v1_ratelimits_setOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export type V1RatelimitSetOverrideResponse = z.infer<
export const registerV1RatelimitSetOverride = (app: App) =>
app.openapi(route, async (c) => {
const req = c.req.valid("json");
if (!req.namespaceId && !req.namespaceName) {
if (!(req.namespaceId || req.namespaceName)) {
throw new UnkeyApiError({
code: "BAD_REQUEST",
message: "You must provide a namespaceId or a namespaceName",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ export const ExpirationSetup = () => {

// Calculate date for showing warning about close expiry (less than 1 hour)
const isExpiringVerySoon =
currentExpiryDate &&
new Date(currentExpiryDate).getTime() - new Date().getTime() < 60 * 60 * 1000;
currentExpiryDate && new Date(currentExpiryDate).getTime() - Date.now() < 60 * 60 * 1000;

const getExpiryDescription = () => {
if (isExpiringVerySoon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const MetadataSetup = () => {
rows={15}
{...register("metadata.data", {
validate: (value) => {
if (metadataEnabled && (!value || !validateJSON(value))) {
if (metadataEnabled && !(value && validateJSON(value))) {
return "Must be valid JSON";
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export const expirationValidationSchema = z.object({
})
.refine(
(date) => {
const minDate = new Date(new Date().getTime() + 2 * 60000);
const minDate = new Date(Date.now() + 2 * 60000);
return date >= minDate;
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export const formValuesToApiInput = (formValues: FormValues, keyAuthId: string):
export const isFeatureEnabled = (sectionId: SectionName, values: FormValues): boolean => {
switch (sectionId) {
case "metadata":
return values.metadata?.enabled || false;
return Boolean(values.metadata?.enabled);
case "ratelimit":
return values.ratelimit?.enabled || false;
return Boolean(values.ratelimit?.enabled);
case "credits":
return values.limit?.enabled || false;
return Boolean(values.limit?.enabled);
case "expiration":
return values.expiration?.enabled || false;
return Boolean(values.expiration?.enabled);
case "general":
return true;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ export function createIdentityOptions({
Metadata
</div>
{/* Content - Different based on metadata presence */}
{!isMetaEmpty(identity.meta) ? (
{isMetaEmpty(identity.meta) ? (
<div className="px-2 py-2 flex-1">
<div className="w-full bg-grayA-1 dark:bg-grayA-2 border rounded-lg border-grayA-5 overflow-hidden">
<div className="flex items-start justify-between w-full gap-2">
<div className="overflow-x-auto w-full min-w-0 p-3">
<pre className="whitespace-pre-wrap break-all text-[11px] leading-5 text-gray-8 font-mono">
No metadata available
</pre>
</div>
</div>
</div>
</div>
) : (
<div className="px-2 py-2 flex-1 overflow-y-auto h-[270px]">
<div className="w-full bg-grayA-1 dark:bg-grayA-2 border rounded-lg border-grayA-5 overflow-hidden h-full">
<div className="flex items-start justify-between w-full gap-2 h-full">
Expand All @@ -90,18 +102,6 @@ export function createIdentityOptions({
</div>
</div>
</div>
) : (
<div className="px-2 py-2 flex-1">
<div className="w-full bg-grayA-1 dark:bg-grayA-2 border rounded-lg border-grayA-5 overflow-hidden">
<div className="flex items-start justify-between w-full gap-2">
<div className="overflow-x-auto w-full min-w-0 p-3">
<pre className="whitespace-pre-wrap break-all text-[11px] leading-5 text-gray-8 font-mono">
No metadata available
</pre>
</div>
</div>
</div>
</div>
)}
</div>
</TooltipContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,15 @@ export const LogsDateTime = () => {
}}
initialTitle={title ?? ""}
onSuggestionChange={setTitle}
customOptions={DEFAULT_OPTIONS.filter(
(option) => !option.value || !option.value.endsWith("m"),
)}
customOptions={DEFAULT_OPTIONS.filter((option) => !option.value?.endsWith("m"))}
>
<div className="group">
<Button
variant="ghost"
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const useFilters = () => {
const activeFilters: KeysOverviewFilterValue[] = [];

for (const [field, value] of Object.entries(searchParams)) {
if (!Array.isArray(value) || !["keyIds", "names", "identities", "outcomes"].includes(field)) {
if (
!(Array.isArray(value) && ["keyIds", "names", "identities", "outcomes"].includes(field))
) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/apis/[apiId]/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ApiLayoutData = {

export const fetchApiAndWorkspaceDataFromDb = async (apiId: string): Promise<ApiLayoutData> => {
const { orgId } = await getAuth();
if (!apiId || !orgId) {
if (!(apiId && orgId)) {
console.error("fetchApiLayoutDataFromDb: apiId or orgId is missing");
notFound();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,15 @@ export const LogsDateTime = () => {
}}
initialTitle={title ?? ""}
onSuggestionChange={setTitle}
customOptions={DEFAULT_OPTIONS.filter(
(option) => !option.value || !option.value.endsWith("m"),
)}
customOptions={DEFAULT_OPTIONS.filter((option) => !option.value?.endsWith("m"))}
>
<div className="group">
<Button
variant="ghost"
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export const UpdateKeyStatus = ({ keyDetails, isOpen, onClose }: UpdateKeyStatus

const handleActionButtonClick = () => {
// Only show confirmation popover for disabling
if (!isEnabling) {
setIsConfirmPopoverOpen(true);
} else {
if (isEnabling) {
performStatusUpdate();
} else {
setIsConfirmPopoverOpen(true);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const EditExternalId = ({
return;
}

if (!isConfirmPopoverOpen && !open) {
if (!(isConfirmPopoverOpen || open)) {
onClose();
}
};
Expand Down Expand Up @@ -99,7 +99,7 @@ export const EditExternalId = ({
className="rounded-lg flex-1"
loading={updateKeyOwner.isLoading}
onClick={handleSubmit}
disabled={!originalIdentityId && !selectedIdentityId}
disabled={!(originalIdentityId || selectedIdentityId)}
>
Update External ID
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const BatchEditExternalId = ({
return;
}

if (!isConfirmPopoverOpen && !open) {
if (!(isConfirmPopoverOpen || open)) {
onClose();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useKeysListQuery({ keyAuthId }: UseKeysListQueryParams) {
};

filters.forEach((filter) => {
if (!keysListFilterFieldNames.includes(filter.field) || !params[filter.field]) {
if (!(keysListFilterFieldNames.includes(filter.field) && params[filter.field])) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const KeysList = ({
) : (
<>
{/* Show icon when not selected and not hovered */}
{!isSelected && !isHovered && (
{!(isSelected || isHovered) && (
// biome-ignore lint/complexity/noUselessFragments: <explanation>
<>
{identity ? (
Expand Down Expand Up @@ -279,7 +279,7 @@ export const KeysList = ({
}

// Early exit if we already found a mix
if (!allEnabled && !allDisabled) {
if (!(allEnabled || allDisabled)) {
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,17 @@ export const DeleteProtection: React.FC<Props> = ({ api }) => {
: "Enable API Delete Protection"}
</Button>
<div className="font-normal text-[12px] text-gray-9 text-center">
This setting can be {!api.deleteProtection ? "disabled" : "re-enabled"} at any time
This setting can be {api.deleteProtection ? "re-enabled" : "disabled"} at any time
</div>
</div>
}
>
<div className="flex flex-col gap-4">
<p className="text-gray-11 text-[13px]">
<span className="font-medium">Important: </span>
{!api.deleteProtection
? "Enabling this prevents the API from being deleted. This setting can be disabled at any time. "
: "Disabling this allows API deletion. This setting can be re-enabled at any time. "}
{api.deleteProtection
? "Disabling this allows API deletion. This setting can be re-enabled at any time. "
: "Enabling this prevents the API from being deleted. This setting can be disabled at any time. "}
<InlineLink
label="Learn more"
href="https://www.unkey.com/docs/security/delete-protection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const LogsDateTime = () => {
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const LogsDateTime = () => {
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default async function RolePage(props: Props) {
},
},
});
if (!role || !role.workspace) {
if (!role?.workspace) {
return notFound();
}
if (role.workspace.orgId !== orgId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const LogsDateTime = () => {
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const LogsDateTime = () => {
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const LogsDateTime = () => {
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const LogsDateTime = () => {
size="md"
className={cn(
"group-data-[state=open]:bg-gray-4 px-2 rounded-lg",
!title ? "opacity-50" : "",
title ? "" : "opacity-50",
title !== "Last 12 hours" ? "bg-gray-4" : "",
)}
aria-label="Filter logs by time"
Expand Down
Loading
Loading