|
| 1 | +import type { ProviderActionDefinition } from "../../core/provider-definition.ts"; |
| 2 | + |
| 3 | +import { s } from "../../core/json-schema.ts"; |
| 4 | +import { defineProviderAction } from "../../core/provider-definition.ts"; |
| 5 | + |
| 6 | +const service = "revenuecat" as const; |
| 7 | + |
| 8 | +const identifier = (description: string) => s.string({ minLength: 1, maxLength: 1500, description }); |
| 9 | + |
| 10 | +const paginationFields = { |
| 11 | + startingAfter: s.string("Return records after this RevenueCat cursor."), |
| 12 | + limit: s.integer("Maximum number of records to return.", { minimum: 1, maximum: 100 }), |
| 13 | +}; |
| 14 | + |
| 15 | +const rawObject = (description: string) => s.looseObject(description); |
| 16 | + |
| 17 | +const listOutput = (description: string, itemDescription: string) => |
| 18 | + s.object(description, { |
| 19 | + object: s.literal("list", { description: "RevenueCat list response marker." }), |
| 20 | + items: s.array(rawObject(itemDescription), { description: "Records returned by RevenueCat." }), |
| 21 | + nextPage: s.nullableString("URL for the next page, or null when there are no more records."), |
| 22 | + url: s.string("URL of the current RevenueCat list response."), |
| 23 | + }); |
| 24 | + |
| 25 | +const singleOutput = (description: string, field: string, itemDescription: string) => |
| 26 | + s.object(description, { |
| 27 | + [field]: rawObject(itemDescription), |
| 28 | + }); |
| 29 | + |
| 30 | +const expandCustomerFields = s.array(s.stringEnum(["attributes"], { description: "A customer field to expand." }), { |
| 31 | + maxItems: 1, |
| 32 | + description: "Optional customer fields to expand in the response.", |
| 33 | +}); |
| 34 | + |
| 35 | +const expandOfferingFields = s.array( |
| 36 | + s.stringEnum(["items.package", "items.package.product"], { |
| 37 | + description: "An Offering field to expand.", |
| 38 | + }), |
| 39 | + { |
| 40 | + maxItems: 2, |
| 41 | + description: "Optional Offering fields to expand in the response.", |
| 42 | + }, |
| 43 | +); |
| 44 | + |
| 45 | +const currency = s.stringEnum( |
| 46 | + ["USD", "EUR", "GBP", "AUD", "CAD", "JPY", "BRL", "KRW", "CNY", "MXN", "SEK", "PLN", "NZD", "CHF"], |
| 47 | + { description: "Currency used for the returned RevenueCat metrics." }, |
| 48 | +); |
| 49 | + |
| 50 | +const projectInput = (description: string, properties: Record<string, object>, required: string[] = ["projectId"]) => |
| 51 | + s.object(description, { projectId: identifier("RevenueCat project ID."), ...properties }, { required }); |
| 52 | + |
| 53 | +export const revenueCatActions: readonly ProviderActionDefinition[] = [ |
| 54 | + defineProviderAction(service, { |
| 55 | + name: "list_projects", |
| 56 | + description: "List RevenueCat projects accessible to the configured secret API key.", |
| 57 | + requiredScopes: ["project_configuration:projects:read"], |
| 58 | + inputSchema: s.object("Pagination for RevenueCat projects.", paginationFields), |
| 59 | + outputSchema: listOutput("A paginated list of RevenueCat projects.", "A RevenueCat project."), |
| 60 | + }), |
| 61 | + defineProviderAction(service, { |
| 62 | + name: "list_customers", |
| 63 | + description: "List customers in a RevenueCat project, optionally searching by email or customer identifier.", |
| 64 | + requiredScopes: ["customer_information:customers:read"], |
| 65 | + inputSchema: projectInput("Filters for RevenueCat customers.", { |
| 66 | + ...paginationFields, |
| 67 | + search: s.string("Search by customer email, app user ID, store transaction identifier, or Apple order ID.", { |
| 68 | + minLength: 1, |
| 69 | + maxLength: 255, |
| 70 | + }), |
| 71 | + }), |
| 72 | + outputSchema: listOutput("A paginated list of RevenueCat customers.", "A RevenueCat customer."), |
| 73 | + }), |
| 74 | + defineProviderAction(service, { |
| 75 | + name: "get_customer", |
| 76 | + description: "Retrieve a RevenueCat customer and optionally expand the customer's attributes.", |
| 77 | + requiredScopes: ["customer_information:customers:read"], |
| 78 | + inputSchema: projectInput( |
| 79 | + "Input for retrieving a RevenueCat customer.", |
| 80 | + { |
| 81 | + customerId: identifier("RevenueCat customer or app user ID."), |
| 82 | + expand: expandCustomerFields, |
| 83 | + }, |
| 84 | + ["projectId", "customerId"], |
| 85 | + ), |
| 86 | + outputSchema: singleOutput("A RevenueCat customer response.", "customer", "A RevenueCat customer."), |
| 87 | + }), |
| 88 | + defineProviderAction(service, { |
| 89 | + name: "list_customer_subscriptions", |
| 90 | + description: "List subscriptions belonging to a RevenueCat customer.", |
| 91 | + requiredScopes: ["customer_information:subscriptions:read"], |
| 92 | + inputSchema: projectInput( |
| 93 | + "Pagination for a customer's RevenueCat subscriptions.", |
| 94 | + { |
| 95 | + customerId: identifier("RevenueCat customer or app user ID."), |
| 96 | + ...paginationFields, |
| 97 | + }, |
| 98 | + ["projectId", "customerId"], |
| 99 | + ), |
| 100 | + outputSchema: listOutput("A paginated list of customer subscriptions.", "A RevenueCat subscription."), |
| 101 | + }), |
| 102 | + defineProviderAction(service, { |
| 103 | + name: "get_subscription", |
| 104 | + description: "Retrieve a RevenueCat subscription by its subscription ID.", |
| 105 | + requiredScopes: ["customer_information:subscriptions:read"], |
| 106 | + inputSchema: projectInput( |
| 107 | + "Input for retrieving a RevenueCat subscription.", |
| 108 | + { |
| 109 | + subscriptionId: identifier("RevenueCat subscription ID."), |
| 110 | + }, |
| 111 | + ["projectId", "subscriptionId"], |
| 112 | + ), |
| 113 | + outputSchema: singleOutput("A RevenueCat subscription response.", "subscription", "A RevenueCat subscription."), |
| 114 | + }), |
| 115 | + defineProviderAction(service, { |
| 116 | + name: "search_subscriptions", |
| 117 | + description: |
| 118 | + "Find subscriptions by a store subscription identifier such as an Apple transaction ID or Google order ID.", |
| 119 | + requiredScopes: ["customer_information:subscriptions:read"], |
| 120 | + inputSchema: projectInput( |
| 121 | + "Input for searching RevenueCat subscriptions.", |
| 122 | + { |
| 123 | + storeSubscriptionIdentifier: identifier("Store subscription identifier to search for."), |
| 124 | + includeScheduled: s.boolean("Whether to include subscriptions scheduled to start in the future."), |
| 125 | + }, |
| 126 | + ["projectId", "storeSubscriptionIdentifier"], |
| 127 | + ), |
| 128 | + outputSchema: listOutput("A list of subscriptions matching the store identifier.", "A RevenueCat subscription."), |
| 129 | + }), |
| 130 | + defineProviderAction(service, { |
| 131 | + name: "list_customer_active_entitlements", |
| 132 | + description: "List the entitlements currently active for a RevenueCat customer.", |
| 133 | + requiredScopes: ["customer_information:customers:read"], |
| 134 | + inputSchema: projectInput( |
| 135 | + "Pagination for a customer's active RevenueCat entitlements.", |
| 136 | + { |
| 137 | + customerId: identifier("RevenueCat customer or app user ID."), |
| 138 | + ...paginationFields, |
| 139 | + }, |
| 140 | + ["projectId", "customerId"], |
| 141 | + ), |
| 142 | + outputSchema: listOutput( |
| 143 | + "A paginated list of active customer entitlements.", |
| 144 | + "An active RevenueCat customer entitlement.", |
| 145 | + ), |
| 146 | + }), |
| 147 | + defineProviderAction(service, { |
| 148 | + name: "list_entitlements", |
| 149 | + description: "List entitlement definitions configured in a RevenueCat project.", |
| 150 | + requiredScopes: ["project_configuration:entitlements:read"], |
| 151 | + inputSchema: projectInput("Pagination for RevenueCat entitlements.", paginationFields), |
| 152 | + outputSchema: listOutput("A paginated list of RevenueCat entitlements.", "A RevenueCat entitlement definition."), |
| 153 | + }), |
| 154 | + defineProviderAction(service, { |
| 155 | + name: "list_offerings", |
| 156 | + description: "List offerings configured in a RevenueCat project, optionally expanding packages and products.", |
| 157 | + requiredScopes: ["project_configuration:offerings:read"], |
| 158 | + inputSchema: projectInput("Pagination and expansion options for RevenueCat offerings.", { |
| 159 | + ...paginationFields, |
| 160 | + expand: expandOfferingFields, |
| 161 | + }), |
| 162 | + outputSchema: listOutput("A paginated list of RevenueCat offerings.", "A RevenueCat offering."), |
| 163 | + }), |
| 164 | + defineProviderAction(service, { |
| 165 | + name: "list_products", |
| 166 | + description: "List products configured in a RevenueCat project.", |
| 167 | + requiredScopes: ["project_configuration:products:read"], |
| 168 | + inputSchema: projectInput("Pagination for RevenueCat products.", paginationFields), |
| 169 | + outputSchema: listOutput("A paginated list of RevenueCat products.", "A RevenueCat product."), |
| 170 | + }), |
| 171 | + defineProviderAction(service, { |
| 172 | + name: "get_overview_metrics", |
| 173 | + description: "Retrieve overview metrics for a RevenueCat project.", |
| 174 | + requiredScopes: ["charts_metrics:overview:read"], |
| 175 | + inputSchema: projectInput("Input for retrieving RevenueCat overview metrics.", { currency }), |
| 176 | + outputSchema: singleOutput( |
| 177 | + "RevenueCat overview metrics response.", |
| 178 | + "metrics", |
| 179 | + "RevenueCat project overview metrics.", |
| 180 | + ), |
| 181 | + }), |
| 182 | + defineProviderAction(service, { |
| 183 | + name: "get_revenue_metric", |
| 184 | + description: "Retrieve total RevenueCat project revenue for an inclusive date range.", |
| 185 | + requiredScopes: ["charts_metrics:overview:read"], |
| 186 | + inputSchema: projectInput( |
| 187 | + "Input for retrieving RevenueCat revenue metrics.", |
| 188 | + { |
| 189 | + startDate: s.date("Inclusive start date in ISO 8601 format."), |
| 190 | + endDate: s.date("Inclusive end date in ISO 8601 format."), |
| 191 | + currency, |
| 192 | + revenueType: s.stringEnum(["revenue", "revenue_net_of_taxes", "proceeds"], { |
| 193 | + description: "Revenue definition returned as the metric value.", |
| 194 | + }), |
| 195 | + }, |
| 196 | + ["projectId", "startDate", "endDate"], |
| 197 | + ), |
| 198 | + outputSchema: singleOutput("RevenueCat revenue metric response.", "metric", "RevenueCat revenue metric data."), |
| 199 | + }), |
| 200 | +]; |
0 commit comments