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

Add links attribute to Variants #103

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-kings-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/lemonsqueezy.js": minor
---

Add `links` attribute to Variants
7 changes: 3 additions & 4 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAuthenticatedUser, lemonSqueezySetup } from "../src/index.js";
import { lemonSqueezySetup, listVariants } from "../src/index.js";

const apiKey = import.meta.env.LEMON_SQUEEZY_API_KEY;

Expand All @@ -9,11 +9,10 @@ lemonSqueezySetup({
});

// Get authenticated user
const { data, error, statusCode } = await getAuthenticatedUser();
const { data, error } = await listVariants();

if (error) {
console.log(error.cause);
} else {
console.log({ data, error, statusCode });
console.log(data.data.attributes.email);
console.log(JSON.stringify({ data: data.data }, null, 2));
}
17 changes: 17 additions & 0 deletions src/variants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ type Attributes = {
* Note: If the variant is a subscription, the license key expiration will be linked to the status of the subscription (e.g. the license will expire when the subscription expires).
*/
is_license_length_unlimited: boolean;
/**
* An array of the link objects.
* `title` – The title of the link
* `url` – The URL of the link
*
* @see {@link https://docs.lemonsqueezy.com/help/products/adding-products#links}
*/
links: Array<{
/**
* The title of the link
*/
title: string;
/**
* The URL of the link
*/
url: string;
}>;
/**
* An integer representing the order of this variant when displayed on the checkout.
*/
Expand Down
12 changes: 8 additions & 4 deletions test/variants/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ describe("Retrieve a variant", () => {
expect(error).toBeNull();
expect(_data).toBeDefined();

const { links, data } = _data!;
expect(links.self).toEqual(`${API_BASE_URL}${PATH}${variantId}`);
const { links: dataLinks, data } = _data!;
expect(dataLinks.self).toEqual(`${API_BASE_URL}${PATH}${variantId}`);
expect(data).toBeDefined();

const { id, type, attributes, relationships } = data;
Expand All @@ -170,6 +170,7 @@ describe("Retrieve a variant", () => {
name,
slug,
description,
links,
has_license_keys,
license_activation_limit,
is_license_limit_unlimited,
Expand Down Expand Up @@ -200,6 +201,7 @@ describe("Retrieve a variant", () => {
name,
slug,
description,
links,
has_license_keys,
license_activation_limit,
is_license_limit_unlimited,
Expand Down Expand Up @@ -247,8 +249,8 @@ describe("Retrieve a variant", () => {
expect(error).toBeNull();
expect(_data).toBeDefined();

const { links, data, included } = _data!;
expect(links.self).toEqual(`${API_BASE_URL}${PATH}${variantId}`);
const { links: dataLinks, data, included } = _data!;
expect(dataLinks.self).toEqual(`${API_BASE_URL}${PATH}${variantId}`);
expect(data).toBeDefined();
expect(included).toBeArray();
expect(!!included?.filter((item) => item.type === "products")).toBeTrue();
Expand All @@ -265,6 +267,7 @@ describe("Retrieve a variant", () => {
slug,
description,
has_license_keys,
links,
license_activation_limit,
is_license_limit_unlimited,
license_length_value,
Expand Down Expand Up @@ -294,6 +297,7 @@ describe("Retrieve a variant", () => {
name,
slug,
description,
links,
has_license_keys,
license_activation_limit,
is_license_limit_unlimited,
Expand Down