forked from mendableai/firecrawl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mendableai#132 from mendableai/feat/idempotency-key
[Feat] Added idempotency key to crawl route
- Loading branch information
Showing
13 changed files
with
150 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Request } from "express"; | ||
import { supabase_service } from "../supabase"; | ||
|
||
export async function createIdempotencyKey( | ||
req: Request, | ||
): Promise<string> { | ||
const idempotencyKey = req.headers['x-idempotency-key'] as string; | ||
if (!idempotencyKey) { | ||
throw new Error("No idempotency key provided in the request headers."); | ||
} | ||
|
||
const { data, error } = await supabase_service | ||
.from("idempotency_keys") | ||
.insert({ key: idempotencyKey }); | ||
|
||
if (error) { | ||
console.error("Failed to create idempotency key:", error); | ||
throw error; | ||
} | ||
|
||
return idempotencyKey; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Request } from "express"; | ||
import { supabase_service } from "../supabase"; | ||
import { validate as isUuid } from 'uuid'; | ||
|
||
export async function validateIdempotencyKey( | ||
req: Request, | ||
): Promise<boolean> { | ||
const idempotencyKey = req.headers['x-idempotency-key']; | ||
if (!idempotencyKey) { | ||
// // not returning for missing idempotency key for now | ||
return true; | ||
} | ||
if (!isUuid(idempotencyKey)) { | ||
console.error("Invalid idempotency key provided in the request headers."); | ||
return false; | ||
} | ||
|
||
const { data, error } = await supabase_service | ||
.from("idempotency_keys") | ||
.select("key") | ||
.eq("key", idempotencyKey); | ||
|
||
if (error) { | ||
console.error(error); | ||
} | ||
|
||
if (!data || data.length === 0) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters