* Filter out metered line items from billing schema This update refines the process of creating a billing schema by filtering out metered line items. The change is necessary as metered line items can be shared across different plans, potentially causing conflicts or duplicates in the schema. * Update packages to newer versions This update upgrades several packages across multiple project files to their latest version. These packages include "supabase-js", "react-query", "react-hook-form", and "pnpm". The commit ensures the project is up-to-date with recent package versions, potentially benefiting from bug fixes, new features, and performance improvements. * Add subscription retrieval in billing services Added a function to retrieve subscription info in both Stripe and LemonSqueezy billing services. To accomplish this, new methods were added to related services and types. This allows querying specific subscription data based on its id, and throws an error if it fails. Furthermore, PayloadBuilder classes were created to systematically build the subscription payload. * Remove account ID retrieval from Lemon Squeezy billing service The code that was querying the database to fetch the accountId has been removed from lemon-squeezy-billing-strategy.service.ts. It was unnecessary as the Lemon Squeezy API does not provide account ID and therefore it is always left empty. Also, adjustments have been made in billing-strategy-provider.service.ts to reflect that the target account ID can be optional. * Extract 'next' parameter from callback URL The update allows for the extraction of the 'next' parameter from the callback URL. If such a parameter is available, it is subsequently added to the search parameters. The enhancement improves URL parameter handling in the authentication callback service. * Refactor URL redirection in auth-callback service The update simplifies the redirection logic in the authentication callback service. This is achieved by setting the url pathname directly to the redirect path, instead of first setting it to the callback parameter. Moreover, the code handling the 'next' path has also been streamlined, setting the url pathname to the next path when available.
Next.js Utilities / @kit/next
This package provides utilities for working with Next.js.
Server Actions
The enhanceAction function allows you to wrap a Next.js Server Action with additional functionality.
import { enhanceAction } from '@kit/next/actions';
export const myServerAction = enhanceAction(async (data, user) => {
// "data" has been parsed with the schema
// and will correctly be typed as the schema type
// in the case below, data will be of type { id: number }
// "user" is the user object from the session
// if "captcha" is true, the action will require a captcha
}, {
captcha: true,
schema: z.object({
id: z.number()
}),
});
The enhanceAction function takes two arguments:
- The action function
- An options object
The options object can contain the following properties:
captcha- If true, the action will require a captcha to be passed to the body ascaptchaTokenschema- A zod schema that the data will be validated againstcaptureException- If true, the action will capture exceptions and report them to the configured provider. It istrueby default.
When successfully called, the action will return the result of the action function.
- The user will be automatically authenticated and the result will be passed as the second argument to the action function.
- The data will be parsed/validated with the schema and passed as the first argument to the action function.
- If the
captchaoption is true, the action will require acaptchaTokento be passed in the body.
The consumer can call the action like so:
import { myServerAction } from 'path/to/myServerAction';
const result = await myServerAction({ id: 1 });
or with an optional captcha token:
import { myServerAction } from 'path/to/myServerAction';
const result = await myServerAction({ id: 1, captchaToken: 'captchaToken' });
Route Handlers
The function enhanceRouteHandler allows you to wrap a Next.js API Route Handler with additional functionality.
import { enhanceRouteHandler } from '@kit/next/routes';
export const POST = enhanceRouteHandler(({ request, body, user }) => {
// "body" has been parsed with the schema
// and will correctly be typed as the schema type
// in the case below, data will be of type { id: number }
// "user" is the user object from the session
// "request" is the raw request object passed by POST
// if "captcha" is true, the action will require a captcha
// if "captureException" is true, the action will capture exceptions and report them to the configured provider
}, {
captcha: true,
captureException: true,
schema: z.object({
id: z.number()
}),
});
When using a Captcha, the consumer will pass an header x-captcha-token with the captcha token.