Skip to content

Commit

Permalink
Add links attribute to Variants (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
brankoconjic authored Jun 14, 2024
1 parent a38699c commit 94ebe0a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
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

0 comments on commit 94ebe0a

Please sign in to comment.