@langwatch/server 3.1.0-beta.4 → 3.1.0-beta.6
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/langwatch/ee/admin/ImpersonationBanner.tsx +61 -0
- package/langwatch/ee/admin/ImpersonationSwitchBackMenuItem.tsx +30 -0
- package/langwatch/ee/admin/__tests__/ImpersonationBanner.integration.test.tsx +82 -0
- package/langwatch/ee/admin/__tests__/impersonation.service.unit.test.ts +231 -0
- package/langwatch/ee/admin/backoffice/BackofficeTable.tsx +200 -0
- package/langwatch/ee/admin/backoffice/__tests__/adminClient.unit.test.ts +147 -0
- package/langwatch/ee/admin/backoffice/__tests__/dateInputToISO.unit.test.ts +42 -0
- package/langwatch/ee/admin/backoffice/__tests__/userVisibility.unit.test.ts +174 -0
- package/langwatch/ee/admin/backoffice/adminClient.ts +114 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationFeaturesView.tsx +373 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationsView.tsx +677 -0
- package/langwatch/ee/admin/backoffice/resources/ProjectsView.tsx +647 -0
- package/langwatch/ee/admin/backoffice/resources/SubscriptionsView.tsx +628 -0
- package/langwatch/ee/admin/backoffice/resources/UsersView.tsx +556 -0
- package/langwatch/ee/admin/backoffice/useAdminResource.ts +104 -0
- package/langwatch/ee/admin/backoffice/userVisibility.ts +105 -0
- package/langwatch/ee/admin/impersonation.service.ts +170 -0
- package/langwatch/ee/admin/isAdmin.ts +9 -0
- package/langwatch/ee/admin/routes/admin.ts +531 -0
- package/langwatch/ee/admin/safeSelects.ts +64 -0
- package/langwatch/ee/billing/__tests__/customerService.unit.test.ts +183 -0
- package/langwatch/ee/billing/__tests__/growthSeatEvent.unit.test.ts +213 -0
- package/langwatch/ee/billing/__tests__/licensePurchaseHandler.unit.test.ts +250 -0
- package/langwatch/ee/billing/__tests__/notification.service.unit.test.ts +768 -0
- package/langwatch/ee/billing/__tests__/planLimits.unit.test.ts +19 -0
- package/langwatch/ee/billing/__tests__/planProvider.unit.test.ts +440 -0
- package/langwatch/ee/billing/__tests__/planTypes.unit.test.ts +32 -0
- package/langwatch/ee/billing/__tests__/pricing.unit.test.ts +54 -0
- package/langwatch/ee/billing/__tests__/seatEventSubscription.unit.test.ts +717 -0
- package/langwatch/ee/billing/__tests__/stripe.integration.test.ts +344 -0
- package/langwatch/ee/billing/__tests__/stripePrices.types.unit.test.ts +27 -0
- package/langwatch/ee/billing/__tests__/stripePricesLoader.unit.test.ts +72 -0
- package/langwatch/ee/billing/__tests__/subscription.service.unit.test.ts +730 -0
- package/langwatch/ee/billing/__tests__/subscriptionItemCalculator.unit.test.ts +176 -0
- package/langwatch/ee/billing/__tests__/usage-limit.service.unit.test.ts +706 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.integration.test.ts +421 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.unit.test.ts +515 -0
- package/langwatch/ee/billing/__tests__/webhookService.unit.test.ts +958 -0
- package/langwatch/ee/billing/currencyRouter.ts +18 -0
- package/langwatch/ee/billing/errors.ts +129 -0
- package/langwatch/ee/billing/index.ts +67 -0
- package/langwatch/ee/billing/middleware.ts +17 -0
- package/langwatch/ee/billing/notifications/notification.service.ts +651 -0
- package/langwatch/ee/billing/notifications/repositories/notification.repository.ts +51 -0
- package/langwatch/ee/billing/notifications/types.ts +9 -0
- package/langwatch/ee/billing/notifications/usage-limit.service.ts +622 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.ts +90 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.unit.test.ts +237 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.ts +120 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.unit.test.ts +324 -0
- package/langwatch/ee/billing/nurturing/hooks/index.ts +17 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.ts +68 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.unit.test.ts +138 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.integration.test.ts +288 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.ts +131 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.unit.test.ts +134 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.ts +101 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.unit.test.ts +317 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.ts +49 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.unit.test.ts +170 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.ts +143 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.unit.test.ts +307 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.ts +179 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.unit.test.ts +266 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.wiring.unit.test.ts +109 -0
- package/langwatch/ee/billing/nurturing/types.ts +125 -0
- package/langwatch/ee/billing/planLimits.ts +190 -0
- package/langwatch/ee/billing/planProvider.ts +119 -0
- package/langwatch/ee/billing/planTypes.ts +53 -0
- package/langwatch/ee/billing/pricing.ts +57 -0
- package/langwatch/ee/billing/services/billableEventsQuery.ts +248 -0
- package/langwatch/ee/billing/services/customerService.ts +90 -0
- package/langwatch/ee/billing/services/licensePurchaseHandler.ts +73 -0
- package/langwatch/ee/billing/services/seatEventSubscription.ts +351 -0
- package/langwatch/ee/billing/services/seatSyncService.ts +34 -0
- package/langwatch/ee/billing/services/subscription.repository.ts +203 -0
- package/langwatch/ee/billing/services/subscription.service.ts +549 -0
- package/langwatch/ee/billing/services/subscriptionItemCalculator.ts +249 -0
- package/langwatch/ee/billing/services/usageReportingService.ts +301 -0
- package/langwatch/ee/billing/services/webhookService.ts +858 -0
- package/langwatch/ee/billing/stripe/stripeCatalog.json +1781 -0
- package/langwatch/ee/billing/stripe/stripeClient.ts +13 -0
- package/langwatch/ee/billing/stripe/stripePriceCatalog.ts +70 -0
- package/langwatch/ee/billing/stripe/stripePrices.types.ts +118 -0
- package/langwatch/ee/billing/subscriptionRouter.ts +202 -0
- package/langwatch/ee/billing/types.ts +102 -0
- package/langwatch/ee/billing/utils/currency.ts +99 -0
- package/langwatch/ee/billing/utils/growthSeatEvent.ts +137 -0
- package/langwatch/ee/licensing/__tests__/constants.unit.test.ts +56 -0
- package/langwatch/ee/licensing/__tests__/defaults.unit.test.ts +192 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testKeys.ts +86 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testLicenses.ts +92 -0
- package/langwatch/ee/licensing/__tests__/licenseGenerationService.unit.test.ts +232 -0
- package/langwatch/ee/licensing/__tests__/licenseHandler.integration.test.ts +419 -0
- package/langwatch/ee/licensing/__tests__/planMapping.unit.test.ts +195 -0
- package/langwatch/ee/licensing/__tests__/planTemplates.unit.test.ts +193 -0
- package/langwatch/ee/licensing/__tests__/signing.unit.test.ts +164 -0
- package/langwatch/ee/licensing/__tests__/validation.unit.test.ts +281 -0
- package/langwatch/ee/licensing/client.ts +29 -0
- package/langwatch/ee/licensing/constants.ts +195 -0
- package/langwatch/ee/licensing/defaults.ts +55 -0
- package/langwatch/ee/licensing/errors.ts +11 -0
- package/langwatch/ee/licensing/index.ts +52 -0
- package/langwatch/ee/licensing/licenseGenerationService.ts +87 -0
- package/langwatch/ee/licensing/licenseHandler.ts +308 -0
- package/langwatch/ee/licensing/planInfo.ts +46 -0
- package/langwatch/ee/licensing/planMapping.ts +37 -0
- package/langwatch/ee/licensing/planTemplates.ts +109 -0
- package/langwatch/ee/licensing/server.ts +43 -0
- package/langwatch/ee/licensing/signing.ts +43 -0
- package/langwatch/ee/licensing/types.ts +156 -0
- package/langwatch/ee/licensing/validation.ts +107 -0
- package/langwatch/ee/managed-providers/ManagedModelProviderAlert.tsx +29 -0
- package/langwatch/ee/managed-providers/managedBedrockConfig.ts +226 -0
- package/langwatch/ee/saas/ExtraFooterComponents.tsx +169 -0
- package/langwatch/package.json +1 -1
- package/langwatch/pnpm-workspace.yaml +0 -1
- package/mcp-server/.env.example +2 -0
- package/mcp-server/.eslintrc.cjs +36 -0
- package/mcp-server/CHANGELOG.md +165 -0
- package/mcp-server/CONTRIBUTING.md +96 -0
- package/mcp-server/README.md +172 -0
- package/mcp-server/dist/archive-scenario-WJ2A7ETN.js +19 -0
- package/mcp-server/dist/archive-suite-4JOM4SSL.js +15 -0
- package/mcp-server/dist/assign-prompt-tag-GL7EAAF3.js +19 -0
- package/mcp-server/dist/chunk-2GT7IFWK.js +40 -0
- package/mcp-server/dist/chunk-2WPLXEKF.js +127 -0
- package/mcp-server/dist/chunk-4AUB2BIA.js +71 -0
- package/mcp-server/dist/chunk-BWWY5KEF.js +71 -0
- package/mcp-server/dist/chunk-CCWCIJJ3.js +22 -0
- package/mcp-server/dist/chunk-EGH5RPXM.js +25 -0
- package/mcp-server/dist/chunk-EUQDVOSU.js +39 -0
- package/mcp-server/dist/chunk-HYMIWO3U.js +44 -0
- package/mcp-server/dist/chunk-IE4M5OGE.js +42 -0
- package/mcp-server/dist/chunk-LUMEZEHL.js +48 -0
- package/mcp-server/dist/chunk-NUFPTHKU.js +9 -0
- package/mcp-server/dist/chunk-UDHJYT6P.js +1567 -0
- package/mcp-server/dist/chunk-WQG2DFHX.js +86 -0
- package/mcp-server/dist/chunk-WVI5CJ6S.js +21 -0
- package/mcp-server/dist/chunk-ZVS4UKN2.js +35 -0
- package/mcp-server/dist/chunk-ZXKLPC2E.js +27 -0
- package/mcp-server/dist/config.d.ts +17 -0
- package/mcp-server/dist/config.js +13 -0
- package/mcp-server/dist/create-agent-MBOOT3XK.js +23 -0
- package/mcp-server/dist/create-annotation-XMV6A7ED.js +24 -0
- package/mcp-server/dist/create-dashboard-VRKLFVZJ.js +18 -0
- package/mcp-server/dist/create-dataset-7HQPZCRE.js +22 -0
- package/mcp-server/dist/create-dataset-records-2NIVFYTV.js +22 -0
- package/mcp-server/dist/create-evaluator-WYFRFLRC.js +27 -0
- package/mcp-server/dist/create-mcp-server.d.ts +8 -0
- package/mcp-server/dist/create-mcp-server.js +8 -0
- package/mcp-server/dist/create-prompt-IEN7O6JT.js +39 -0
- package/mcp-server/dist/create-prompt-tag-CAEZ45VO.js +17 -0
- package/mcp-server/dist/create-scenario-6YHSMGLP.js +26 -0
- package/mcp-server/dist/create-suite-H5XOFDE5.js +38 -0
- package/mcp-server/dist/delete-agent-JKTNBWAA.js +18 -0
- package/mcp-server/dist/delete-annotation-ACMDV6QO.js +17 -0
- package/mcp-server/dist/delete-dashboard-VJSR7CRU.js +18 -0
- package/mcp-server/dist/delete-dataset-RTTTWP4D.js +20 -0
- package/mcp-server/dist/delete-dataset-records-KNQTIPQK.js +21 -0
- package/mcp-server/dist/delete-evaluator-7FVC5WM4.js +15 -0
- package/mcp-server/dist/delete-prompt-tag-ZMZUAGFW.js +17 -0
- package/mcp-server/dist/delete-workflow-EYQ3T4RQ.js +17 -0
- package/mcp-server/dist/discover-evaluator-schema-H23XCLNE.js +1402 -0
- package/mcp-server/dist/discover-scenario-schema-MEEEVND7.js +65 -0
- package/mcp-server/dist/discover-schema-3T52ORPB.js +446 -0
- package/mcp-server/dist/get-agent-E3QSTVKG.js +28 -0
- package/mcp-server/dist/get-analytics-2OHV763I.js +72 -0
- package/mcp-server/dist/get-dashboard-PC7JDHH6.js +29 -0
- package/mcp-server/dist/get-dataset-H5IK5FVU.js +48 -0
- package/mcp-server/dist/get-evaluator-UWVUPYTM.js +47 -0
- package/mcp-server/dist/get-prompt-WZUOLLQC.js +45 -0
- package/mcp-server/dist/get-scenario-Q6LCNUYN.js +33 -0
- package/mcp-server/dist/get-simulation-run-Z2XKO256.js +56 -0
- package/mcp-server/dist/get-suite-BXK5TN7P.js +44 -0
- package/mcp-server/dist/get-trace-4EJAYVBG.js +50 -0
- package/mcp-server/dist/get-workflow-O34QJLHD.js +25 -0
- package/mcp-server/dist/http-server-RSTXN4CN.js +224 -0
- package/mcp-server/dist/index.d.ts +2 -0
- package/mcp-server/dist/index.js +67774 -0
- package/mcp-server/dist/langwatch-api-annotations-ERBG27RF.js +17 -0
- package/mcp-server/dist/langwatch-api-dashboards-G6TR7VVO.js +17 -0
- package/mcp-server/dist/langwatch-api-monitors-WSXZLS2B.js +52 -0
- package/mcp-server/dist/langwatch-api-secrets-RR5DKG2X.js +40 -0
- package/mcp-server/dist/langwatch-api-triggers-2RTNSWQY.js +30 -0
- package/mcp-server/dist/langwatch-api-workflows-VJRIIDZ7.js +15 -0
- package/mcp-server/dist/list-agents-AW3P6FJV.js +32 -0
- package/mcp-server/dist/list-annotations-QNCGWPQ3.js +33 -0
- package/mcp-server/dist/list-dashboards-R7RK2IXL.js +32 -0
- package/mcp-server/dist/list-dataset-records-WVCSQP7P.js +39 -0
- package/mcp-server/dist/list-datasets-KEXRLDEU.js +60 -0
- package/mcp-server/dist/list-evaluators-7R2LB4JH.js +34 -0
- package/mcp-server/dist/list-model-providers-OBYJCKBX.js +35 -0
- package/mcp-server/dist/list-prompt-tags-6LY3ZPYI.js +23 -0
- package/mcp-server/dist/list-prompts-VWEZ4CDE.js +32 -0
- package/mcp-server/dist/list-scenarios-TXD4W2ZJ.js +40 -0
- package/mcp-server/dist/list-simulation-runs-RHPOLMFI.js +43 -0
- package/mcp-server/dist/list-suites-FSGBX27Z.js +42 -0
- package/mcp-server/dist/list-workflows-VRGEZ3EN.js +35 -0
- package/mcp-server/dist/rename-prompt-tag-VOJJLX4M.js +18 -0
- package/mcp-server/dist/run-agent-KTCC7TB7.js +36 -0
- package/mcp-server/dist/run-evaluation-2X3V3Q6L.js +64 -0
- package/mcp-server/dist/run-suite-BTMHGI2D.js +29 -0
- package/mcp-server/dist/run-workflow-IGAYGKJL.js +36 -0
- package/mcp-server/dist/search-traces-VYFUIMXH.js +72 -0
- package/mcp-server/dist/set-model-provider-W5IUI326.js +33 -0
- package/mcp-server/dist/update-agent-4BB7EYLR.js +20 -0
- package/mcp-server/dist/update-dataset-CXBKZ4W3.js +22 -0
- package/mcp-server/dist/update-dataset-record-HOHAMHXG.js +19 -0
- package/mcp-server/dist/update-evaluator-IVOR6FTR.js +24 -0
- package/mcp-server/dist/update-prompt-OWQAKE7K.js +24 -0
- package/mcp-server/dist/update-scenario-GDFVILPN.js +27 -0
- package/mcp-server/dist/update-suite-BXYUYSPT.js +39 -0
- package/mcp-server/package.json +79 -0
- package/mcp-server/pnpm-lock.yaml +6103 -0
- package/mcp-server/pnpm-workspace.yaml +2 -0
- package/mcp-server/pyproject.toml +17 -0
- package/mcp-server/src/__tests__/all-tools.integration.test.ts +1681 -0
- package/mcp-server/src/__tests__/config.unit.test.ts +169 -0
- package/mcp-server/src/__tests__/datasets.integration.test.ts +603 -0
- package/mcp-server/src/__tests__/datasets.unit.test.ts +240 -0
- package/mcp-server/src/__tests__/date-parsing.unit.test.ts +78 -0
- package/mcp-server/src/__tests__/discover-evaluator-schema.unit.test.ts +89 -0
- package/mcp-server/src/__tests__/discover-schema.unit.test.ts +118 -0
- package/mcp-server/src/__tests__/docker.integration.test.ts +234 -0
- package/mcp-server/src/__tests__/evaluator-tools.unit.test.ts +262 -0
- package/mcp-server/src/__tests__/http-transport.integration.test.ts +397 -0
- package/mcp-server/src/__tests__/integration.integration.test.ts +288 -0
- package/mcp-server/src/__tests__/langwatch-api.unit.test.ts +455 -0
- package/mcp-server/src/__tests__/model-provider-tools.unit.test.ts +190 -0
- package/mcp-server/src/__tests__/scenario-tools.integration.test.ts +286 -0
- package/mcp-server/src/__tests__/scenario-tools.unit.test.ts +185 -0
- package/mcp-server/src/__tests__/schemas.unit.test.ts +85 -0
- package/mcp-server/src/__tests__/tools.unit.test.ts +900 -0
- package/mcp-server/src/config.d.ts +15 -0
- package/mcp-server/src/config.ts +107 -0
- package/mcp-server/src/create-mcp-server.d.ts +6 -0
- package/mcp-server/src/create-mcp-server.ts +1799 -0
- package/mcp-server/src/http-server.ts +329 -0
- package/mcp-server/src/index.ts +46 -0
- package/mcp-server/src/langwatch-api-agents.ts +108 -0
- package/mcp-server/src/langwatch-api-annotations.ts +49 -0
- package/mcp-server/src/langwatch-api-dashboards.ts +48 -0
- package/mcp-server/src/langwatch-api-datasets.ts +191 -0
- package/mcp-server/src/langwatch-api-evaluators.ts +80 -0
- package/mcp-server/src/langwatch-api-model-providers.ts +41 -0
- package/mcp-server/src/langwatch-api-monitors.ts +82 -0
- package/mcp-server/src/langwatch-api-scenarios.ts +67 -0
- package/mcp-server/src/langwatch-api-secrets.ts +48 -0
- package/mcp-server/src/langwatch-api-simulation-runs.ts +51 -0
- package/mcp-server/src/langwatch-api-suites.ts +118 -0
- package/mcp-server/src/langwatch-api-triggers.ts +48 -0
- package/mcp-server/src/langwatch-api-workflows.ts +41 -0
- package/mcp-server/src/langwatch-api.ts +299 -0
- package/mcp-server/src/schemas/analytics-groups.ts +78 -0
- package/mcp-server/src/schemas/analytics-metrics.ts +179 -0
- package/mcp-server/src/schemas/create-dataset.ts +48 -0
- package/mcp-server/src/schemas/filter-fields.ts +119 -0
- package/mcp-server/src/schemas/index.ts +4 -0
- package/mcp-server/src/tools/archive-scenario.ts +19 -0
- package/mcp-server/src/tools/archive-suite.ts +12 -0
- package/mcp-server/src/tools/assign-prompt-tag.ts +16 -0
- package/mcp-server/src/tools/create-agent.ts +15 -0
- package/mcp-server/src/tools/create-annotation.ts +18 -0
- package/mcp-server/src/tools/create-dashboard.ts +7 -0
- package/mcp-server/src/tools/create-dataset-records.ts +23 -0
- package/mcp-server/src/tools/create-dataset.ts +22 -0
- package/mcp-server/src/tools/create-evaluator.ts +33 -0
- package/mcp-server/src/tools/create-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/create-prompt.ts +58 -0
- package/mcp-server/src/tools/create-scenario.ts +30 -0
- package/mcp-server/src/tools/create-suite.ts +42 -0
- package/mcp-server/src/tools/delete-agent.ts +7 -0
- package/mcp-server/src/tools/delete-annotation.ts +7 -0
- package/mcp-server/src/tools/delete-dashboard.ts +7 -0
- package/mcp-server/src/tools/delete-dataset-records.ts +22 -0
- package/mcp-server/src/tools/delete-dataset.ts +20 -0
- package/mcp-server/src/tools/delete-evaluator.ts +12 -0
- package/mcp-server/src/tools/delete-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/delete-workflow.ts +7 -0
- package/mcp-server/src/tools/discover-evaluator-schema.ts +143 -0
- package/mcp-server/src/tools/discover-scenario-schema.ts +71 -0
- package/mcp-server/src/tools/discover-schema.ts +106 -0
- package/mcp-server/src/tools/format-dataset-mutation.ts +25 -0
- package/mcp-server/src/tools/get-agent.ts +21 -0
- package/mcp-server/src/tools/get-analytics.ts +98 -0
- package/mcp-server/src/tools/get-dashboard.ts +22 -0
- package/mcp-server/src/tools/get-dataset.ts +63 -0
- package/mcp-server/src/tools/get-evaluator.ts +53 -0
- package/mcp-server/src/tools/get-prompt.ts +54 -0
- package/mcp-server/src/tools/get-scenario.ts +36 -0
- package/mcp-server/src/tools/get-simulation-run.ts +60 -0
- package/mcp-server/src/tools/get-suite.ts +47 -0
- package/mcp-server/src/tools/get-trace.ts +61 -0
- package/mcp-server/src/tools/get-workflow.ts +17 -0
- package/mcp-server/src/tools/list-agents.ts +27 -0
- package/mcp-server/src/tools/list-annotations.ts +33 -0
- package/mcp-server/src/tools/list-dashboards.ts +27 -0
- package/mcp-server/src/tools/list-dataset-records.ts +46 -0
- package/mcp-server/src/tools/list-datasets.ts +80 -0
- package/mcp-server/src/tools/list-evaluators.ts +37 -0
- package/mcp-server/src/tools/list-model-providers.ts +40 -0
- package/mcp-server/src/tools/list-prompt-tags.ts +21 -0
- package/mcp-server/src/tools/list-prompts.ts +34 -0
- package/mcp-server/src/tools/list-scenarios.ts +47 -0
- package/mcp-server/src/tools/list-simulation-runs.ts +49 -0
- package/mcp-server/src/tools/list-suites.ts +43 -0
- package/mcp-server/src/tools/list-workflows.ts +31 -0
- package/mcp-server/src/tools/rename-prompt-tag.ts +14 -0
- package/mcp-server/src/tools/run-agent.ts +36 -0
- package/mcp-server/src/tools/run-evaluation.ts +87 -0
- package/mcp-server/src/tools/run-suite.ts +28 -0
- package/mcp-server/src/tools/run-workflow.ts +36 -0
- package/mcp-server/src/tools/search-traces.ts +91 -0
- package/mcp-server/src/tools/set-model-provider.ts +46 -0
- package/mcp-server/src/tools/update-agent.ts +13 -0
- package/mcp-server/src/tools/update-dataset-record.ts +21 -0
- package/mcp-server/src/tools/update-dataset.ts +23 -0
- package/mcp-server/src/tools/update-evaluator.ts +30 -0
- package/mcp-server/src/tools/update-prompt.ts +31 -0
- package/mcp-server/src/tools/update-scenario.ts +32 -0
- package/mcp-server/src/tools/update-suite.ts +44 -0
- package/mcp-server/src/utils/date-parsing.ts +31 -0
- package/mcp-server/src/utils/escape-markdown.ts +12 -0
- package/mcp-server/tsconfig.json +27 -0
- package/mcp-server/uv.lock +2731 -0
- package/package.json +2 -1
- package/packages/server/dist/cli.cjs +1 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { createLogger } from "../../../src/utils/logger/server";
|
|
2
|
+
import { captureException } from "../../../src/utils/posthogErrorCapture";
|
|
3
|
+
import type { AppConfig } from "../../../src/server/app-layer/config";
|
|
4
|
+
import type {
|
|
5
|
+
CioBatchCall,
|
|
6
|
+
CioEventName,
|
|
7
|
+
CioOrgTraits,
|
|
8
|
+
CioPersonTraits,
|
|
9
|
+
} from "./types";
|
|
10
|
+
|
|
11
|
+
const logger = createLogger("ee:nurturing-service");
|
|
12
|
+
|
|
13
|
+
const EXTERNAL_SERVICE_TIMEOUT_MS = 10_000;
|
|
14
|
+
|
|
15
|
+
const REGIONAL_ENDPOINTS = {
|
|
16
|
+
us: "https://cdp.customer.io/v1",
|
|
17
|
+
eu: "https://cdp-eu.customer.io/v1",
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
type Region = keyof typeof REGIONAL_ENDPOINTS;
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Options
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
export type NurturingServiceOptions = {
|
|
27
|
+
config: Pick<AppConfig, "customerIoApiKey" | "customerIoRegion">;
|
|
28
|
+
fetchFn?: typeof fetch;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// NurturingService — Customer.io Pipelines API client
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Wraps the Customer.io Pipelines API with fire-and-forget semantics.
|
|
37
|
+
*
|
|
38
|
+
* Callers use optional chaining (`nurturing?.identifyUser(...)`) when the
|
|
39
|
+
* service may be absent (e.g. self-hosted without Customer.io).
|
|
40
|
+
* Defense-in-depth: methods silently no-op if the API key is missing.
|
|
41
|
+
*/
|
|
42
|
+
export class NurturingService {
|
|
43
|
+
private readonly apiKey: string | undefined;
|
|
44
|
+
private readonly baseUrl: string;
|
|
45
|
+
private readonly fetchFn: typeof fetch;
|
|
46
|
+
|
|
47
|
+
private constructor(options: NurturingServiceOptions) {
|
|
48
|
+
this.apiKey = options.config.customerIoApiKey;
|
|
49
|
+
const region = options.config.customerIoRegion;
|
|
50
|
+
this.baseUrl =
|
|
51
|
+
region && region in REGIONAL_ENDPOINTS
|
|
52
|
+
? REGIONAL_ENDPOINTS[region as Region]
|
|
53
|
+
: REGIONAL_ENDPOINTS.eu;
|
|
54
|
+
this.fetchFn =
|
|
55
|
+
options.fetchFn ?? ((...args) => fetch(...args)) as typeof fetch;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Factory method for creating a NurturingService.
|
|
60
|
+
* If the API key is falsy, all methods behave as silent no-ops.
|
|
61
|
+
*/
|
|
62
|
+
static create(options: NurturingServiceOptions): NurturingService {
|
|
63
|
+
return new NurturingService(options);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// -------------------------------------------------------------------------
|
|
67
|
+
// Public API
|
|
68
|
+
// -------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
/** Identify a user with person-level traits in Customer.io. */
|
|
71
|
+
async identifyUser({
|
|
72
|
+
userId,
|
|
73
|
+
traits,
|
|
74
|
+
}: {
|
|
75
|
+
userId: string;
|
|
76
|
+
traits: Partial<CioPersonTraits>;
|
|
77
|
+
}): Promise<void> {
|
|
78
|
+
await this.post("/identify", { userId, traits });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Track a named event for a user in Customer.io. */
|
|
82
|
+
async trackEvent({
|
|
83
|
+
userId,
|
|
84
|
+
event,
|
|
85
|
+
properties,
|
|
86
|
+
}: {
|
|
87
|
+
userId: string;
|
|
88
|
+
event: CioEventName;
|
|
89
|
+
properties?: Record<string, unknown>;
|
|
90
|
+
}): Promise<void> {
|
|
91
|
+
await this.post("/track", { userId, event, properties });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Associate a user with an organization (group) in Customer.io. */
|
|
95
|
+
async groupUser({
|
|
96
|
+
userId,
|
|
97
|
+
groupId,
|
|
98
|
+
traits,
|
|
99
|
+
}: {
|
|
100
|
+
userId: string;
|
|
101
|
+
groupId: string;
|
|
102
|
+
traits?: Partial<CioOrgTraits>;
|
|
103
|
+
}): Promise<void> {
|
|
104
|
+
await this.post("/group", { userId, groupId, traits });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Send multiple operations in a single batch request. */
|
|
108
|
+
async batch(calls: CioBatchCall[]): Promise<void> {
|
|
109
|
+
const batchItems = calls.map((call) => {
|
|
110
|
+
switch (call.type) {
|
|
111
|
+
case "identify":
|
|
112
|
+
return { type: "identify", userId: call.userId, traits: call.traits };
|
|
113
|
+
case "track":
|
|
114
|
+
return {
|
|
115
|
+
type: "track",
|
|
116
|
+
userId: call.userId,
|
|
117
|
+
event: call.event,
|
|
118
|
+
properties: call.properties,
|
|
119
|
+
};
|
|
120
|
+
case "group":
|
|
121
|
+
return {
|
|
122
|
+
type: "group",
|
|
123
|
+
userId: call.userId,
|
|
124
|
+
groupId: call.groupId,
|
|
125
|
+
traits: call.traits,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
await this.post("/batch", { batch: batchItems });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// -------------------------------------------------------------------------
|
|
133
|
+
// Internal
|
|
134
|
+
// -------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
private async post(path: string, body: unknown): Promise<void> {
|
|
137
|
+
if (!this.apiKey) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const url = `${this.baseUrl}${path}`;
|
|
142
|
+
|
|
143
|
+
const controller = new AbortController();
|
|
144
|
+
const timeoutId = setTimeout(
|
|
145
|
+
() => controller.abort(),
|
|
146
|
+
EXTERNAL_SERVICE_TIMEOUT_MS,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const response = await this.fetchFn(url, {
|
|
151
|
+
method: "POST",
|
|
152
|
+
headers: {
|
|
153
|
+
"Content-Type": "application/json",
|
|
154
|
+
Authorization:
|
|
155
|
+
"Basic " + Buffer.from(`${this.apiKey}:`).toString("base64"),
|
|
156
|
+
},
|
|
157
|
+
body: JSON.stringify(body),
|
|
158
|
+
signal: controller.signal,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
if (!response.ok) {
|
|
162
|
+
const responseBody = await response.text().catch(() => "<unreadable>");
|
|
163
|
+
logger.error(
|
|
164
|
+
{ path, status: response.status, responseBody: responseBody.slice(0, 500) },
|
|
165
|
+
`[CIO] <<< ${path} FAILED: HTTP ${response.status}`,
|
|
166
|
+
);
|
|
167
|
+
captureException(
|
|
168
|
+
new Error(`Customer.io ${path} failed: HTTP ${response.status}`),
|
|
169
|
+
{ extra: { path, status: response.status } },
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
logger.error({ error, path }, `[CIO] <<< ${path} EXCEPTION`);
|
|
174
|
+
captureException(error);
|
|
175
|
+
} finally {
|
|
176
|
+
clearTimeout(timeoutId);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { beforeEach, describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { NurturingService } from "./nurturing.service";
|
|
3
|
+
import type { CioBatchCall } from "./types";
|
|
4
|
+
|
|
5
|
+
// Suppress logger output and captureException in tests
|
|
6
|
+
vi.mock("../../../src/utils/logger/server", () => ({
|
|
7
|
+
createLogger: () => ({
|
|
8
|
+
info: vi.fn(),
|
|
9
|
+
warn: vi.fn(),
|
|
10
|
+
error: vi.fn(),
|
|
11
|
+
debug: vi.fn(),
|
|
12
|
+
}),
|
|
13
|
+
}));
|
|
14
|
+
vi.mock("../../../src/utils/posthogErrorCapture", () => ({
|
|
15
|
+
captureException: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function createMockFetch(
|
|
23
|
+
response: Partial<Response> = { ok: true, status: 200 },
|
|
24
|
+
) {
|
|
25
|
+
return vi.fn().mockResolvedValue(response);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createService({
|
|
29
|
+
apiKey = "test-api-key",
|
|
30
|
+
region = "us" as "us" | "eu",
|
|
31
|
+
fetchFn = createMockFetch(),
|
|
32
|
+
} = {}) {
|
|
33
|
+
return {
|
|
34
|
+
service: NurturingService.create({
|
|
35
|
+
config: { customerIoApiKey: apiKey, customerIoRegion: region },
|
|
36
|
+
fetchFn,
|
|
37
|
+
}),
|
|
38
|
+
fetchFn,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("NurturingService", () => {
|
|
43
|
+
describe("identifyUser()", () => {
|
|
44
|
+
describe("when created with an API key and region 'us'", () => {
|
|
45
|
+
it("sends HTTP request to cdp.customer.io/v1/identify with Basic Auth", async () => {
|
|
46
|
+
const { service, fetchFn } = createService();
|
|
47
|
+
|
|
48
|
+
await service.identifyUser({ userId: "user-123", traits: { email: "test@example.com" } });
|
|
49
|
+
|
|
50
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
51
|
+
const [url, options] = fetchFn.mock.calls[0]!;
|
|
52
|
+
expect(url).toBe("https://cdp.customer.io/v1/identify");
|
|
53
|
+
expect(options.method).toBe("POST");
|
|
54
|
+
|
|
55
|
+
const authHeader = options.headers["Authorization"];
|
|
56
|
+
const expectedAuth =
|
|
57
|
+
"Basic " + Buffer.from("test-api-key:").toString("base64");
|
|
58
|
+
expect(authHeader).toBe(expectedAuth);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("includes user ID and traits in the request body", async () => {
|
|
62
|
+
const { service, fetchFn } = createService();
|
|
63
|
+
|
|
64
|
+
await service.identifyUser({ userId: "user-123", traits: {
|
|
65
|
+
email: "test@example.com",
|
|
66
|
+
name: "Jane Doe",
|
|
67
|
+
}});
|
|
68
|
+
|
|
69
|
+
const body = JSON.parse(fetchFn.mock.calls[0]![1].body);
|
|
70
|
+
expect(body).toEqual({
|
|
71
|
+
userId: "user-123",
|
|
72
|
+
traits: { email: "test@example.com", name: "Jane Doe" },
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("when created with region 'eu'", () => {
|
|
78
|
+
it("sends request to cdp-eu.customer.io/v1/identify", async () => {
|
|
79
|
+
const { service, fetchFn } = createService({ region: "eu" });
|
|
80
|
+
|
|
81
|
+
await service.identifyUser({ userId: "user-123", traits: { email: "test@example.com" } });
|
|
82
|
+
|
|
83
|
+
const [url] = fetchFn.mock.calls[0]!;
|
|
84
|
+
expect(url).toBe("https://cdp-eu.customer.io/v1/identify");
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("trackEvent()", () => {
|
|
90
|
+
describe("when called with user ID, event name, and properties", () => {
|
|
91
|
+
it("sends event payload to the track endpoint", async () => {
|
|
92
|
+
const { service, fetchFn } = createService();
|
|
93
|
+
|
|
94
|
+
await service.trackEvent({ userId: "user-123", event: "signed_up", properties: {
|
|
95
|
+
role: "engineer",
|
|
96
|
+
}});
|
|
97
|
+
|
|
98
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
99
|
+
const [url, options] = fetchFn.mock.calls[0]!;
|
|
100
|
+
expect(url).toBe("https://cdp.customer.io/v1/track");
|
|
101
|
+
expect(options.method).toBe("POST");
|
|
102
|
+
|
|
103
|
+
const body = JSON.parse(options.body);
|
|
104
|
+
expect(body).toEqual({
|
|
105
|
+
userId: "user-123",
|
|
106
|
+
event: "signed_up",
|
|
107
|
+
properties: { role: "engineer" },
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("groupUser()", () => {
|
|
114
|
+
describe("when called with user ID, group ID, and org traits", () => {
|
|
115
|
+
it("sends org traits to the group endpoint", async () => {
|
|
116
|
+
const { service, fetchFn } = createService();
|
|
117
|
+
|
|
118
|
+
await service.groupUser({ userId: "user-123", groupId: "org-456", traits: {
|
|
119
|
+
name: "Acme Corp",
|
|
120
|
+
plan: "free",
|
|
121
|
+
}});
|
|
122
|
+
|
|
123
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
124
|
+
const [url, options] = fetchFn.mock.calls[0]!;
|
|
125
|
+
expect(url).toBe("https://cdp.customer.io/v1/group");
|
|
126
|
+
expect(options.method).toBe("POST");
|
|
127
|
+
|
|
128
|
+
const body = JSON.parse(options.body);
|
|
129
|
+
expect(body).toEqual({
|
|
130
|
+
userId: "user-123",
|
|
131
|
+
groupId: "org-456",
|
|
132
|
+
traits: { name: "Acme Corp", plan: "free" },
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("batch()", () => {
|
|
139
|
+
describe("when called with multiple identify and track calls", () => {
|
|
140
|
+
it("sends a single HTTP request to the batch endpoint containing all calls", async () => {
|
|
141
|
+
const { service, fetchFn } = createService();
|
|
142
|
+
|
|
143
|
+
const calls: CioBatchCall[] = [
|
|
144
|
+
{
|
|
145
|
+
type: "identify",
|
|
146
|
+
userId: "user-1",
|
|
147
|
+
traits: { email: "a@b.com" },
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
type: "track",
|
|
151
|
+
userId: "user-1",
|
|
152
|
+
event: "signed_up",
|
|
153
|
+
properties: { role: "admin" },
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
type: "group",
|
|
157
|
+
userId: "user-1",
|
|
158
|
+
groupId: "org-1",
|
|
159
|
+
traits: { name: "Org" },
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
await service.batch(calls);
|
|
164
|
+
|
|
165
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
166
|
+
const [url, options] = fetchFn.mock.calls[0]!;
|
|
167
|
+
expect(url).toBe("https://cdp.customer.io/v1/batch");
|
|
168
|
+
expect(options.method).toBe("POST");
|
|
169
|
+
|
|
170
|
+
const body = JSON.parse(options.body);
|
|
171
|
+
expect(body).toEqual({
|
|
172
|
+
batch: [
|
|
173
|
+
{
|
|
174
|
+
type: "identify",
|
|
175
|
+
userId: "user-1",
|
|
176
|
+
traits: { email: "a@b.com" },
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
type: "track",
|
|
180
|
+
userId: "user-1",
|
|
181
|
+
event: "signed_up",
|
|
182
|
+
properties: { role: "admin" },
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
type: "group",
|
|
186
|
+
userId: "user-1",
|
|
187
|
+
groupId: "org-1",
|
|
188
|
+
traits: { name: "Org" },
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("when the Customer.io API does not respond within 10 seconds", () => {
|
|
197
|
+
it("aborts the request", async () => {
|
|
198
|
+
const { captureException } = await import(
|
|
199
|
+
"../../../src/utils/posthogErrorCapture"
|
|
200
|
+
);
|
|
201
|
+
const slowFetch = vi.fn().mockImplementation((_url, options) => {
|
|
202
|
+
return new Promise((_resolve, reject) => {
|
|
203
|
+
// Simulate the abort signal triggering
|
|
204
|
+
if (options?.signal) {
|
|
205
|
+
options.signal.addEventListener("abort", () => {
|
|
206
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const service = NurturingService.create({
|
|
213
|
+
config: { customerIoApiKey: "key", customerIoRegion: "us" },
|
|
214
|
+
fetchFn: slowFetch as unknown as typeof fetch,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Use fake timers to trigger the timeout immediately
|
|
218
|
+
vi.useFakeTimers();
|
|
219
|
+
const promise = service.identifyUser({ userId: "user-1", traits: { email: "a@b.com" } });
|
|
220
|
+
vi.advanceTimersByTime(10_000);
|
|
221
|
+
await promise;
|
|
222
|
+
vi.useRealTimers();
|
|
223
|
+
|
|
224
|
+
expect(captureException).toHaveBeenCalled();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("when the Customer.io API returns a 500 error", () => {
|
|
229
|
+
it("resolves without throwing", async () => {
|
|
230
|
+
const { service } = createService({
|
|
231
|
+
fetchFn: createMockFetch({ ok: false, status: 500 }),
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
await expect(
|
|
235
|
+
service.identifyUser({ userId: "user-123", traits: { email: "test@example.com" } }),
|
|
236
|
+
).resolves.toBeUndefined();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("captures the error for observability", async () => {
|
|
240
|
+
const { captureException } = await import(
|
|
241
|
+
"../../../src/utils/posthogErrorCapture"
|
|
242
|
+
);
|
|
243
|
+
const { service } = createService({
|
|
244
|
+
fetchFn: createMockFetch({ ok: false, status: 500 }),
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await service.identifyUser({ userId: "user-123", traits: { email: "test@example.com" } });
|
|
248
|
+
|
|
249
|
+
expect(captureException).toHaveBeenCalled();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe("when created with a falsy API key", () => {
|
|
254
|
+
it("behaves as a no-op without making HTTP requests", async () => {
|
|
255
|
+
const fetchFn = createMockFetch();
|
|
256
|
+
const service = NurturingService.create({
|
|
257
|
+
config: { customerIoApiKey: undefined, customerIoRegion: "us" },
|
|
258
|
+
fetchFn,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
await service.identifyUser({ userId: "user-123", traits: { email: "test@example.com" } });
|
|
262
|
+
|
|
263
|
+
expect(fetchFn).not.toHaveBeenCalled();
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { NurturingService } from "./nurturing.service";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wiring unit tests for NurturingService app construction patterns.
|
|
6
|
+
*
|
|
7
|
+
* These test the service construction patterns that presets.ts uses
|
|
8
|
+
* without importing the full App dependency graph (which requires
|
|
9
|
+
* generated Prisma/ES types). The actual wiring in presets.ts follows
|
|
10
|
+
* the same pattern tested here.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Suppress logger and captureException
|
|
14
|
+
vi.mock("../../../src/utils/logger/server", () => ({
|
|
15
|
+
createLogger: () => ({
|
|
16
|
+
info: vi.fn(),
|
|
17
|
+
warn: vi.fn(),
|
|
18
|
+
error: vi.fn(),
|
|
19
|
+
debug: vi.fn(),
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
22
|
+
vi.mock("../../../src/utils/posthogErrorCapture", () => ({
|
|
23
|
+
captureException: vi.fn(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
describe("NurturingService app wiring", () => {
|
|
27
|
+
describe("when the app config includes a customerIoApiKey", () => {
|
|
28
|
+
it("creates an active NurturingService instance", () => {
|
|
29
|
+
const service = NurturingService.create({
|
|
30
|
+
config: {
|
|
31
|
+
customerIoApiKey: "test-key",
|
|
32
|
+
customerIoRegion: "us",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(service).toBeInstanceOf(NurturingService);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("makes HTTP requests when methods are called", async () => {
|
|
40
|
+
const fetchFn = vi.fn<typeof fetch>().mockResolvedValue(
|
|
41
|
+
new Response(null, { status: 200 }),
|
|
42
|
+
);
|
|
43
|
+
const service = NurturingService.create({
|
|
44
|
+
config: { customerIoApiKey: "test-key", customerIoRegion: "us" },
|
|
45
|
+
fetchFn,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await service.identifyUser({ userId: "user-1", traits: { email: "a@b.com" } });
|
|
49
|
+
|
|
50
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("when the app config has no customerIoApiKey", () => {
|
|
55
|
+
it("produces undefined (no service created)", () => {
|
|
56
|
+
// This mirrors what presets.ts does: undefined when no API key
|
|
57
|
+
const apiKey: string | undefined = undefined;
|
|
58
|
+
const nurturing = apiKey
|
|
59
|
+
? NurturingService.create({
|
|
60
|
+
config: { customerIoApiKey: apiKey, customerIoRegion: "us" },
|
|
61
|
+
})
|
|
62
|
+
: undefined;
|
|
63
|
+
|
|
64
|
+
expect(nurturing).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("when the app config has no customerIoRegion", () => {
|
|
69
|
+
it("defaults to the EU regional endpoint", async () => {
|
|
70
|
+
const fetchFn = vi.fn<typeof fetch>().mockResolvedValue(
|
|
71
|
+
new Response(null, { status: 200 }),
|
|
72
|
+
);
|
|
73
|
+
const service = NurturingService.create({
|
|
74
|
+
config: { customerIoApiKey: "key", customerIoRegion: undefined },
|
|
75
|
+
fetchFn,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await service.identifyUser({ userId: "user-1", traits: { email: "a@b.com" } });
|
|
79
|
+
|
|
80
|
+
const [url] = fetchFn.mock.calls[0]!;
|
|
81
|
+
expect(url).toContain("cdp-eu.customer.io");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("when createTestApp is called", () => {
|
|
86
|
+
it("nurturing is undefined (no service in tests)", () => {
|
|
87
|
+
// createTestApp() passes nurturing: undefined
|
|
88
|
+
const nurturing: NurturingService | undefined = undefined;
|
|
89
|
+
expect(nurturing).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("when region is set to 'eu'", () => {
|
|
94
|
+
it("routes requests to the EU endpoint", async () => {
|
|
95
|
+
const fetchFn = vi.fn<typeof fetch>().mockResolvedValue(
|
|
96
|
+
new Response(null, { status: 200 }),
|
|
97
|
+
);
|
|
98
|
+
const service = NurturingService.create({
|
|
99
|
+
config: { customerIoApiKey: "key", customerIoRegion: "eu" },
|
|
100
|
+
fetchFn,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
await service.identifyUser({ userId: "user-1", traits: { email: "a@b.com" } });
|
|
104
|
+
|
|
105
|
+
const [url] = fetchFn.mock.calls[0]!;
|
|
106
|
+
expect(url).toContain("cdp-eu.customer.io");
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer.io trait schema contract.
|
|
3
|
+
*
|
|
4
|
+
* Defines the complete data model pushed to Customer.io by reactors and hooks.
|
|
5
|
+
* All call sites use these typed parameters instead of ad-hoc Record<string, unknown>.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Person traits (via /identify)
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
export interface CioPersonTraits {
|
|
13
|
+
// Onboarding
|
|
14
|
+
email: string;
|
|
15
|
+
name: string;
|
|
16
|
+
role: string;
|
|
17
|
+
company_size: string;
|
|
18
|
+
signup_usage: string;
|
|
19
|
+
signup_solution: string;
|
|
20
|
+
signup_feature_usage: string;
|
|
21
|
+
utm_campaign: string;
|
|
22
|
+
how_heard: string;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
integration_method: string;
|
|
25
|
+
|
|
26
|
+
// Attribution (first-touch URL params — captured client-side, forwarded
|
|
27
|
+
// via signUpData). Optional because callers always use
|
|
28
|
+
// `Partial<CioPersonTraits>` and set them conditionally; marking them
|
|
29
|
+
// required would lie about the runtime contract.
|
|
30
|
+
lead_source?: string;
|
|
31
|
+
utm_source?: string;
|
|
32
|
+
utm_medium?: string;
|
|
33
|
+
utm_term?: string;
|
|
34
|
+
utm_content?: string;
|
|
35
|
+
referrer?: string;
|
|
36
|
+
|
|
37
|
+
// Trace milestones (customerIoTraceSync reactor)
|
|
38
|
+
has_traces: boolean;
|
|
39
|
+
sdk_language: string;
|
|
40
|
+
sdk_framework: string;
|
|
41
|
+
first_trace_at: string;
|
|
42
|
+
trace_count: number;
|
|
43
|
+
daily_trace_count: number;
|
|
44
|
+
last_trace_at: string;
|
|
45
|
+
trace_count_updated_at: string;
|
|
46
|
+
|
|
47
|
+
// Evaluation milestones (customerIoEvaluationSync reactor)
|
|
48
|
+
has_evaluations: boolean;
|
|
49
|
+
evaluation_count: number;
|
|
50
|
+
first_evaluation_at: string;
|
|
51
|
+
last_evaluation_at: string;
|
|
52
|
+
|
|
53
|
+
// Prompt milestones (prompt creation hook)
|
|
54
|
+
has_prompts: boolean;
|
|
55
|
+
prompt_count: number;
|
|
56
|
+
|
|
57
|
+
// Simulation milestones (customerIoSimulationSync reactor)
|
|
58
|
+
has_simulations: boolean;
|
|
59
|
+
simulation_count: number;
|
|
60
|
+
first_simulation_at: string;
|
|
61
|
+
last_simulation_at: string;
|
|
62
|
+
|
|
63
|
+
// Feature adoption
|
|
64
|
+
team_member_count: number;
|
|
65
|
+
workflow_count: number;
|
|
66
|
+
scenario_count: number;
|
|
67
|
+
|
|
68
|
+
// Activity tracking
|
|
69
|
+
last_active_at: string;
|
|
70
|
+
|
|
71
|
+
// Billing
|
|
72
|
+
plan: string;
|
|
73
|
+
has_subscription: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// Organization traits (via /group)
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
export interface CioOrgTraits {
|
|
81
|
+
name: string;
|
|
82
|
+
plan: string;
|
|
83
|
+
company_size: string;
|
|
84
|
+
member_count: number;
|
|
85
|
+
project_count: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Event names (via /track)
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
export type CioEventName =
|
|
93
|
+
| "signed_up"
|
|
94
|
+
| "first_trace_integrated"
|
|
95
|
+
| "first_evaluation_created"
|
|
96
|
+
| "evaluation_ran"
|
|
97
|
+
| "scenario_created"
|
|
98
|
+
| "team_member_invited"
|
|
99
|
+
| "workflow_created"
|
|
100
|
+
| "experiment_ran"
|
|
101
|
+
| "first_prompt_created"
|
|
102
|
+
| "first_simulation_ran";
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Batch call discriminated union
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
export type CioBatchCall =
|
|
109
|
+
| {
|
|
110
|
+
type: "identify";
|
|
111
|
+
userId: string;
|
|
112
|
+
traits: Partial<CioPersonTraits>;
|
|
113
|
+
}
|
|
114
|
+
| {
|
|
115
|
+
type: "track";
|
|
116
|
+
userId: string;
|
|
117
|
+
event: CioEventName;
|
|
118
|
+
properties?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
type: "group";
|
|
122
|
+
userId: string;
|
|
123
|
+
groupId: string;
|
|
124
|
+
traits?: Partial<CioOrgTraits>;
|
|
125
|
+
};
|