Skip to content
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

Update template to use D1 #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update template to use D1 #3

wants to merge 1 commit into from

Conversation

triozer
Copy link
Member

@triozer triozer commented Jan 7, 2025

Context

See https://github.com/framer/company/issues/31205.

What was done

This pull request introduces several significant changes, focusing on migrating from Cloudflare KV to D1 database, refactoring the OAuth flow, updating dependencies, and enhancing the HTML template.

Database Migration (KV to D1):

  • Replaced Cloudflare KV storage with D1 database for improved query capabilities and better data management
  • src/schema.sql: Added a new table key_values to store key-value pairs, which supports the new OAuth flow implementation.

Refactoring OAuth Flow:

  • src/index.ts: Refactored the OAuth flow by delegating the authorization, redirection, polling, and token refreshing logic to the new provider module. This modularization simplifies the main request handler.
  • src/provider.ts: Added new functions (authorize, redirect, poll, refresh) to handle different parts of the OAuth flow, improving code organization and readability.

Updating Dependencies:

  • package.json: Updated several dependencies to their latest versions, including @cloudflare/vitest-pool-workers, @cloudflare/workers-types, typescript, and vitest. This ensures compatibility with the latest features and security patches.

Enhancing HTML Template:

  • src/getHTMLTemplate.ts: Enhanced the getHTMLTemplate function to accept title and message parameters and updated the HTML structure and styles for better user experience.

Configuration and Documentation Updates:

  • .dev.vars.example: Moved the PLUGIN_ID variable to a more appropriate location in the file.
  • README.md: Added instructions for installing mkcert, creating development certificates, and seeding the local database to improve the setup process for local development.

QA

  • Follow the README
  • To run against this branch use: npm create cloudflare@latest -- --template framer/plugin-oauth#feature/use-d1

@triozer triozer force-pushed the feature/use-d1 branch 2 times, most recently from f81d41a to 082a058 Compare January 7, 2025 15:56
@triozer triozer requested a review from huntercaron January 7, 2025 15:57
- Add bootstrap command

Signed-off-by: Cédric Boirard <cedric@framer.com>
@triozer triozer requested a review from niekert January 10, 2025 10:29
@tom-james-watson tom-james-watson requested review from tom-james-watson and removed request for niekert January 14, 2025 18:12
Copy link

@tom-james-watson tom-james-watson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me, though I don't really have any context on why this change is needed?

@triozer
Copy link
Member Author

triozer commented Jan 15, 2025

The main idea was to move to D1 because it offers faster reads (https://github.com/framer/FramerPluginWorkers/pull/32). And as this is supposed to be a template for building OAuth Workers, I tried to simplify it so that we only need to update the provider.ts file!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants