@usethrottle/mcp 0.6.0 → 0.8.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.
package/dist/mcp.js CHANGED
@@ -118,6 +118,10 @@ var ThrottleClient = class {
118
118
  const body = await this.requestJson("PATCH", path, options);
119
119
  return body && typeof body === "object" && "data" in body ? body.data : body;
120
120
  }
121
+ async delete(path, options = {}) {
122
+ const body = await this.requestJson("DELETE", path, options);
123
+ return body && typeof body === "object" && "data" in body ? body.data : body;
124
+ }
121
125
  };
122
126
  async function optional(load) {
123
127
  try {
@@ -171,6 +175,7 @@ function add(group, resource, actions, labels, opts = {}) {
171
175
  }
172
176
  add("Orders", "orders", ["read", "write"], { read: "View orders", write: "Manage orders" });
173
177
  add("Quotes", "quotes", ["read", "write"], { read: "View quotes", write: "Manage quotes" });
178
+ add("Forms", "forms", ["read", "write"], { read: "View site forms and their submissions", write: "Manage site forms" }, { sensitive: true });
174
179
  add("Orders", "order_cancellations", ["write"], { write: "Cancel orders" });
175
180
  add("Orders", "order_returns", ["read", "write"], { read: "View returns", write: "Process returns" });
176
181
  add("Orders", "order_comps", ["write"], { write: "Comp orders (write off the balance)" }, { sensitive: true });
@@ -196,6 +201,8 @@ add("Customers", "customer_addresses", ["read", "write"], { read: "View addresse
196
201
  add("Customers", "customer_payment_methods", ["read", "write"], { read: "View stored cards", write: "Manage stored cards" }, { sensitive: true });
197
202
  add("Customers", "customer_tokens", ["read"], { read: "Check shoppers' sign-in tokens" });
198
203
  add("Customers", "customer_directory", ["read"], { read: "Find customers by name or email" }, { sensitive: true });
204
+ add("Customers", "customer_groups", ["read", "write"], { read: "View customer groups", write: "Manage customer groups and members" });
205
+ REG["customer_groups:write"] = { ...REG["customer_groups:write"], extensionAllowed: false };
199
206
  add(
200
207
  "Customer accounts",
201
208
  "customer_accounts",
@@ -255,6 +262,7 @@ add("Webhooks & Events", "webhooks", ["read", "write"], { read: "View webhooks",
255
262
  add("Webhooks & Events", "webhook_deliveries", ["read", "write"], { read: "View deliveries", write: "Retry deliveries" });
256
263
  add("Webhooks & Events", "events", ["read"], { read: "View events" });
257
264
  add("Webhooks & Events", "audit_logs", ["read"], { read: "View audit log" });
265
+ add("Webhooks & Events", "activity", ["write"], { write: "Add history entries to records" });
258
266
  add("Applications", "applications", ["read", "write"], { read: "View applications", write: "Manage applications" });
259
267
  add("Workspace", "merchant", ["read", "write"], { read: "View workspace settings", write: "Edit workspace settings" });
260
268
  add("Workspace", "embed_config", ["read", "write"], { read: "View embed config", write: "Edit embed config" });
@@ -336,8 +344,10 @@ var PREFIX_RULES = [
336
344
  ["cart.", "carts:read"],
337
345
  ["order.", "orders:read"],
338
346
  ["quote.", "quotes:read"],
347
+ ["form.", "forms:read"],
339
348
  ["return.", "order_returns:read"],
340
349
  ["payment.", "payments:read"],
350
+ ["customer_group.", "customer_groups:read"],
341
351
  ["customer.", "customers:read"],
342
352
  ["subscription.", "subscriptions:read"],
343
353
  ["fulfillment.", "fulfillments:read"],
@@ -1577,6 +1587,103 @@ var ACTIONS = [
1577
1587
  "The updated record is echoed back with email, phone, firstName, lastName and name nulled unless the credential holds customer_pii:read, which OAuth connections cannot hold \u2014 the update still applied, only the response is redacted."
1578
1588
  ]
1579
1589
  },
1590
+ // ------------------------------------------------------------ customer groups
1591
+ {
1592
+ id: "list_customer_groups",
1593
+ title: "List customer groups",
1594
+ description: "List the customer groups of the application (at most 50), with member and discount counts. A customer belongs to at most one group; a group can be fixed or a percent group with a percentBps rate.",
1595
+ kind: "read",
1596
+ scopes: ["customer_groups:read"],
1597
+ input: [],
1598
+ requests: [{ method: "GET", path: "/api/v1/customer-groups" }],
1599
+ channels: ["mcp"]
1600
+ },
1601
+ {
1602
+ id: "get_customer_group",
1603
+ title: "Get a customer group",
1604
+ description: "Fetch one customer group by id.",
1605
+ kind: "read",
1606
+ scopes: ["customer_groups:read"],
1607
+ input: [{ name: "id", type: "string", required: true, description: "Customer group id." }],
1608
+ requests: [{ method: "GET", path: "/api/v1/customer-groups/:id" }],
1609
+ channels: ["mcp"]
1610
+ },
1611
+ {
1612
+ id: "create_customer_group",
1613
+ title: "Create a customer group",
1614
+ description: "Create a customer group. kind is fixed or percent; a percent group requires percentBps (1-10000, 1500 = 15%) and a fixed group must not have one.",
1615
+ kind: "write",
1616
+ scopes: ["customer_groups:write"],
1617
+ input: [
1618
+ { name: "name", type: "string", required: true, description: "Group name, 1 to 100 characters." },
1619
+ { name: "kind", type: "string", required: true, description: "fixed or percent." },
1620
+ { name: "percentBps", type: "number", required: false, description: "Percent rate in basis points, 1-10000. Required for percent groups." },
1621
+ { name: "enabled", type: "boolean", required: false, description: "Whether the group is active.", default: true },
1622
+ { name: "taxExempt", type: "boolean", required: false, description: "Members are exempt from tax. Needs taxExemptReason.", default: false },
1623
+ { name: "taxExemptReason", type: "string", required: false, description: "Avalara entity-use code (A-R) that explains the exemption. Required when taxExempt is true." }
1624
+ ],
1625
+ requests: [{ method: "POST", path: "/api/v1/customer-groups" }],
1626
+ channels: ["mcp"],
1627
+ idempotent: true
1628
+ },
1629
+ {
1630
+ id: "update_customer_group",
1631
+ title: "Update a customer group",
1632
+ description: "Change fields on a customer group. Only the fields supplied are touched.",
1633
+ kind: "write",
1634
+ scopes: ["customer_groups:write"],
1635
+ input: [
1636
+ { name: "id", type: "string", required: true, description: "Customer group id." },
1637
+ { name: "name", type: "string", required: false, description: "Group name, 1 to 100 characters." },
1638
+ { name: "kind", type: "string", required: false, description: "fixed or percent." },
1639
+ { name: "percentBps", type: "number", required: false, description: "Percent rate in basis points, 1-10000. To make the group fixed, set kind to fixed (the rate is cleared)." },
1640
+ { name: "enabled", type: "boolean", required: false, description: "Whether the group is active." },
1641
+ { name: "taxExempt", type: "boolean", required: false, description: "Members are exempt from tax. Needs taxExemptReason." },
1642
+ { name: "taxExemptReason", type: "string", required: false, description: "Avalara entity-use code (A-R). Set null to clear when taxExempt is false." }
1643
+ ],
1644
+ requests: [{ method: "PATCH", path: "/api/v1/customer-groups/:id" }],
1645
+ channels: ["mcp"],
1646
+ idempotent: true
1647
+ },
1648
+ {
1649
+ id: "delete_customer_group",
1650
+ title: "Delete a customer group",
1651
+ description: "Delete a customer group. Its members are removed from it; the response reports removedMemberCount.",
1652
+ kind: "write",
1653
+ scopes: ["customer_groups:write"],
1654
+ input: [{ name: "id", type: "string", required: true, description: "Customer group id." }],
1655
+ requests: [{ method: "DELETE", path: "/api/v1/customer-groups/:id" }],
1656
+ channels: ["mcp"],
1657
+ idempotent: true
1658
+ },
1659
+ {
1660
+ id: "add_customer_group_members",
1661
+ title: "Add customers to a group",
1662
+ description: "Add up to 100 customers to a group. A customer already in another group is moved; the response counts added and moved.",
1663
+ kind: "write",
1664
+ scopes: ["customer_groups:write"],
1665
+ input: [
1666
+ { name: "id", type: "string", required: true, description: "Customer group id." },
1667
+ { name: "customerIds", type: "array", required: true, description: "Customer ids (1-100)." }
1668
+ ],
1669
+ requests: [{ method: "POST", path: "/api/v1/customer-groups/:id/members" }],
1670
+ channels: ["mcp"],
1671
+ idempotent: true
1672
+ },
1673
+ {
1674
+ id: "remove_customer_group_members",
1675
+ title: "Remove customers from a group",
1676
+ description: "Remove up to 100 customers from a group; the response counts removed.",
1677
+ kind: "write",
1678
+ scopes: ["customer_groups:write"],
1679
+ input: [
1680
+ { name: "id", type: "string", required: true, description: "Customer group id." },
1681
+ { name: "customerIds", type: "array", required: true, description: "Customer ids (1-100)." }
1682
+ ],
1683
+ requests: [{ method: "POST", path: "/api/v1/customer-groups/:id/members/remove" }],
1684
+ channels: ["mcp"],
1685
+ idempotent: true
1686
+ },
1580
1687
  {
1581
1688
  id: "create_checkout_link",
1582
1689
  title: "Create a checkout link",
@@ -1899,6 +2006,9 @@ details: ${JSON.stringify(e.details)}` : "";
1899
2006
  return `Error: ${e?.message ?? String(error)}`;
1900
2007
  }
1901
2008
 
2009
+ // src/handlers.ts
2010
+ import { randomUUID } from "crypto";
2011
+
1902
2012
  // src/contract.ts
1903
2013
  var RETIRED_FIELDS = {
1904
2014
  storeId: "applicationId",
@@ -2422,6 +2532,41 @@ var HANDLERS = {
2422
2532
  },
2423
2533
  idempotencyKey: `mcp-update-customer-${String(args.id)}-${Date.now()}`
2424
2534
  }),
2535
+ // ----------------------------------------------------------- customer groups
2536
+ list_customer_groups: async (ctx) => ctx.client.get("/api/v1/customer-groups"),
2537
+ get_customer_group: async (ctx, args) => ctx.client.get(`/api/v1/customer-groups/${String(args.id)}`),
2538
+ create_customer_group: async (ctx, args) => ctx.client.post("/api/v1/customer-groups", {
2539
+ body: {
2540
+ name: args.name,
2541
+ kind: args.kind,
2542
+ percentBps: args.percentBps,
2543
+ enabled: args.enabled,
2544
+ taxExempt: args.taxExempt,
2545
+ taxExemptReason: args.taxExemptReason
2546
+ },
2547
+ // Never put the merchant-written name in a header: non-Latin-1 chars make fetch throw.
2548
+ idempotencyKey: `mcp-create-customer-group-${Date.now()}-${randomUUID()}`
2549
+ }),
2550
+ // A null percentBps is meaningful (fixed group), so only `undefined` is dropped.
2551
+ update_customer_group: async (ctx, args) => ctx.client.patch(`/api/v1/customer-groups/${String(args.id)}`, {
2552
+ body: {
2553
+ name: args.name,
2554
+ kind: args.kind,
2555
+ percentBps: args.percentBps,
2556
+ enabled: args.enabled,
2557
+ taxExempt: args.taxExempt,
2558
+ taxExemptReason: args.taxExemptReason
2559
+ }
2560
+ }),
2561
+ delete_customer_group: async (ctx, args) => ctx.client.delete(`/api/v1/customer-groups/${String(args.id)}`),
2562
+ add_customer_group_members: async (ctx, args) => ctx.client.post(`/api/v1/customer-groups/${String(args.id)}/members`, {
2563
+ body: { customerIds: args.customerIds },
2564
+ idempotencyKey: `mcp-add-customer-group-members-${Date.now()}-${randomUUID()}`
2565
+ }),
2566
+ remove_customer_group_members: async (ctx, args) => ctx.client.post(`/api/v1/customer-groups/${String(args.id)}/members/remove`, {
2567
+ body: { customerIds: args.customerIds },
2568
+ idempotencyKey: `mcp-remove-customer-group-members-${Date.now()}-${randomUUID()}`
2569
+ }),
2425
2570
  create_checkout_link: async (ctx, args) => {
2426
2571
  const lineItems = Array.isArray(args.lineItems) ? args.lineItems : [];
2427
2572
  if (lineItems.length === 0) {
@@ -3419,6 +3564,20 @@ var FULFILLMENT2 = {
3419
3564
  detail: { carrier: T, serviceLevel: T, trackingNumber: T, trackingUrl: T, shippedAt: S, estimatedDelivery: S, actualDelivery: S }
3420
3565
  };
3421
3566
  var CUSTOMER = { id: S, netN: S, acceptsMarketing: S, createdAt: S };
3567
+ var CUSTOMER_GROUP = {
3568
+ id: S,
3569
+ name: T,
3570
+ kind: S,
3571
+ percentBps: S,
3572
+ enabled: S,
3573
+ taxExempt: S,
3574
+ taxExemptReason: T,
3575
+ version: S,
3576
+ memberCount: S,
3577
+ discountCount: S,
3578
+ createdAt: S,
3579
+ updatedAt: S
3580
+ };
3422
3581
  var SUBSCRIPTION2 = {
3423
3582
  id: S,
3424
3583
  status: S,
@@ -3624,6 +3783,9 @@ var OAUTH_PROJECTIONS = {
3624
3783
  addresses: section([{ id: S, isDefault: S, ...ADDRESS }]),
3625
3784
  subscriptions: section([SUBSCRIPTION2])
3626
3785
  },
3786
+ // Group names are merchant-written (T); the rest is Throttle-generated.
3787
+ list_customer_groups: [CUSTOMER_GROUP],
3788
+ get_customer_group: CUSTOMER_GROUP,
3627
3789
  list_subscriptions: page3(SUBSCRIPTION2),
3628
3790
  get_subscription: SUBSCRIPTION2,
3629
3791
  search_quotes: page3(QUOTE_SUMMARY2),
@@ -3884,7 +4046,7 @@ var OAUTH_PROJECTIONS = {
3884
4046
  };
3885
4047
 
3886
4048
  // src/server.ts
3887
- var VERSION = true ? "0.6.0" : "0.0.0-dev";
4049
+ var VERSION = true ? "0.8.0" : "0.0.0-dev";
3888
4050
  function registerableActions(policy) {
3889
4051
  const isProduction = policy.identity.environment.providerEnvironment === "production";
3890
4052
  return actionsForChannel("mcp").filter((action) => {