-
Notifications
You must be signed in to change notification settings - Fork 189
BigSet Add-on for Google Sheets #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MabudAlam
wants to merge
13
commits into
tinyfish-io:main
Choose a base branch
from
MabudAlam:sheet-addon
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a6d4815
Addon init
MabudAlam 52e540f
Refactor code structure for improved readability and maintainability
MabudAlam bd6eb37
First working Dataset insertion
MabudAlam 1af072a
Added the my datasets and public datasets tab
MabudAlam 604bf60
Added Saved Dataset Detail view and minor improvements
MabudAlam f487aef
Implemented Dataset enrichment
MabudAlam 7f68dd4
Refactoring and fixes
MabudAlam a45ae72
Fixed bugs
MabudAlam 5f10706
Format the dataset name
MabudAlam 10e09e8
Fix the Column name and description formating on addon
MabudAlam d7e2a53
Merge branch 'main' into sheet-addon
MabudAlam 099b57c
Merge branch 'main' into sheet-addon
MabudAlam 2ceae68
Merge branch 'main' into sheet-addon
MabudAlam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,90 @@ | ||
| import { createHash, randomBytes } from "node:crypto"; | ||
| import type { FastifyReply, FastifyRequest } from "fastify"; | ||
|
|
||
| import { env } from "./env.js"; | ||
| import { convex, internal } from "./convex.js"; | ||
| import { LOCAL_USER_ID } from "./local-credentials.js"; | ||
|
|
||
| const KEY_PREFIX_LEN = 8; | ||
|
|
||
| function hashKey(key: string): string { | ||
| return createHash("sha256").update(key).digest("hex"); | ||
| } | ||
|
|
||
| export function generateApiKey(): { key: string; keyHash: string; keyPrefix: string } { | ||
| const random = randomBytes(32).toString("base64url"); | ||
| const key = `bsk_${random}`; | ||
| const keyHash = hashKey(key); | ||
| const keyPrefix = key.slice(0, KEY_PREFIX_LEN); | ||
| return { key, keyHash, keyPrefix }; | ||
| } | ||
|
|
||
| export function apiKeyHash(key: string): string { | ||
| return hashKey(key); | ||
| } | ||
|
|
||
| export async function requireApiKey( | ||
| req: FastifyRequest, | ||
| reply: FastifyReply, | ||
| ): Promise<boolean> { | ||
| const header = req.headers["x-api-key"]; | ||
| const authHeader = req.headers.authorization; | ||
| let rawKey: string | undefined; | ||
| if (typeof header === "string" && header.startsWith("bsk_")) { | ||
| rawKey = header; | ||
| } else if (typeof authHeader === "string" && authHeader.startsWith("Bearer bsk_")) { | ||
| rawKey = authHeader.slice("Bearer ".length); | ||
| } | ||
| if (!rawKey) return false; | ||
|
|
||
| const keyHash = hashKey(rawKey); | ||
| const record = await convex.query(internal.apiKeys.lookupByHash, { keyHash }); | ||
| if (!record) { | ||
| await reply.code(401).send({ error: "Invalid API key" }); | ||
| return true; | ||
| } | ||
|
|
||
| req.auth = { userId: record.ownerId }; | ||
|
|
||
| void convex | ||
| .mutation(internal.apiKeys.touchLastUsed, { | ||
| id: record._id, | ||
| lastUsedAt: Date.now(), | ||
| }) | ||
| .catch(() => {}); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Try API-key auth. Returns: | ||
| * - `true` if the request had an X-API-Key / Bearer bsk_… header | ||
| * (either the key was accepted and req.auth is set, or the response | ||
| * was already sent with 401). Caller must NOT continue. | ||
| * - `false` if no API key was presented. Caller should fall through | ||
| * to Clerk (or whatever its next auth mechanism is). | ||
| */ | ||
| export async function tryApiKeyAuth( | ||
| req: FastifyRequest, | ||
| reply: FastifyReply, | ||
| ): Promise<boolean> { | ||
| const header = req.headers["x-api-key"]; | ||
| const authHeader = req.headers.authorization; | ||
| const hasKey = | ||
| (typeof header === "string" && header.startsWith("bsk_")) || | ||
| (typeof authHeader === "string" && authHeader.startsWith("Bearer bsk_")); | ||
| if (!hasKey) return false; | ||
| await requireApiKey(req, reply); | ||
| return true; | ||
| } | ||
|
|
||
| export async function requireApiKeyOrCli( | ||
| req: FastifyRequest, | ||
| reply: FastifyReply, | ||
| ): Promise<boolean> { | ||
| if (env.IS_LOCAL_MODE) { | ||
| req.auth = { userId: LOCAL_USER_ID }; | ||
| return true; | ||
| } | ||
| return requireApiKey(req, reply); | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.