Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7c49bd1
feat: new filter logic
ogzhanolguncu Jan 10, 2025
23b7393
fix: remove ununused hook
ogzhanolguncu Jan 10, 2025
feaa801
Merge branch 'main' into logs-v2-filter-cloud
ogzhanolguncu Jan 13, 2025
92c1c99
fix: parsing logic
ogzhanolguncu Jan 13, 2025
61c8abb
Merge branch 'logs-v2-filter-cloud' of github.com:unkeyed/unkey into …
ogzhanolguncu Jan 13, 2025
fd36900
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 13, 2025
1cd7e17
chore: remove log
ogzhanolguncu Jan 13, 2025
89281b2
Merge branch 'logs-v2-filter-cloud' of github.com:unkeyed/unkey into …
ogzhanolguncu Jan 13, 2025
723738f
chore: revert flag
ogzhanolguncu Jan 13, 2025
0c1b297
feat: add ui for logs search
ogzhanolguncu Jan 13, 2025
e9afe8e
fix: input for search
ogzhanolguncu Jan 13, 2025
2dac542
feat: add structured query parsing
ogzhanolguncu Jan 13, 2025
33116a9
feat: allow parsing multiple search
ogzhanolguncu Jan 13, 2025
6beefba
chore: run formatter
ogzhanolguncu Jan 13, 2025
964a99f
Merge branch 'main' of github.com:unkeyed/unkey into logs-v2-search
ogzhanolguncu Jan 13, 2025
df0903a
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 13, 2025
5182ba5
chore: fix build issue
ogzhanolguncu Jan 13, 2025
48b3bec
Merge branch 'logs-v2-search' of github.com:unkeyed/unkey into logs-v…
ogzhanolguncu Jan 13, 2025
bd6d6cb
fix: build issue
ogzhanolguncu Jan 13, 2025
55f8301
fix: build error
ogzhanolguncu Jan 13, 2025
e0e4884
Merge branch 'main' into logs-v2-search
ogzhanolguncu Jan 14, 2025
bc967e3
feat: give preselected ai queries for users
ogzhanolguncu Jan 14, 2025
ffbd76a
refactor: common functions into a hook
ogzhanolguncu Jan 14, 2025
1a6120e
refactor: checkbox component and selection logic
ogzhanolguncu Jan 14, 2025
cff30d0
refactor: allow easier filter navigation
ogzhanolguncu Jan 14, 2025
8d4c067
refactor: add full keyboard navigation for selected filters
ogzhanolguncu Jan 14, 2025
628b3bc
fix: key creation and default prefix assignment
ogzhanolguncu Jan 14, 2025
1b3bb2b
Merge branch 'main' into fix-key-creation-and-default-prefix
ogzhanolguncu Jan 14, 2025
017234b
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 14, 2025
494ed95
fix: PR comments
ogzhanolguncu Jan 14, 2025
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
45 changes: 45 additions & 0 deletions apps/api/src/routes/v1_keys_createKey.happy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { eq, schema } from "@unkey/db";
import { newId } from "@unkey/id";
import { IntegrationHarness } from "src/pkg/testutil/integration-harness";

import { KeyV1 } from "@unkey/keys";
import type { V1KeysCreateKeyRequest, V1KeysCreateKeyResponse } from "./v1_keys_createKey";

test("creates key", async (t) => {
Expand Down Expand Up @@ -34,6 +35,50 @@ test("creates key", async (t) => {
expect(found!.hash).toEqual(await sha256(res.body.key));
});

test("creates key with default prefix and bytes from keyAuth", async (t) => {
const expectedPrefix = "_prefix";
const expectedBytes = 66;

const h = await IntegrationHarness.init(t);
const root = await h.createRootKey([`api.${h.resources.userApi.id}.create_key`]);

await h.db.primary
.update(schema.keyAuth)
.set({
defaultPrefix: expectedPrefix,
defaultBytes: expectedBytes,
})
.where(eq(schema.keyAuth.id, h.resources.userKeyAuth.id));

// Make the request without specifying prefix or byteLength
const res = await h.post<V1KeysCreateKeyRequest, V1KeysCreateKeyResponse>({
url: "/v1/keys.createKey",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${root.key}`,
},
body: {
apiId: h.resources.userApi.id,
enabled: true,
},
});

expect(res.status, `expected 200, received: ${JSON.stringify(res, null, 2)}`).toBe(200);

const found = await h.db.primary.query.keys.findFirst({
where: (table, { eq }) => eq(table.id, res.body.keyId),
});

const referenceKey = new KeyV1({
byteLength: expectedBytes,
prefix: expectedPrefix,
}).toString();

expect(found).toBeDefined();
expect(found!.start).toEqual(referenceKey.slice(0, 5));
expect(found!.hash).toEqual(await sha256(res.body.key));
});

describe("with enabled flag", () => {
describe("not set", () => {
test("should still create an enabled key", async (t) => {
Expand Down
7 changes: 5 additions & 2 deletions apps/api/src/routes/v1_keys_createKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const registerV1KeysCreateKey = (app: App) =>
})) ?? null
);
});

if (err) {
throw new UnkeyApiError({
code: "INTERNAL_SERVER_ERROR",
Expand Down Expand Up @@ -350,10 +351,12 @@ export const registerV1KeysCreateKey = (app: App) =>
apiId: api.id,
});
}

const secret = new KeyV1({
byteLength: req.byteLength ?? 16,
prefix: req.prefix,
byteLength: req.byteLength ?? api.keyAuth?.defaultBytes ?? 16,
prefix: req.prefix ?? (api.keyAuth?.defaultPrefix as string | undefined),
}).toString();

const start = secret.slice(0, (req.prefix?.length ?? 0) + 5);
const kId = newId("key");
const hash = await sha256(secret.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ export const CreateKey = ({ apiId, keyAuthId, defaultBytes, defaultPrefix }: Pro
});

async function onSubmit(values: z.infer<typeof formSchema>) {
if (values.limit?.refill?.interval !== "none" && !values.limit?.refill?.amount) {
if (
values.limitEnabled &&
values.limit?.refill?.interval !== "none" &&
!values.limit?.refill?.amount
) {
form.setError("limit.refill.amount", {
type: "manual",
message: "Please enter a value if interval is selected",
});
return;
}

if (!values.expireEnabled) {
delete values.expires;
}
Expand Down