lmsqueezy/lemonsqueezy.js

Add clearer docs for set up

Closed this issue · 2 comments

Is this the expected usage in v2? Would be nice to show a simple example in the README with the new setup function.

import { env } from "@/env.mjs";
import { lemonSqueezySetup, updateSubscriptionItem } from "@lemonsqueezy/lemonsqueezy.js";

function setUpLemon() {
  if (!env.LEMON_SQUEEZY_API_KEY) return;
  lemonSqueezySetup({apiKey: env.LEMON_SQUEEZY_API_KEY });
}

export async function updateSubscriptionItemQuantity(options: {
  id: number;
  quantity: number;
}) {
  setUpLemon();
  return updateSubscriptionItem(options.id, options.quantity);
}

Hi, @elie222.

Just call the lemonSqueezySetup function once before using any of the functions.

import { env } from "@/env.mjs";
import { lemonSqueezySetup, updateSubscriptionItem } from "@lemonsqueezy/lemonsqueezy.js";

lemonSqueezySetup({apiKey: env.LEMON_SQUEEZY_API_KEY });

export async function updateSubscriptionItemQuantity(options: {
  id: number;
  quantity: number;
}) {
  return updateSubscriptionItem(options.id, options.quantity);
}

I hope this helps.

Also, the updateSubscriptionItem function will have a break change in the future because the official API added two new parameters. I have to admit that this was a design error on my part. Please stay tuned for the next new version.