diff --git a/.changeset/curvy-kings-drum.md b/.changeset/curvy-kings-drum.md new file mode 100644 index 0000000..554cfca --- /dev/null +++ b/.changeset/curvy-kings-drum.md @@ -0,0 +1,5 @@ +--- +"@lemonsqueezy/lemonsqueezy.js": minor +--- + +Add `links` attribute to Variants diff --git a/examples/index.ts b/examples/index.ts index 8e5dda2..e6385e5 100644 --- a/examples/index.ts +++ b/examples/index.ts @@ -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; @@ -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)); } diff --git a/src/variants/types.ts b/src/variants/types.ts index 0560de9..3ed9a4c 100644 --- a/src/variants/types.ts +++ b/src/variants/types.ts @@ -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. */ diff --git a/test/variants/index.test.ts b/test/variants/index.test.ts index 648a721..d4be19a 100644 --- a/test/variants/index.test.ts +++ b/test/variants/index.test.ts @@ -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; @@ -170,6 +170,7 @@ describe("Retrieve a variant", () => { name, slug, description, + links, has_license_keys, license_activation_limit, is_license_limit_unlimited, @@ -200,6 +201,7 @@ describe("Retrieve a variant", () => { name, slug, description, + links, has_license_keys, license_activation_limit, is_license_limit_unlimited, @@ -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(); @@ -265,6 +267,7 @@ describe("Retrieve a variant", () => { slug, description, has_license_keys, + links, license_activation_limit, is_license_limit_unlimited, license_length_value, @@ -294,6 +297,7 @@ describe("Retrieve a variant", () => { name, slug, description, + links, has_license_keys, license_activation_limit, is_license_limit_unlimited,