diff --git a/example/convex/_generated/api.d.ts b/example/convex/_generated/api.d.ts index 0db7822..9ef6925 100644 --- a/example/convex/_generated/api.d.ts +++ b/example/convex/_generated/api.d.ts @@ -49,5 +49,5 @@ export declare const internal: FilterApi< >; export declare const components: { - stripe: import("@convex/stripe/_generated/component.js").ComponentApi<"stripe">; + stripe: import("@convex-dev/stripe/_generated/component.js").ComponentApi<"stripe">; }; diff --git a/example/convex/convex.config.ts b/example/convex/convex.config.ts index f4a13bd..e4f4aed 100644 --- a/example/convex/convex.config.ts +++ b/example/convex/convex.config.ts @@ -1,5 +1,5 @@ import { defineApp } from "convex/server"; -import stripe from "@convex/stripe/convex.config.js"; +import stripe from "@convex-dev/stripe/convex.config.js"; const app = defineApp(); app.use(stripe); diff --git a/example/convex/http.ts b/example/convex/http.ts index bdbc0be..9ee9993 100644 --- a/example/convex/http.ts +++ b/example/convex/http.ts @@ -1,7 +1,6 @@ import { httpRouter } from "convex/server"; -import type Stripe from "stripe"; import { components } from "./_generated/api"; -import { registerRoutes } from "@convex/stripe"; +import { registerRoutes } from "@convex-dev/stripe"; const http = httpRouter(); @@ -10,10 +9,7 @@ const http = httpRouter(); registerRoutes(http, components.stripe, { webhookPath: "/stripe/webhook", events: { - "customer.subscription.updated": async ( - ctx: any, - event: Stripe.CustomerSubscriptionUpdatedEvent - ) => { + "customer.subscription.updated": async (ctx, event) => { // Example custom handler: Log subscription updates const subscription = event.data.object; console.log("🔔 Custom handler: Subscription updated!", { @@ -24,10 +20,7 @@ registerRoutes(http, components.stripe, { // You can run additional logic here after the default database sync // For example, send a notification, update other tables, etc. }, - "payment_intent.succeeded": async ( - ctx: any, - event: Stripe.PaymentIntentSucceededEvent - ) => { + "payment_intent.succeeded": async (ctx, event) => { // Example custom handler: Log successful one-time payments const paymentIntent = event.data.object; console.log("💰 Custom handler: Payment succeeded!", { @@ -36,7 +29,7 @@ registerRoutes(http, components.stripe, { }); }, }, - onEvent: async (ctx: any, event: Stripe.Event) => { + onEvent: async (ctx, event) => { // Log all events for monitoring/debugging console.log(`📊 Event received: ${event.type}`, { id: event.id, diff --git a/example/convex/stripe.ts b/example/convex/stripe.ts index c41126a..283f1f8 100644 --- a/example/convex/stripe.ts +++ b/example/convex/stripe.ts @@ -1,13 +1,13 @@ /** * Benji's Store - Stripe Integration - * - * This file demonstrates how to use the @convex/stripe component + * + * This file demonstrates how to use the @convex-dev/stripe component * for handling payments and subscriptions with Clerk authentication. */ import { action, mutation, query } from "./_generated/server"; import { components } from "./_generated/api"; -import { StripeSubscriptions } from "@convex/stripe"; +import { StripeSubscriptions } from "@convex-dev/stripe"; import { v } from "convex/values"; const stripeClient = new StripeSubscriptions(components.stripe, {}); diff --git a/package-lock.json b/package-lock.json index 9a690b9..3d4b284 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@convex/stripe", + "name": "@convex-dev/stripe", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@convex/stripe", + "name": "@convex-dev/stripe", "version": "0.1.0", "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 74de072..bfda6e0 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { - "name": "@convex/stripe", + "name": "@convex-dev/stripe", "description": "A stripe component for Convex.", - "repository": "github:michaelshimeles", - "homepage": "https://github.com/michaelshimeles#readme", + "repository": "github:get-convex/stripe", + "homepage": "https://github.com/get-convex/stripe#readme", "bugs": { - "url": "https://github.com/michaelshimeles/issues" + "url": "https://github.com/get-convex/stripe/issues" }, "version": "0.1.0", "license": "Apache-2.0", diff --git a/src/client/index.ts b/src/client/index.ts index 897c42f..b9f4a4c 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -333,10 +333,10 @@ export class StripeSubscriptions { * export default http; * ``` */ -export function registerRoutes( +export function registerRoutes( http: HttpRouter, component: ComponentApi, - config?: RegisterRoutesConfig + config?: RegisterRoutesConfig, ) { const webhookPath = config?.webhookPath ?? "/stripe/webhook"; const eventHandlers = config?.events ?? {}; diff --git a/src/client/types.ts b/src/client/types.ts index a6b7d9a..68b2284 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -1,78 +1,78 @@ import type { - HttpRouter, - GenericActionCtx, - GenericMutationCtx, - GenericDataModel, - GenericQueryCtx, - } from "convex/server"; - import type Stripe from "stripe"; - - // Type utils follow - - export type QueryCtx = Pick, "runQuery">; - export type MutationCtx = Pick< - GenericMutationCtx, - "runQuery" | "runMutation" - >; - export type ActionCtx = Pick< - GenericActionCtx, - "runQuery" | "runMutation" | "runAction" - >; - - // Webhook Event Handler Types - + HttpRouter, + GenericActionCtx, + GenericMutationCtx, + GenericDataModel, + GenericQueryCtx, +} from "convex/server"; +import type Stripe from "stripe"; + +// Type utils follow + +export type QueryCtx = Pick, "runQuery">; +export type MutationCtx = Pick< + GenericMutationCtx, + "runQuery" | "runMutation" +>; +export type ActionCtx = Pick< + GenericActionCtx, + "runQuery" | "runMutation" | "runAction" +>; + +// Webhook Event Handler Types + +/** + * Handler function for a specific Stripe webhook event. + * Receives the mutation context and the full Stripe event object. + */ +export type StripeEventHandler< + Ctx extends ActionCtx = ActionCtx, + T extends Stripe.Event.Type = Stripe.Event.Type, +> = (ctx: Ctx, event: Stripe.Event & { type: T }) => Promise; + +/** + * Map of event types to their handlers. + * Users can provide handlers for any Stripe webhook event type. + */ +export type StripeEventHandlers = { + [K in Stripe.Event.Type]?: StripeEventHandler; +}; + +/** + * Configuration for webhook registration. + */ +export type RegisterRoutesConfig = { /** - * Handler function for a specific Stripe webhook event. - * Receives the mutation context and the full Stripe event object. + * Optional webhook path. Defaults to "/stripe/webhook" */ - export type StripeEventHandler< - T extends Stripe.Event.Type = Stripe.Event.Type, - > = (ctx: ActionCtx, event: Stripe.Event & { type: T }) => Promise; - + webhookPath?: string; + /** - * Map of event types to their handlers. - * Users can provide handlers for any Stripe webhook event type. + * Optional event handlers that run after default processing. + * The component will handle database syncing automatically, + * and then call your custom handlers. */ - export type StripeEventHandlers = { - [K in Stripe.Event.Type]?: StripeEventHandler; - }; - + events?: StripeEventHandlers; + /** - * Configuration for webhook registration. + * Optional generic event handler that runs for all events. + * This runs after default processing and before specific event handlers. */ - export type RegisterRoutesConfig = { - /** - * Optional webhook path. Defaults to "/stripe/webhook" - */ - webhookPath?: string; - - /** - * Optional event handlers that run after default processing. - * The component will handle database syncing automatically, - * and then call your custom handlers. - */ - events?: StripeEventHandlers; - - /** - * Optional generic event handler that runs for all events. - * This runs after default processing and before specific event handlers. - */ - onEvent?: StripeEventHandler; - /** - * Stripe webhook secret for signature verification. - * Defaults to process.env.STRIPE_WEBHOOK_SECRET - */ - STRIPE_WEBHOOK_SECRET?: string; - - /** - * Stripe secret key for API calls. - * Defaults to process.env.STRIPE_SECRET_KEY - */ - STRIPE_SECRET_KEY?: string; - }; - + onEvent?: StripeEventHandler; /** - * Type for the HttpRouter to be used in registerRoutes + * Stripe webhook secret for signature verification. + * Defaults to process.env.STRIPE_WEBHOOK_SECRET */ - export type { HttpRouter }; - \ No newline at end of file + STRIPE_WEBHOOK_SECRET?: string; + + /** + * Stripe secret key for API calls. + * Defaults to process.env.STRIPE_SECRET_KEY + */ + STRIPE_SECRET_KEY?: string; +}; + +/** + * Type for the HttpRouter to be used in registerRoutes + */ +export type { HttpRouter };