@yawlabs/lemonsqueezy-mcp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +146 -281
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -21013,6 +21013,26 @@ var StdioServerTransport = class {
21013
21013
  // src/api.ts
21014
21014
  var BASE_URL = "https://api.lemonsqueezy.com/v1";
21015
21015
  var REQUEST_TIMEOUT_MS = 3e4;
21016
+ var DEFAULT_RETRY_WAIT_MS = 1e3;
21017
+ var MAX_RETRY_WAIT_MS = 3e4;
21018
+ function parseRetryAfterMs(header) {
21019
+ if (!header) return DEFAULT_RETRY_WAIT_MS;
21020
+ const trimmed = header.trim();
21021
+ const seconds = Number(trimmed);
21022
+ if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
21023
+ const dateMs = Date.parse(trimmed);
21024
+ if (Number.isFinite(dateMs)) return Math.max(0, dateMs - Date.now());
21025
+ return DEFAULT_RETRY_WAIT_MS;
21026
+ }
21027
+ async function fetchWithRetry(url, init) {
21028
+ const makeCall = () => fetch(url, { ...init, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
21029
+ const res = await makeCall();
21030
+ if (res.status !== 429) return res;
21031
+ const waitMs = parseRetryAfterMs(res.headers.get("retry-after"));
21032
+ if (waitMs > MAX_RETRY_WAIT_MS) return res;
21033
+ await new Promise((resolve) => setTimeout(resolve, waitMs));
21034
+ return makeCall();
21035
+ }
21016
21036
  function getApiKey() {
21017
21037
  const key = process.env.LEMONSQUEEZY_API_KEY;
21018
21038
  if (!key) {
@@ -21057,12 +21077,7 @@ async function apiRequest(method, path, body) {
21057
21077
  const url = path.startsWith("http") ? path : `${BASE_URL}${path}`;
21058
21078
  let res;
21059
21079
  try {
21060
- res = await fetch(url, {
21061
- method,
21062
- headers,
21063
- body: fetchBody,
21064
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
21065
- });
21080
+ res = await fetchWithRetry(url, { method, headers, body: fetchBody });
21066
21081
  } catch (err) {
21067
21082
  if (err instanceof Error && err.name === "TimeoutError") {
21068
21083
  return { ok: false, status: 0, error: `Request timed out after ${REQUEST_TIMEOUT_MS / 1e3}s` };
@@ -21078,7 +21093,7 @@ async function apiRequest(method, path, body) {
21078
21093
  return { ok: false, status: res.status, error: errorBody };
21079
21094
  }
21080
21095
  }
21081
- if (res.status === 204 || res.headers.get("content-length") === "0") {
21096
+ if (res.status === 204) {
21082
21097
  return { ok: true, status: res.status };
21083
21098
  }
21084
21099
  const data = await res.json();
@@ -21088,14 +21103,13 @@ async function licenseRequest(path, body) {
21088
21103
  const url = `${BASE_URL}${path}`;
21089
21104
  let res;
21090
21105
  try {
21091
- res = await fetch(url, {
21106
+ res = await fetchWithRetry(url, {
21092
21107
  method: "POST",
21093
21108
  headers: {
21094
21109
  Accept: "application/json",
21095
21110
  "Content-Type": "application/x-www-form-urlencoded"
21096
21111
  },
21097
- body: new URLSearchParams(body),
21098
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
21112
+ body: new URLSearchParams(body)
21099
21113
  });
21100
21114
  } catch (err) {
21101
21115
  if (err instanceof Error && err.name === "TimeoutError") {
@@ -21107,7 +21121,12 @@ async function licenseRequest(path, body) {
21107
21121
  const errorBody = await res.text();
21108
21122
  try {
21109
21123
  const parsed = JSON.parse(errorBody);
21110
- return { ok: false, status: res.status, data: parsed, error: parsed.error ?? errorBody };
21124
+ return {
21125
+ ok: false,
21126
+ status: res.status,
21127
+ data: parsed,
21128
+ error: parsed.errors?.[0]?.detail ?? parsed.error ?? errorBody
21129
+ };
21111
21130
  } catch {
21112
21131
  return { ok: false, status: res.status, error: errorBody };
21113
21132
  }
@@ -21115,6 +21134,27 @@ async function licenseRequest(path, body) {
21115
21134
  const data = await res.json();
21116
21135
  return { ok: true, status: res.status, data };
21117
21136
  }
21137
+ function getHandler(endpoint, idField) {
21138
+ return async (input) => {
21139
+ const query = buildQuery({ include: input.include?.split(",") });
21140
+ return apiGet(`${endpoint}/${input[idField]}${query}`);
21141
+ };
21142
+ }
21143
+ function listHandler(endpoint, filterMap = {}) {
21144
+ return async (input) => {
21145
+ const filter = {};
21146
+ for (const [inputKey, apiKey] of Object.entries(filterMap)) {
21147
+ const val = input[inputKey];
21148
+ if (val !== void 0) filter[apiKey] = String(val);
21149
+ }
21150
+ const query = buildQuery({
21151
+ include: input.include?.split(","),
21152
+ filter,
21153
+ page: { number: input.pageNumber, size: input.pageSize }
21154
+ });
21155
+ return apiGet(`${endpoint}${query}`);
21156
+ };
21157
+ }
21118
21158
  async function apiGet(path) {
21119
21159
  return apiRequest("GET", path);
21120
21160
  }
@@ -21128,6 +21168,44 @@ async function apiDelete(path) {
21128
21168
  return apiRequest("DELETE", path);
21129
21169
  }
21130
21170
 
21171
+ // src/tools/affiliates.ts
21172
+ var affiliateTools = [
21173
+ {
21174
+ name: "ls_get_affiliate",
21175
+ description: "Get a specific affiliate by ID, including commission rate, status, and earnings.",
21176
+ annotations: {
21177
+ title: "Get affiliate",
21178
+ readOnlyHint: true,
21179
+ destructiveHint: false,
21180
+ idempotentHint: true,
21181
+ openWorldHint: true
21182
+ },
21183
+ inputSchema: external_exports.object({
21184
+ affiliateId: external_exports.string().describe("The affiliate ID"),
21185
+ include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store,user')")
21186
+ }),
21187
+ handler: getHandler("/affiliates", "affiliateId")
21188
+ },
21189
+ {
21190
+ name: "ls_list_affiliates",
21191
+ description: "List all affiliates for the authenticated user's stores, optionally filtered by user email. Results are paginated \u2014 check meta.page in the response for currentPage, lastPage, and total.",
21192
+ annotations: {
21193
+ title: "List affiliates",
21194
+ readOnlyHint: true,
21195
+ destructiveHint: false,
21196
+ idempotentHint: true,
21197
+ openWorldHint: true
21198
+ },
21199
+ inputSchema: external_exports.object({
21200
+ userEmail: external_exports.string().email().optional().describe("Filter by affiliate's user email"),
21201
+ include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store,user')"),
21202
+ pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21203
+ pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21204
+ }),
21205
+ handler: listHandler("/affiliates", { userEmail: "user_email" })
21206
+ }
21207
+ ];
21208
+
21131
21209
  // src/tools/checkouts.ts
21132
21210
  var checkoutTools = [
21133
21211
  {
@@ -21144,10 +21222,7 @@ var checkoutTools = [
21144
21222
  checkoutId: external_exports.string().describe("The checkout ID"),
21145
21223
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store,variant')")
21146
21224
  }),
21147
- handler: async (input) => {
21148
- const query = buildQuery({ include: input.include?.split(",") });
21149
- return apiGet(`/checkouts/${input.checkoutId}${query}`);
21150
- }
21225
+ handler: getHandler("/checkouts", "checkoutId")
21151
21226
  },
21152
21227
  {
21153
21228
  name: "ls_list_checkouts",
@@ -21166,17 +21241,7 @@ var checkoutTools = [
21166
21241
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21167
21242
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21168
21243
  }),
21169
- handler: async (input) => {
21170
- const filter = {};
21171
- if (input.storeId) filter.store_id = input.storeId;
21172
- if (input.variantId) filter.variant_id = input.variantId;
21173
- const query = buildQuery({
21174
- include: input.include?.split(","),
21175
- filter,
21176
- page: { number: input.pageNumber, size: input.pageSize }
21177
- });
21178
- return apiGet(`/checkouts${query}`);
21179
- }
21244
+ handler: listHandler("/checkouts", { storeId: "store_id", variantId: "variant_id" })
21180
21245
  },
21181
21246
  {
21182
21247
  name: "ls_create_checkout",
@@ -21254,10 +21319,7 @@ var customerTools = [
21254
21319
  customerId: external_exports.string().describe("The customer ID"),
21255
21320
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store,orders,subscriptions,license-keys')")
21256
21321
  }),
21257
- handler: async (input) => {
21258
- const query = buildQuery({ include: input.include?.split(",") });
21259
- return apiGet(`/customers/${input.customerId}${query}`);
21260
- }
21322
+ handler: getHandler("/customers", "customerId")
21261
21323
  },
21262
21324
  {
21263
21325
  name: "ls_list_customers",
@@ -21276,17 +21338,7 @@ var customerTools = [
21276
21338
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21277
21339
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21278
21340
  }),
21279
- handler: async (input) => {
21280
- const filter = {};
21281
- if (input.storeId) filter.store_id = input.storeId;
21282
- if (input.email) filter.email = input.email;
21283
- const query = buildQuery({
21284
- include: input.include?.split(","),
21285
- filter,
21286
- page: { number: input.pageNumber, size: input.pageSize }
21287
- });
21288
- return apiGet(`/customers${query}`);
21289
- }
21341
+ handler: listHandler("/customers", { storeId: "store_id", email: "email" })
21290
21342
  },
21291
21343
  {
21292
21344
  name: "ls_create_customer",
@@ -21402,10 +21454,7 @@ var discountRedemptionTools = [
21402
21454
  discountRedemptionId: external_exports.string().describe("The discount redemption ID"),
21403
21455
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'discount,order')")
21404
21456
  }),
21405
- handler: async (input) => {
21406
- const query = buildQuery({ include: input.include?.split(",") });
21407
- return apiGet(`/discount-redemptions/${input.discountRedemptionId}${query}`);
21408
- }
21457
+ handler: getHandler("/discount-redemptions", "discountRedemptionId")
21409
21458
  },
21410
21459
  {
21411
21460
  name: "ls_list_discount_redemptions",
@@ -21424,17 +21473,7 @@ var discountRedemptionTools = [
21424
21473
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21425
21474
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21426
21475
  }),
21427
- handler: async (input) => {
21428
- const filter = {};
21429
- if (input.discountId) filter.discount_id = input.discountId;
21430
- if (input.orderId) filter.order_id = input.orderId;
21431
- const query = buildQuery({
21432
- include: input.include?.split(","),
21433
- filter,
21434
- page: { number: input.pageNumber, size: input.pageSize }
21435
- });
21436
- return apiGet(`/discount-redemptions${query}`);
21437
- }
21476
+ handler: listHandler("/discount-redemptions", { discountId: "discount_id", orderId: "order_id" })
21438
21477
  }
21439
21478
  ];
21440
21479
 
@@ -21454,10 +21493,7 @@ var discountTools = [
21454
21493
  discountId: external_exports.string().describe("The discount ID"),
21455
21494
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store,variants,discount-redemptions')")
21456
21495
  }),
21457
- handler: async (input) => {
21458
- const query = buildQuery({ include: input.include?.split(",") });
21459
- return apiGet(`/discounts/${input.discountId}${query}`);
21460
- }
21496
+ handler: getHandler("/discounts", "discountId")
21461
21497
  },
21462
21498
  {
21463
21499
  name: "ls_list_discounts",
@@ -21475,16 +21511,7 @@ var discountTools = [
21475
21511
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21476
21512
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21477
21513
  }),
21478
- handler: async (input) => {
21479
- const filter = {};
21480
- if (input.storeId) filter.store_id = input.storeId;
21481
- const query = buildQuery({
21482
- include: input.include?.split(","),
21483
- filter,
21484
- page: { number: input.pageNumber, size: input.pageSize }
21485
- });
21486
- return apiGet(`/discounts${query}`);
21487
- }
21514
+ handler: listHandler("/discounts", { storeId: "store_id" })
21488
21515
  },
21489
21516
  {
21490
21517
  name: "ls_create_discount",
@@ -21579,10 +21606,7 @@ var fileTools = [
21579
21606
  fileId: external_exports.string().describe("The file ID"),
21580
21607
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'variant')")
21581
21608
  }),
21582
- handler: async (input) => {
21583
- const query = buildQuery({ include: input.include?.split(",") });
21584
- return apiGet(`/files/${input.fileId}${query}`);
21585
- }
21609
+ handler: getHandler("/files", "fileId")
21586
21610
  },
21587
21611
  {
21588
21612
  name: "ls_list_files",
@@ -21600,16 +21624,7 @@ var fileTools = [
21600
21624
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21601
21625
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21602
21626
  }),
21603
- handler: async (input) => {
21604
- const filter = {};
21605
- if (input.variantId) filter.variant_id = input.variantId;
21606
- const query = buildQuery({
21607
- include: input.include?.split(","),
21608
- filter,
21609
- page: { number: input.pageNumber, size: input.pageSize }
21610
- });
21611
- return apiGet(`/files${query}`);
21612
- }
21627
+ handler: listHandler("/files", { variantId: "variant_id" })
21613
21628
  }
21614
21629
  ];
21615
21630
 
@@ -21629,10 +21644,7 @@ var licenseKeyInstanceTools = [
21629
21644
  licenseKeyInstanceId: external_exports.string().describe("The license key instance ID"),
21630
21645
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'license-key')")
21631
21646
  }),
21632
- handler: async (input) => {
21633
- const query = buildQuery({ include: input.include?.split(",") });
21634
- return apiGet(`/license-key-instances/${input.licenseKeyInstanceId}${query}`);
21635
- }
21647
+ handler: getHandler("/license-key-instances", "licenseKeyInstanceId")
21636
21648
  },
21637
21649
  {
21638
21650
  name: "ls_list_license_key_instances",
@@ -21650,16 +21662,7 @@ var licenseKeyInstanceTools = [
21650
21662
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21651
21663
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21652
21664
  }),
21653
- handler: async (input) => {
21654
- const filter = {};
21655
- if (input.licenseKeyId) filter.license_key_id = input.licenseKeyId;
21656
- const query = buildQuery({
21657
- include: input.include?.split(","),
21658
- filter,
21659
- page: { number: input.pageNumber, size: input.pageSize }
21660
- });
21661
- return apiGet(`/license-key-instances${query}`);
21662
- }
21665
+ handler: listHandler("/license-key-instances", { licenseKeyId: "license_key_id" })
21663
21666
  }
21664
21667
  ];
21665
21668
 
@@ -21681,10 +21684,7 @@ var licenseKeyTools = [
21681
21684
  "Comma-separated related resources to include (e.g. 'store,customer,order,order-item,product,license-key-instances')"
21682
21685
  )
21683
21686
  }),
21684
- handler: async (input) => {
21685
- const query = buildQuery({ include: input.include?.split(",") });
21686
- return apiGet(`/license-keys/${input.licenseKeyId}${query}`);
21687
- }
21687
+ handler: getHandler("/license-keys", "licenseKeyId")
21688
21688
  },
21689
21689
  {
21690
21690
  name: "ls_list_license_keys",
@@ -21707,19 +21707,12 @@ var licenseKeyTools = [
21707
21707
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21708
21708
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21709
21709
  }),
21710
- handler: async (input) => {
21711
- const filter = {};
21712
- if (input.storeId) filter.store_id = input.storeId;
21713
- if (input.orderId) filter.order_id = input.orderId;
21714
- if (input.orderItemId) filter.order_item_id = input.orderItemId;
21715
- if (input.productId) filter.product_id = input.productId;
21716
- const query = buildQuery({
21717
- include: input.include?.split(","),
21718
- filter,
21719
- page: { number: input.pageNumber, size: input.pageSize }
21720
- });
21721
- return apiGet(`/license-keys${query}`);
21722
- }
21710
+ handler: listHandler("/license-keys", {
21711
+ storeId: "store_id",
21712
+ orderId: "order_id",
21713
+ orderItemId: "order_item_id",
21714
+ productId: "product_id"
21715
+ })
21723
21716
  },
21724
21717
  {
21725
21718
  name: "ls_update_license_key",
@@ -21835,10 +21828,7 @@ var orderItemTools = [
21835
21828
  orderItemId: external_exports.string().describe("The order item ID"),
21836
21829
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'order,product,variant')")
21837
21830
  }),
21838
- handler: async (input) => {
21839
- const query = buildQuery({ include: input.include?.split(",") });
21840
- return apiGet(`/order-items/${input.orderItemId}${query}`);
21841
- }
21831
+ handler: getHandler("/order-items", "orderItemId")
21842
21832
  },
21843
21833
  {
21844
21834
  name: "ls_list_order_items",
@@ -21858,18 +21848,7 @@ var orderItemTools = [
21858
21848
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21859
21849
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21860
21850
  }),
21861
- handler: async (input) => {
21862
- const filter = {};
21863
- if (input.orderId) filter.order_id = input.orderId;
21864
- if (input.productId) filter.product_id = input.productId;
21865
- if (input.variantId) filter.variant_id = input.variantId;
21866
- const query = buildQuery({
21867
- include: input.include?.split(","),
21868
- filter,
21869
- page: { number: input.pageNumber, size: input.pageSize }
21870
- });
21871
- return apiGet(`/order-items${query}`);
21872
- }
21851
+ handler: listHandler("/order-items", { orderId: "order_id", productId: "product_id", variantId: "variant_id" })
21873
21852
  }
21874
21853
  ];
21875
21854
 
@@ -21891,10 +21870,7 @@ var orderTools = [
21891
21870
  "Comma-separated related resources to include (e.g. 'store,customer,order-items,subscriptions,license-keys,discount-redemptions')"
21892
21871
  )
21893
21872
  }),
21894
- handler: async (input) => {
21895
- const query = buildQuery({ include: input.include?.split(",") });
21896
- return apiGet(`/orders/${input.orderId}${query}`);
21897
- }
21873
+ handler: getHandler("/orders", "orderId")
21898
21874
  },
21899
21875
  {
21900
21876
  name: "ls_list_orders",
@@ -21915,17 +21891,7 @@ var orderTools = [
21915
21891
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
21916
21892
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
21917
21893
  }),
21918
- handler: async (input) => {
21919
- const filter = {};
21920
- if (input.storeId) filter.store_id = input.storeId;
21921
- if (input.userEmail) filter.user_email = input.userEmail;
21922
- const query = buildQuery({
21923
- include: input.include?.split(","),
21924
- filter,
21925
- page: { number: input.pageNumber, size: input.pageSize }
21926
- });
21927
- return apiGet(`/orders${query}`);
21928
- }
21894
+ handler: listHandler("/orders", { storeId: "store_id", userEmail: "user_email" })
21929
21895
  },
21930
21896
  {
21931
21897
  name: "ls_generate_order_invoice",
@@ -22000,10 +21966,7 @@ var priceTools = [
22000
21966
  priceId: external_exports.string().describe("The price ID"),
22001
21967
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'variant')")
22002
21968
  }),
22003
- handler: async (input) => {
22004
- const query = buildQuery({ include: input.include?.split(",") });
22005
- return apiGet(`/prices/${input.priceId}${query}`);
22006
- }
21969
+ handler: getHandler("/prices", "priceId")
22007
21970
  },
22008
21971
  {
22009
21972
  name: "ls_list_prices",
@@ -22021,16 +21984,7 @@ var priceTools = [
22021
21984
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22022
21985
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22023
21986
  }),
22024
- handler: async (input) => {
22025
- const filter = {};
22026
- if (input.variantId) filter.variant_id = input.variantId;
22027
- const query = buildQuery({
22028
- include: input.include?.split(","),
22029
- filter,
22030
- page: { number: input.pageNumber, size: input.pageSize }
22031
- });
22032
- return apiGet(`/prices${query}`);
22033
- }
21987
+ handler: listHandler("/prices", { variantId: "variant_id" })
22034
21988
  }
22035
21989
  ];
22036
21990
 
@@ -22050,10 +22004,7 @@ var productTools = [
22050
22004
  productId: external_exports.string().describe("The product ID"),
22051
22005
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store,variants')")
22052
22006
  }),
22053
- handler: async (input) => {
22054
- const query = buildQuery({ include: input.include?.split(",") });
22055
- return apiGet(`/products/${input.productId}${query}`);
22056
- }
22007
+ handler: getHandler("/products", "productId")
22057
22008
  },
22058
22009
  {
22059
22010
  name: "ls_list_products",
@@ -22071,16 +22022,7 @@ var productTools = [
22071
22022
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22072
22023
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22073
22024
  }),
22074
- handler: async (input) => {
22075
- const filter = {};
22076
- if (input.storeId) filter.store_id = input.storeId;
22077
- const query = buildQuery({
22078
- include: input.include?.split(","),
22079
- filter,
22080
- page: { number: input.pageNumber, size: input.pageSize }
22081
- });
22082
- return apiGet(`/products${query}`);
22083
- }
22025
+ handler: listHandler("/products", { storeId: "store_id" })
22084
22026
  }
22085
22027
  ];
22086
22028
 
@@ -22102,10 +22044,7 @@ var storeTools = [
22102
22044
  "Comma-separated related resources to include (e.g. 'products,discounts,license-keys,subscriptions,webhooks')"
22103
22045
  )
22104
22046
  }),
22105
- handler: async (input) => {
22106
- const query = buildQuery({ include: input.include?.split(",") });
22107
- return apiGet(`/stores/${input.storeId}${query}`);
22108
- }
22047
+ handler: getHandler("/stores", "storeId")
22109
22048
  },
22110
22049
  {
22111
22050
  name: "ls_list_stores",
@@ -22124,13 +22063,7 @@ var storeTools = [
22124
22063
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22125
22064
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22126
22065
  }),
22127
- handler: async (input) => {
22128
- const query = buildQuery({
22129
- include: input.include?.split(","),
22130
- page: { number: input.pageNumber, size: input.pageSize }
22131
- });
22132
- return apiGet(`/stores${query}`);
22133
- }
22066
+ handler: listHandler("/stores")
22134
22067
  }
22135
22068
  ];
22136
22069
 
@@ -22150,10 +22083,7 @@ var subscriptionInvoiceTools = [
22150
22083
  subscriptionInvoiceId: external_exports.string().describe("The subscription invoice ID"),
22151
22084
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store,subscription')")
22152
22085
  }),
22153
- handler: async (input) => {
22154
- const query = buildQuery({ include: input.include?.split(",") });
22155
- return apiGet(`/subscription-invoices/${input.subscriptionInvoiceId}${query}`);
22156
- }
22086
+ handler: getHandler("/subscription-invoices", "subscriptionInvoiceId")
22157
22087
  },
22158
22088
  {
22159
22089
  name: "ls_list_subscription_invoices",
@@ -22174,19 +22104,12 @@ var subscriptionInvoiceTools = [
22174
22104
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22175
22105
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22176
22106
  }),
22177
- handler: async (input) => {
22178
- const filter = {};
22179
- if (input.storeId) filter.store_id = input.storeId;
22180
- if (input.subscriptionId) filter.subscription_id = input.subscriptionId;
22181
- if (input.status) filter.status = input.status;
22182
- if (input.refunded !== void 0) filter.refunded = String(input.refunded);
22183
- const query = buildQuery({
22184
- include: input.include?.split(","),
22185
- filter,
22186
- page: { number: input.pageNumber, size: input.pageSize }
22187
- });
22188
- return apiGet(`/subscription-invoices${query}`);
22189
- }
22107
+ handler: listHandler("/subscription-invoices", {
22108
+ storeId: "store_id",
22109
+ subscriptionId: "subscription_id",
22110
+ status: "status",
22111
+ refunded: "refunded"
22112
+ })
22190
22113
  },
22191
22114
  {
22192
22115
  name: "ls_generate_subscription_invoice",
@@ -22265,10 +22188,7 @@ var subscriptionItemTools = [
22265
22188
  subscriptionItemId: external_exports.string().describe("The subscription item ID"),
22266
22189
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'subscription,price,usage-records')")
22267
22190
  }),
22268
- handler: async (input) => {
22269
- const query = buildQuery({ include: input.include?.split(",") });
22270
- return apiGet(`/subscription-items/${input.subscriptionItemId}${query}`);
22271
- }
22191
+ handler: getHandler("/subscription-items", "subscriptionItemId")
22272
22192
  },
22273
22193
  {
22274
22194
  name: "ls_list_subscription_items",
@@ -22287,17 +22207,7 @@ var subscriptionItemTools = [
22287
22207
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22288
22208
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22289
22209
  }),
22290
- handler: async (input) => {
22291
- const filter = {};
22292
- if (input.subscriptionId) filter.subscription_id = input.subscriptionId;
22293
- if (input.priceId) filter.price_id = input.priceId;
22294
- const query = buildQuery({
22295
- include: input.include?.split(","),
22296
- filter,
22297
- page: { number: input.pageNumber, size: input.pageSize }
22298
- });
22299
- return apiGet(`/subscription-items${query}`);
22300
- }
22210
+ handler: listHandler("/subscription-items", { subscriptionId: "subscription_id", priceId: "price_id" })
22301
22211
  },
22302
22212
  {
22303
22213
  name: "ls_update_subscription_item",
@@ -22360,10 +22270,7 @@ var subscriptionTools = [
22360
22270
  "Comma-separated related resources to include (e.g. 'store,customer,order,order-item,product,variant,subscription-items,subscription-invoices')"
22361
22271
  )
22362
22272
  }),
22363
- handler: async (input) => {
22364
- const query = buildQuery({ include: input.include?.split(",") });
22365
- return apiGet(`/subscriptions/${input.subscriptionId}${query}`);
22366
- }
22273
+ handler: getHandler("/subscriptions", "subscriptionId")
22367
22274
  },
22368
22275
  {
22369
22276
  name: "ls_list_subscriptions",
@@ -22389,22 +22296,15 @@ var subscriptionTools = [
22389
22296
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22390
22297
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22391
22298
  }),
22392
- handler: async (input) => {
22393
- const filter = {};
22394
- if (input.storeId) filter.store_id = input.storeId;
22395
- if (input.orderId) filter.order_id = input.orderId;
22396
- if (input.orderItemId) filter.order_item_id = input.orderItemId;
22397
- if (input.productId) filter.product_id = input.productId;
22398
- if (input.variantId) filter.variant_id = input.variantId;
22399
- if (input.userEmail) filter.user_email = input.userEmail;
22400
- if (input.status) filter.status = input.status;
22401
- const query = buildQuery({
22402
- include: input.include?.split(","),
22403
- filter,
22404
- page: { number: input.pageNumber, size: input.pageSize }
22405
- });
22406
- return apiGet(`/subscriptions${query}`);
22407
- }
22299
+ handler: listHandler("/subscriptions", {
22300
+ storeId: "store_id",
22301
+ orderId: "order_id",
22302
+ orderItemId: "order_item_id",
22303
+ productId: "product_id",
22304
+ variantId: "variant_id",
22305
+ userEmail: "user_email",
22306
+ status: "status"
22307
+ })
22408
22308
  },
22409
22309
  {
22410
22310
  name: "ls_update_subscription",
@@ -22481,10 +22381,7 @@ var usageRecordTools = [
22481
22381
  usageRecordId: external_exports.string().describe("The usage record ID"),
22482
22382
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'subscription-item')")
22483
22383
  }),
22484
- handler: async (input) => {
22485
- const query = buildQuery({ include: input.include?.split(",") });
22486
- return apiGet(`/usage-records/${input.usageRecordId}${query}`);
22487
- }
22384
+ handler: getHandler("/usage-records", "usageRecordId")
22488
22385
  },
22489
22386
  {
22490
22387
  name: "ls_list_usage_records",
@@ -22502,16 +22399,7 @@ var usageRecordTools = [
22502
22399
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22503
22400
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22504
22401
  }),
22505
- handler: async (input) => {
22506
- const filter = {};
22507
- if (input.subscriptionItemId) filter.subscription_item_id = input.subscriptionItemId;
22508
- const query = buildQuery({
22509
- include: input.include?.split(","),
22510
- filter,
22511
- page: { number: input.pageNumber, size: input.pageSize }
22512
- });
22513
- return apiGet(`/usage-records${query}`);
22514
- }
22402
+ handler: listHandler("/usage-records", { subscriptionItemId: "subscription_item_id" })
22515
22403
  },
22516
22404
  {
22517
22405
  name: "ls_create_usage_record",
@@ -22583,10 +22471,7 @@ var variantTools = [
22583
22471
  variantId: external_exports.string().describe("The variant ID"),
22584
22472
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'product,files')")
22585
22473
  }),
22586
- handler: async (input) => {
22587
- const query = buildQuery({ include: input.include?.split(",") });
22588
- return apiGet(`/variants/${input.variantId}${query}`);
22589
- }
22474
+ handler: getHandler("/variants", "variantId")
22590
22475
  },
22591
22476
  {
22592
22477
  name: "ls_list_variants",
@@ -22604,16 +22489,7 @@ var variantTools = [
22604
22489
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22605
22490
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22606
22491
  }),
22607
- handler: async (input) => {
22608
- const filter = {};
22609
- if (input.productId) filter.product_id = input.productId;
22610
- const query = buildQuery({
22611
- include: input.include?.split(","),
22612
- filter,
22613
- page: { number: input.pageNumber, size: input.pageSize }
22614
- });
22615
- return apiGet(`/variants${query}`);
22616
- }
22492
+ handler: listHandler("/variants", { productId: "product_id" })
22617
22493
  }
22618
22494
  ];
22619
22495
 
@@ -22633,10 +22509,7 @@ var webhookTools = [
22633
22509
  webhookId: external_exports.string().describe("The webhook ID"),
22634
22510
  include: external_exports.string().optional().describe("Comma-separated related resources to include (e.g. 'store')")
22635
22511
  }),
22636
- handler: async (input) => {
22637
- const query = buildQuery({ include: input.include?.split(",") });
22638
- return apiGet(`/webhooks/${input.webhookId}${query}`);
22639
- }
22512
+ handler: getHandler("/webhooks", "webhookId")
22640
22513
  },
22641
22514
  {
22642
22515
  name: "ls_list_webhooks",
@@ -22654,16 +22527,7 @@ var webhookTools = [
22654
22527
  pageNumber: external_exports.number().int().min(1).optional().describe("Page number (1-indexed)"),
22655
22528
  pageSize: external_exports.number().int().min(1).max(100).optional().describe("Results per page (1-100)")
22656
22529
  }),
22657
- handler: async (input) => {
22658
- const filter = {};
22659
- if (input.storeId) filter.store_id = input.storeId;
22660
- const query = buildQuery({
22661
- include: input.include?.split(","),
22662
- filter,
22663
- page: { number: input.pageNumber, size: input.pageSize }
22664
- });
22665
- return apiGet(`/webhooks${query}`);
22666
- }
22530
+ handler: listHandler("/webhooks", { storeId: "store_id" })
22667
22531
  },
22668
22532
  {
22669
22533
  name: "ls_create_webhook",
@@ -22749,7 +22613,7 @@ var webhookTools = [
22749
22613
  ];
22750
22614
 
22751
22615
  // src/index.ts
22752
- var version2 = true ? "0.2.0" : (await null).createRequire(import.meta.url)("../package.json").version;
22616
+ var version2 = true ? "0.3.0" : (await null).createRequire(import.meta.url)("../package.json").version;
22753
22617
  var subcommand = process.argv[2];
22754
22618
  if (subcommand === "version" || subcommand === "--version") {
22755
22619
  console.log(version2);
@@ -22775,7 +22639,8 @@ var allTools = [
22775
22639
  ...licenseKeyInstanceTools,
22776
22640
  ...checkoutTools,
22777
22641
  ...webhookTools,
22778
- ...licenseTools
22642
+ ...licenseTools,
22643
+ ...affiliateTools
22779
22644
  ];
22780
22645
  var server = new McpServer({
22781
22646
  name: "@yawlabs/lemonsqueezy-mcp",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yawlabs/lemonsqueezy-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "LemonSqueezy MCP server for managing your store from AI assistants",
5
5
  "license": "MIT",
6
6
  "author": "YawLabs <contact@yaw.sh>",
@@ -34,7 +34,7 @@
34
34
  "test:ci": "npm run test",
35
35
  "lint": "biome check src/",
36
36
  "lint:fix": "biome check --write src/",
37
- "prepublishOnly": "npm run build"
37
+ "prepublishOnly": "npm run build && node --test dist/**/*.test.js"
38
38
  },
39
39
  "dependencies": {},
40
40
  "devDependencies": {