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

fix: include exports for non-node environments #118

Merged
merged 1 commit into from
Mar 6, 2025
Merged

Conversation

danbillson
Copy link
Contributor

Related to issue: #117

Includes additional exports for non-node environments, allowing the runtime to pick up the edge build, which has a replacement implementation for node:crypto unavailable in other runtimes.

Usage with nextjs on cloudflare

As we've seen a couple issue with @paddle/paddle-node-sdk and nextjs on cloudflare, here is a usage guide:

Import the Paddle class from @paddle/paddle-node-sdk in the API route and create the instance in the route handler

// app/api/webhook/route.ts

export const runtime = "edge";

import {
  Environment,
  LogLevel,
  Paddle,
  PaddleOptions,
} from "@paddle/paddle-node-sdk";
import { NextRequest } from "next/server";

const paddleOptions: PaddleOptions = {
  environment:
    (process.env.NEXT_PUBLIC_PADDLE_ENV as Environment) ?? Environment.sandbox,
  logLevel: LogLevel.error,
};

export async function GET(request: NextRequest) {
  const paddle = new Paddle(process.env.PADDLE_API_KEY!, paddleOptions);

  return Response.json({ paddle, success: true });
}

Note: This will not work if you create a separate utility outside of the API route i.e. a getPaddleInstance utility as it will try and use the node runtime

@danbillson danbillson requested a review from samcolby March 6, 2025 11:00
@danbillson danbillson self-assigned this Mar 6, 2025
@danbillson danbillson requested a review from a team as a code owner March 6, 2025 11:01
@danbillson danbillson requested a review from vifer March 6, 2025 11:09
@danbillson danbillson merged commit 63ef366 into main Mar 6, 2025
6 of 7 checks passed
@danbillson danbillson deleted the worker-builds branch March 6, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants