|
| 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 = "chartmogul"; |
| 7 | + |
| 8 | +const cursorSchema = s.nonEmptyString("The cursor returned by ChartMogul for fetching the next page."); |
| 9 | +const perPageSchema = s.integer("The maximum number of records to return. ChartMogul caps this at 200.", { |
| 10 | + minimum: 1, |
| 11 | + maximum: 200, |
| 12 | +}); |
| 13 | +const customerUuidSchema = s.nonEmptyString("The ChartMogul UUID of the customer."); |
| 14 | + |
| 15 | +const paginationOutputSchema = { |
| 16 | + cursor: s.nullableString("The cursor to use for the next page when ChartMogul returns one."), |
| 17 | + hasMore: s.boolean("Whether ChartMogul reports more records after this page."), |
| 18 | +}; |
| 19 | + |
| 20 | +const accountSchema = s.object("A normalized ChartMogul account object.", { |
| 21 | + uuid: s.nullableString("The ChartMogul account UUID."), |
| 22 | + name: s.nullableString("The account name returned by ChartMogul."), |
| 23 | + currency: s.nullableString("The account ISO 4217 currency code."), |
| 24 | + timeZone: s.nullableString("The account time zone identifier."), |
| 25 | + weekStartOn: s.nullableString("The first day of the week configured for the account."), |
| 26 | + raw: s.looseObject("The raw account object returned by ChartMogul."), |
| 27 | +}); |
| 28 | + |
| 29 | +const dataSourceSchema = s.object("A normalized ChartMogul data source.", { |
| 30 | + uuid: s.nullableString("The ChartMogul UUID for the source."), |
| 31 | + name: s.nullableString("The source name."), |
| 32 | + system: s.nullableString("The billing system type for the source."), |
| 33 | + createdAt: s.nullableString("The time when the source was created."), |
| 34 | + status: s.nullableString("The current source status."), |
| 35 | + raw: s.looseObject("The raw data source object returned by ChartMogul."), |
| 36 | +}); |
| 37 | + |
| 38 | +const customerSchema = s.object("A normalized ChartMogul customer.", { |
| 39 | + uuid: s.nullableString("The ChartMogul UUID for the customer."), |
| 40 | + externalId: s.nullableString("The primary external customer identifier."), |
| 41 | + externalIds: s.array( |
| 42 | + "All external customer identifiers returned by ChartMogul.", |
| 43 | + s.string("One external customer identifier."), |
| 44 | + ), |
| 45 | + dataSourceUuid: s.nullableString("The source UUID for the customer."), |
| 46 | + dataSourceUuids: s.array("All source UUIDs associated with the customer.", s.string("One source UUID.")), |
| 47 | + name: s.nullableString("The customer name when returned by ChartMogul."), |
| 48 | + email: s.nullableString("The customer email when returned by ChartMogul."), |
| 49 | + status: s.nullableString("The combined lead or subscription status."), |
| 50 | + company: s.nullableString("The customer company name."), |
| 51 | + country: s.nullableString("The customer country code."), |
| 52 | + state: s.nullableString("The customer state or region."), |
| 53 | + city: s.nullableString("The customer city."), |
| 54 | + customerSince: s.nullableString("The time when the customer first became a customer."), |
| 55 | + mrr: s.nullableNumber("The current monthly recurring revenue in the account currency subunit."), |
| 56 | + arr: s.nullableNumber("The current annual recurring revenue in the account currency subunit."), |
| 57 | + currency: s.nullableString("The customer currency code."), |
| 58 | + chartmogulUrl: s.nullableString("The ChartMogul app URL for the customer."), |
| 59 | + billingSystemUrl: s.nullableString("The upstream billing system URL for the customer."), |
| 60 | + raw: s.looseObject("The raw customer object returned by ChartMogul."), |
| 61 | +}); |
| 62 | + |
| 63 | +const contactSchema = s.object("A normalized ChartMogul contact.", { |
| 64 | + uuid: s.nullableString("The ChartMogul UUID for the contact."), |
| 65 | + customerUuid: s.nullableString("The ChartMogul UUID of the owning customer."), |
| 66 | + customerExternalId: s.nullableString("The external ID of the owning customer."), |
| 67 | + dataSourceUuid: s.nullableString("The source UUID for the contact."), |
| 68 | + externalId: s.nullableString("The external contact identifier."), |
| 69 | + firstName: s.nullableString("The contact first name."), |
| 70 | + lastName: s.nullableString("The contact last name."), |
| 71 | + title: s.nullableString("The contact job title."), |
| 72 | + email: s.nullableString("The contact email address."), |
| 73 | + phone: s.nullableString("The contact phone number."), |
| 74 | + linkedIn: s.nullableString("The contact LinkedIn URL."), |
| 75 | + twitter: s.nullableString("The contact Twitter or X URL."), |
| 76 | + position: s.nullableInteger("The contact position value returned by ChartMogul."), |
| 77 | + raw: s.looseObject("The raw contact object returned by ChartMogul."), |
| 78 | +}); |
| 79 | + |
| 80 | +export const chartmogulActions: ProviderActionDefinition[] = [ |
| 81 | + defineProviderAction(service, { |
| 82 | + name: "get_account", |
| 83 | + description: "Retrieve basic ChartMogul account settings for the authenticated API key.", |
| 84 | + inputSchema: s.object( |
| 85 | + "Input parameters for retrieving ChartMogul account settings.", |
| 86 | + { |
| 87 | + include: s.array( |
| 88 | + "Additional account settings to include in the response.", |
| 89 | + s.stringEnum("One supported ChartMogul account setting include value.", [ |
| 90 | + "churn_recognition", |
| 91 | + "churn_when_zero_mrr", |
| 92 | + "auto_churn_subscription", |
| 93 | + "refund_handling", |
| 94 | + "proximate_movement_reclassification", |
| 95 | + ]), |
| 96 | + { minItems: 1 }, |
| 97 | + ), |
| 98 | + }, |
| 99 | + { optional: ["include"] }, |
| 100 | + ), |
| 101 | + outputSchema: s.object("The response returned when retrieving ChartMogul account details.", { |
| 102 | + account: accountSchema, |
| 103 | + }), |
| 104 | + }), |
| 105 | + defineProviderAction(service, { |
| 106 | + name: "list_sources", |
| 107 | + description: "List ChartMogul data sources with optional source name or billing system filters.", |
| 108 | + inputSchema: s.object( |
| 109 | + "Input parameters for listing ChartMogul data sources.", |
| 110 | + { |
| 111 | + name: s.nonEmptyString("The source name to filter by."), |
| 112 | + system: s.nonEmptyString("The billing system type to filter by, such as Stripe, Recurly, or Custom."), |
| 113 | + }, |
| 114 | + { optional: ["name", "system"] }, |
| 115 | + ), |
| 116 | + outputSchema: s.object("The response returned when listing ChartMogul data sources.", { |
| 117 | + dataSources: s.array("The data sources returned by ChartMogul.", dataSourceSchema), |
| 118 | + }), |
| 119 | + }), |
| 120 | + defineProviderAction(service, { |
| 121 | + name: "list_customers", |
| 122 | + description: "List ChartMogul customers with cursor pagination and common customer filters.", |
| 123 | + inputSchema: s.object( |
| 124 | + "Input parameters for listing ChartMogul customers.", |
| 125 | + { |
| 126 | + dataSourceUuid: s.nonEmptyString("The ChartMogul source UUID used to filter customers."), |
| 127 | + externalId: s.nonEmptyString("The external customer identifier to filter by."), |
| 128 | + email: s.nonEmptyString("The customer email address to search for."), |
| 129 | + withAssociatedEmails: s.boolean("Whether email search should also match associated contact email addresses."), |
| 130 | + status: s.nonEmptyString("The lead or subscription status to filter by."), |
| 131 | + system: s.nonEmptyString("The billing system to filter by, such as Stripe, Recurly, or Custom."), |
| 132 | + cursor: cursorSchema, |
| 133 | + perPage: perPageSchema, |
| 134 | + }, |
| 135 | + { |
| 136 | + optional: [ |
| 137 | + "dataSourceUuid", |
| 138 | + "externalId", |
| 139 | + "email", |
| 140 | + "withAssociatedEmails", |
| 141 | + "status", |
| 142 | + "system", |
| 143 | + "cursor", |
| 144 | + "perPage", |
| 145 | + ], |
| 146 | + }, |
| 147 | + ), |
| 148 | + outputSchema: s.object("The response returned when listing ChartMogul customers.", { |
| 149 | + customers: s.array("The customers returned by ChartMogul.", customerSchema), |
| 150 | + ...paginationOutputSchema, |
| 151 | + }), |
| 152 | + }), |
| 153 | + defineProviderAction(service, { |
| 154 | + name: "get_customer", |
| 155 | + description: "Retrieve a single ChartMogul customer by customer UUID.", |
| 156 | + inputSchema: s.object("Input parameters for retrieving a ChartMogul customer.", { |
| 157 | + customerUuid: customerUuidSchema, |
| 158 | + }), |
| 159 | + outputSchema: s.object("The response returned when retrieving a ChartMogul customer.", { |
| 160 | + customer: customerSchema, |
| 161 | + }), |
| 162 | + }), |
| 163 | + defineProviderAction(service, { |
| 164 | + name: "list_contacts", |
| 165 | + description: "List ChartMogul contacts with cursor pagination and common contact filters.", |
| 166 | + inputSchema: s.object( |
| 167 | + "Input parameters for listing ChartMogul contacts.", |
| 168 | + { |
| 169 | + email: s.nonEmptyString("The contact email address to filter by."), |
| 170 | + customerExternalId: s.nonEmptyString("The customer external identifier whose contacts should be returned."), |
| 171 | + customerUuid: customerUuidSchema, |
| 172 | + dataSourceUuid: s.nonEmptyString("The source UUID whose contacts should be returned."), |
| 173 | + cursor: cursorSchema, |
| 174 | + perPage: perPageSchema, |
| 175 | + }, |
| 176 | + { |
| 177 | + optional: ["email", "customerExternalId", "customerUuid", "dataSourceUuid", "cursor", "perPage"], |
| 178 | + }, |
| 179 | + ), |
| 180 | + outputSchema: s.object("The response returned when listing ChartMogul contacts.", { |
| 181 | + contacts: s.array("The contacts returned by ChartMogul.", contactSchema), |
| 182 | + ...paginationOutputSchema, |
| 183 | + }), |
| 184 | + }), |
| 185 | +]; |
| 186 | + |
| 187 | +export type ChartmogulActionName = "get_account" | "list_sources" | "list_customers" | "get_customer" | "list_contacts"; |
0 commit comments