Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(devex): use the generated api clients in workflows (#104678)

Julian Bezb4ed4b3fac12
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 8bcd4fcb888d..c1a7ff60b1a5 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6069,9 +6069,9 @@ snapshots:
products-data-modeling-model-downstream-summary--one-dependent-model--light:
hash: v1.k794b7964.3781c6628ca1661df8c04dca9810e60e506339605cc7cf450c92f04d192e8e43.VSEp-9GtYN9N2rEpDX857fuikGwj_Te0u8y5aEqi_vs
products-data-modeling-model-health-summary--completed--dark:
- hash: v1.k794b7964.9cc469bbaef73328746c4ac6e81de0642d88ef96873576cfade18a4b6e9286e0.X8VeEn2p1rOdvI_CdJ1LAN_0-Qu_dtlRx1uQlE7t_Oc
+ hash: v1.k794b7964.37f90f8bf20aa47e3abe005ab74bbb47fd9c475f491c1e0ddd942de6190f1600.MlhUcwji0tVk-RlGO9kEU_qNp9XChA3u33WJvlsPwJw
products-data-modeling-model-health-summary--completed--light:
- hash: v1.k794b7964.4de53541f1249d0fb5beb418d582c65cda06eb36176807b4106bdf2bf3ed8a89.VyuxhEpCuUGzcKDXqjagV_YMAaeEkbXBIJEzOXHYGH4
+ hash: v1.k794b7964.9d66a078564dcd91717204e4e611b9023095765364e39bb77c6410e1c0d0b5a1.aFGNDXJzk5EmeMNPPEFYQ8meHG8uXmxEL8HSGBau_ms
products-data-modeling-model-health-summary--failed--dark:
hash: v1.k794b7964.6430f3b47e258c4782cdbe6bca02dda179bd44c7c19a8a5e21bfff8f67189499.2uOe1596jH8GT3dlzMThKIxl7XUOl7pj7GbwpkXF7V4
products-data-modeling-model-health-summary--failed--light:
@@ -6093,9 +6093,9 @@ snapshots:
products-data-modeling-model-health-summary--narrow--light:
hash: v1.k794b7964.e21979877fbe3c641b5fcf07731626126b51cb13b0feb652eae14c806850addf.qPtHjCRtiajbTPO_yDTncVlCGwwexFfGu-6k4ZR_F8s
products-data-modeling-model-health-summary--running--dark:
- hash: v1.k794b7964.3d5813d589d6df8c849d1d0ecb3c4feadb34d7e48a190c6a7fed5ccb0b27848c.PBT6ffPfT9Cr_-ee_IJllSy3kmYQxuyCT_7pQCP2vDw
+ hash: v1.k794b7964.83c9543f9bc40e36071f0dc344675b287a2179027e88e4520f8056cde875666f.gzrK5E9tPU2RGly5TdWZmSpQUM6pUq_MnK4WAONEwMg
products-data-modeling-model-health-summary--running--light:
- hash: v1.k794b7964.467fc05c1d1434d678fabaa13455ddc7110d3c533afb867207ae6b1b05f64f4f.c7PSGKdTA0iHiz0VY_y8oZxDHeTfpCUSVohNEUubBhI
+ hash: v1.k794b7964.42042eee92aa9bc545fbac2570739a63c404238b6ef465bdb2cbf593c0bdee9a.tyvrOO1wKhlPLl_M7D1h6Va7vF9P46ceZViYJkmrK4s
products-data-modeling-model-health-summary--stale-history--dark:
hash: v1.k794b7964.fd37a8315fdd454d5e99c5cc201ac820390eca6c86246e51cba727f92cb521ad.rqM1As_QJVVWqDUhfq9umFTTTbY8lUueR-EZbe0Y8CU
products-data-modeling-model-health-summary--stale-history--light:
diff --git a/frontend/src/lib/api-ratchet-baseline.txt b/frontend/src/lib/api-ratchet-baseline.txt
index 5443d8edc068..cfb70d380823 100644
--- a/frontend/src/lib/api-ratchet-baseline.txt
+++ b/frontend/src/lib/api-ratchet-baseline.txt
@@ -191,10 +191,7 @@ messagingCategoriesRemoveTrackConfig projects/{}/messaging_categories/remove_tra
messagingCategoriesRemoveWebhookConfig projects/{}/messaging_categories/remove_webhook_config
messagingCategoriesSaveTrackConfig projects/{}/messaging_categories/save_track_config
messagingCategoriesSaveWebhookConfig projects/{}/messaging_categories/save_webhook_config
-messagingCategory projects/{}/messaging_categories/{}
-messagingPreferencesBulkAddOptOuts projects/{}/messaging_preferences/bulk_add_opt_outs
messagingPreferencesExportOptOutsCsv projects/{}/messaging_preferences/export_opt_outs_csv
-messagingPreferencesLink projects/{}/messaging_preferences/generate_link
messagingTemplate projects/{}/messaging_templates/{}
messagingTemplates projects/{}/messaging_templates
notebook projects/{}/notebooks/{}
diff --git a/frontend/src/lib/api.test.ts b/frontend/src/lib/api.test.ts
index 468d7c83581c..f844e6b4ebb8 100644
--- a/frontend/src/lib/api.test.ts
+++ b/frontend/src/lib/api.test.ts
@@ -187,16 +187,6 @@ describe('API helper', () => {
() => api.messaging.updateTemplate('template-1', {}),
'/api/projects/2/messaging_templates/template-1/',
],
- [
- 'messaging.getCategory',
- () => api.messaging.getCategory('category-1'),
- '/api/projects/2/messaging_categories/category-1/',
- ],
- [
- 'messaging.generateMessagingPreferencesLink',
- () => api.messaging.generateMessagingPreferencesLink(),
- '/api/projects/2/messaging_preferences/generate_link/',
- ],
])("%s targets the tab's team, not @current", async (_name, request, expected) => {
await request()
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index ee669f50d842..a37a9cf70e40 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -225,7 +225,6 @@ import type {
GitHubReposResponseApi,
} from 'products/integrations/frontend/generated/api.schemas'
import type { LogExplanation } from 'products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/ExploreWithAI/types'
-import type { BulkAddOptOutsResultApi, BulkOptOutEntryApi } from 'products/messaging/frontend/generated/api.schemas'
import type { NotebookCollabCursorApi } from 'products/notebooks/frontend/generated/api.schemas'
import type { Task, TaskListParams, TaskRun, TaskUpsertProps } from 'products/posthog_ai/frontend/types/taskTypes'
import type {
@@ -1931,10 +1930,6 @@ export class ApiRequest {
return this.teamProjectDetail().addPathComponent('messaging_categories')
}
- public messagingCategory(categoryId: string): ApiRequest {
- return this.messagingCategories().addPathComponent(categoryId)
- }
-
public messagingCategoriesImportFromCustomerIO(): ApiRequest {
return this.messagingCategories().addPathComponent('import_from_customerio')
}
@@ -1963,20 +1958,10 @@ export class ApiRequest {
return this.messagingCategories().addPathComponent('remove_track_config')
}
- public messagingPreferences(): ApiRequest {
- return this.teamProjectDetail().addPathComponent('messaging_preferences')
- }
-
- public messagingPreferencesLink(): ApiRequest {
- return this.messagingPreferences().addPathComponent('generate_link')
- }
-
public messagingPreferencesExportOptOutsCsv(): ApiRequest {
- return this.messagingPreferences().addPathComponent('export_opt_outs_csv')
- }
-
- public messagingPreferencesBulkAddOptOuts(): ApiRequest {
- return this.messagingPreferences().addPathComponent('bulk_add_opt_outs')
+ return this.teamProjectDetail()
+ .addPathComponent('messaging_preferences')
+ .addPathComponent('export_opt_outs_csv')
}
public hogFlows(): ApiRequest {
@@ -6390,34 +6375,8 @@ const api = {
): Promise<MessageTemplate> {
return await new ApiRequest().messagingTemplate(templateId).update({ data })
},
-
- // Messaging Categories
- async getCategories(params?: { category_type?: string }): Promise<PaginatedResponse<any>> {
- return await new ApiRequest()
- .messagingCategories()
- .withQueryString(toParams(params || {}))
- .get()
- },
- async getCategory(categoryId: string): Promise<any> {
- return await new ApiRequest().messagingCategory(categoryId).get()
- },
- async createCategory(data: any): Promise<any> {
- return await new ApiRequest().messagingCategories().create({ data })
- },
- async updateCategory(categoryId: string, data: any): Promise<any> {
- return await new ApiRequest().messagingCategory(categoryId).update({ data })
- },
- async deleteCategory(categoryId: string): Promise<void> {
- return await new ApiRequest().messagingCategory(categoryId).delete()
- },
- async generateMessagingPreferencesLink(recipient?: string): Promise<string | null> {
- const response = await new ApiRequest().messagingPreferencesLink().create({
- data: {
- recipient,
- },
- })
- return response.preferences_url || null
- },
+ // The generated client's export function forces the response through JSON parsing (see
+ // frontend/src/lib/api-orval-mutator.ts), which breaks the CSV blob this endpoint streams back.
async exportOptOutsCsv(categoryKey?: string): Promise<Blob> {
const response = await new ApiRequest()
.messagingPreferencesExportOptOutsCsv()
@@ -6425,11 +6384,6 @@ const api = {
.getResponse()
return await response.blob()
},
- async bulkAddOptOuts(optOuts: BulkOptOutEntryApi[], categoryKey?: string): Promise<BulkAddOptOutsResultApi> {
- return await new ApiRequest().messagingPreferencesBulkAddOptOuts().create({
- data: { opt_outs: optOuts, category_key: categoryKey },
- })
- },
},
hogFlows: {
async getHogFlows(params?: {
diff --git a/products/workflows/frontend/OptOuts/NewCategoryModal.tsx b/products/workflows/frontend/OptOuts/NewCategoryModal.tsx
index c134409277e9..6f8267b7d24d 100644
--- a/products/workflows/frontend/OptOuts/NewCategoryModal.tsx
+++ b/products/workflows/frontend/OptOuts/NewCategoryModal.tsx
@@ -6,15 +6,7 @@ import { LemonButton, LemonInput, LemonModal, LemonSelect, LemonTextArea, Link }
import { LemonField } from 'lib/lemon-ui/LemonField'
import { newCategoryLogic } from './newCategoryLogic'
-
-interface MessageCategory {
- id: string
- key: string
- name: string
- description: string
- public_description: string
- category_type: string
-}
+import type { MessageCategory } from './optOutCategoriesLogic'
interface NewCategoryModalProps {
isOpen: boolean
diff --git a/products/workflows/frontend/OptOuts/OptOutCategories.tsx b/products/workflows/frontend/OptOuts/OptOutCategories.tsx
index eb2adef5fdcd..7a111ba4e37d 100644
--- a/products/workflows/frontend/OptOuts/OptOutCategories.tsx
+++ b/products/workflows/frontend/OptOuts/OptOutCategories.tsx
@@ -12,20 +12,11 @@ import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { customerIOImportLogic } from './customerIOImportLogic'
import { NewCategoryModal } from './NewCategoryModal'
-import { optOutCategoriesLogic } from './optOutCategoriesLogic'
+import { MessageCategory, optOutCategoriesLogic } from './optOutCategoriesLogic'
import { OptOutList } from './OptOutList'
const HedgehogConstruction2 = pngHoggie(construction2Png)
-interface MessageCategory {
- id: string
- key: string
- name: string
- description: string
- public_description: string
- category_type: string
-}
-
export function OptOutCategories(): JSX.Element {
const { categories, categoriesLoading, isNewCategoryModalOpen } = useValues(optOutCategoriesLogic)
const { loadCategories, deleteCategory, closeNewCategoryModal, openNewCategoryModal } =
@@ -57,7 +48,7 @@ export function OptOutCategories(): JSX.Element {
<div className="text-xs text-muted">{category.description}</div>
</div>
<LemonTag type={category.category_type === 'marketing' ? 'success' : 'completion'}>
- {category.category_type.toUpperCase()}
+ {(category.category_type ?? '').toUpperCase()}
</LemonTag>
</div>
<More
diff --git a/products/workflows/frontend/OptOuts/newCategoryLogic.ts b/products/workflows/frontend/OptOuts/newCategoryLogic.ts
index bf2fccbaca6b..7579c50e2579 100644
--- a/products/workflows/frontend/OptOuts/newCategoryLogic.ts
+++ b/products/workflows/frontend/OptOuts/newCategoryLogic.ts
@@ -2,9 +2,12 @@ import { MakeLogicType, actions, kea, key, listeners, path, props } from 'kea'
import { forms } from 'kea-forms'
import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from 'kea-forms'
-import api from 'lib/api'
+import { ApiConfig } from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { messagingCategoriesCreate, messagingCategoriesPartialUpdate } from 'products/messaging/frontend/generated/api'
+import type { MessageCategoryTypeEnumApi } from 'products/messaging/frontend/generated/api.schemas'
+
import { MessageCategory, optOutCategoriesLogic } from './optOutCategoriesLogic'
export type CategoryForm = {
@@ -12,7 +15,7 @@ export type CategoryForm = {
key: string
description: string
public_description: string
- category_type: string
+ category_type: MessageCategoryTypeEnumApi
}
export type CategoryLogicProps = {
@@ -117,9 +120,9 @@ export const newCategoryLogic = kea<newCategoryLogicType>([
? {
name: props.category.name,
key: props.category.key,
- description: props.category.description,
- public_description: props.category.public_description,
- category_type: props.category.category_type,
+ description: props.category.description ?? '',
+ public_description: props.category.public_description ?? '',
+ category_type: props.category.category_type ?? 'marketing',
}
: NEW_CATEGORY,
errors: ({ name, key }: CategoryForm) => {
@@ -134,13 +137,14 @@ export const newCategoryLogic = kea<newCategoryLogicType>([
}
},
submit: async (formValues: CategoryForm) => {
+ const teamId = String(ApiConfig.getCurrentTeamId())
if (props.category) {
// Update existing category
- await api.messaging.updateCategory(props.category.id, formValues)
+ await messagingCategoriesPartialUpdate(teamId, props.category.id, formValues)
lemonToast.success('Category updated successfully')
} else {
// Create new category
- await api.messaging.createCategory(formValues)
+ await messagingCategoriesCreate(teamId, formValues)
lemonToast.success('Category created successfully')
}
// Reload categories in the parent logic
diff --git a/products/workflows/frontend/OptOuts/optOutCategoriesLogic.ts b/products/workflows/frontend/OptOuts/optOutCategoriesLogic.ts
index 8d6b4eb08748..6f1f34825105 100644
--- a/products/workflows/frontend/OptOuts/optOutCategoriesLogic.ts
+++ b/products/workflows/frontend/OptOuts/optOutCategoriesLogic.ts
@@ -1,16 +1,12 @@
import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
-import api from 'lib/api'
+import { ApiConfig } from 'lib/api'
-export type MessageCategory = {
- id: string
- key: string
- name: string
- description: string
- public_description: string
- category_type: string
-}
+import { messagingCategoriesList, messagingCategoriesPartialUpdate } from 'products/messaging/frontend/generated/api'
+import type { MessageCategoryApi } from 'products/messaging/frontend/generated/api.schemas'
+
+export type MessageCategory = MessageCategoryApi
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface optOutCategoriesLogicValues {
@@ -38,12 +34,12 @@ export interface optOutCategoriesLogicActions {
errorObject?: any
}
loadCategoriesSuccess: (
- categories: MessageCategory[],
+ categories: MessageCategoryApi[],
payload?: {
value: true
}
) => {
- categories: MessageCategory[]
+ categories: MessageCategoryApi[]
payload?: {
value: true
}
@@ -69,8 +65,8 @@ export const optOutCategoriesLogic = kea<optOutCategoriesLogicType>([
categories: {
__default: [] as MessageCategory[],
loadCategories: async (): Promise<MessageCategory[]> => {
- const response = await api.messaging.getCategories({ category_type: 'marketing' })
- return response.results || []
+ const response = await messagingCategoriesList(String(ApiConfig.getCurrentTeamId()))
+ return response.results
},
},
}),
@@ -94,7 +90,7 @@ export const optOutCategoriesLogic = kea<optOutCategoriesLogicType>([
listeners(({ actions }) => ({
deleteCategory: async ({ id }: { id: string }) => {
try {
- await api.messaging.updateCategory(id, { deleted: true })
+ await messagingCategoriesPartialUpdate(String(ApiConfig.getCurrentTeamId()), id, { deleted: true })
actions.loadCategories()
} catch (error) {
console.error('Failed to delete category:', error)
diff --git a/products/workflows/frontend/OptOuts/optOutListLogic.ts b/products/workflows/frontend/OptOuts/optOutListLogic.ts
index 37b1b7e9fefb..a4d06753f450 100644
--- a/products/workflows/frontend/OptOuts/optOutListLogic.ts
+++ b/products/workflows/frontend/OptOuts/optOutListLogic.ts
@@ -18,10 +18,11 @@ import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import { downloadFile } from 'lib/utils/dom'
-import { projectLogic } from 'scenes/projectLogic'
+import { teamLogic } from 'scenes/teamLogic'
import {
messagingPreferencesAddOptOutCreate,
+ messagingPreferencesBulkAddOptOutsCreate,
messagingPreferencesOptOutsRetrieve,
messagingPreferencesRemoveOptOutCreate,
} from 'products/messaging/frontend/generated/api'
@@ -57,7 +58,7 @@ export type OptOutListLogicProps = {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface optOutListLogicValues {
preferencesUrlLoading: boolean // optOutSceneLogic
- currentProjectId: number | null // projectLogic
+ currentTeamId: number | null // teamLogic
addOptOut: MessagePreferencesApi | null
addOptOutLoading: boolean
csvExport: null
@@ -249,7 +250,7 @@ export const optOutListLogic = kea<optOutListLogicType>([
path(['products', 'workflows', 'frontend', 'OptOuts', 'optOutListLogic']),
props({} as OptOutListLogicProps),
connect(() => ({
- values: [optOutSceneLogic, ['preferencesUrlLoading'], projectLogic, ['currentProjectId']],
+ values: [optOutSceneLogic, ['preferencesUrlLoading'], teamLogic, ['currentTeamId']],
actions: [optOutSceneLogic, ['openPreferencesPage']],
})),
actions({
@@ -367,10 +368,10 @@ export const optOutListLogic = kea<optOutListLogicType>([
}),
loaders(({ props, values, actions }) => {
const fetchPage = async (page: number): Promise<PaginatedOptOutsApi> => {
- if (values.currentProjectId === null) {
+ if (values.currentTeamId === null) {
return EMPTY_OPT_OUTS
}
- return await messagingPreferencesOptOutsRetrieve(String(values.currentProjectId), {
+ return await messagingPreferencesOptOutsRetrieve(String(values.currentTeamId), {
category_key: props.category?.key,
search: values.searchTerm.trim() || undefined,
page,
@@ -381,11 +382,11 @@ export const optOutListLogic = kea<optOutListLogicType>([
addOptOut: {
__default: null as MessagePreferencesApi | null,
addOptOut: async (identifier: string): Promise<MessagePreferencesApi> => {
- if (values.currentProjectId === null) {
+ if (values.currentTeamId === null) {
throw new Error('No current project')
}
try {
- const result = await messagingPreferencesAddOptOutCreate(String(values.currentProjectId), {
+ const result = await messagingPreferencesAddOptOutCreate(String(values.currentTeamId), {
identifier,
category_key: props.category?.key,
})
@@ -401,11 +402,11 @@ export const optOutListLogic = kea<optOutListLogicType>([
removeOptOut: {
__default: null as string | null,
removeOptOut: async (identifier: string): Promise<string> => {
- if (values.currentProjectId === null) {
+ if (values.currentTeamId === null) {
throw new Error('No current project')
}
try {
- await messagingPreferencesRemoveOptOutCreate(String(values.currentProjectId), {
+ await messagingPreferencesRemoveOptOutCreate(String(values.currentTeamId), {
identifier,
category_key: props.category?.key,
})
@@ -460,6 +461,10 @@ export const optOutListLogic = kea<optOutListLogicType>([
if (!file) {
return null
}
+ if (values.currentTeamId === null) {
+ lemonToast.error('No current project')
+ return null
+ }
let rows: string[][]
try {
@@ -483,9 +488,15 @@ export const optOutListLogic = kea<optOutListLogicType>([
for (let start = 0; start < parsed.entries.length; start += BULK_OPT_OUT_CHUNK_SIZE) {
const chunk = parsed.entries.slice(start, start + BULK_OPT_OUT_CHUNK_SIZE)
try {
- const chunkResult = await api.messaging.bulkAddOptOuts(
- chunk.map(({ identifier, category_key }) => ({ identifier, category_key })),
- props.category?.key
+ const chunkResult = await messagingPreferencesBulkAddOptOutsCreate(
+ String(values.currentTeamId),
+ {
+ opt_outs: chunk.map(({ identifier, category_key }) => ({
+ identifier,
+ category_key,
+ })),
+ category_key: props.category?.key,
+ }
)
result.opted_out += chunkResult.opted_out
result.skipped += chunkResult.skipped
diff --git a/products/workflows/frontend/OptOuts/optOutSceneLogic.ts b/products/workflows/frontend/OptOuts/optOutSceneLogic.ts
index f51f8e75b803..1030a00c00cf 100644
--- a/products/workflows/frontend/OptOuts/optOutSceneLogic.ts
+++ b/products/workflows/frontend/OptOuts/optOutSceneLogic.ts
@@ -3,9 +3,11 @@ import { loaders } from 'kea-loaders'
import { lemonToast } from '@posthog/lemon-ui'
-import api from 'lib/api'
+import { ApiConfig } from 'lib/api'
import { userLogic } from 'scenes/userLogic'
+import { messagingPreferencesGenerateLinkCreate } from 'products/messaging/frontend/generated/api'
+
import type { UserType } from '../../../../frontend/src/types'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -57,15 +59,16 @@ export const optOutSceneLogic = kea<optOutSceneLogicType>([
}
try {
- const newPreferencesUrl = await api.messaging.generateMessagingPreferencesLink(
- recipient ?? values.user.email
+ const response = await messagingPreferencesGenerateLinkCreate(
+ String(ApiConfig.getCurrentTeamId()),
+ { recipient: recipient ?? values.user.email }
)
- if (!newPreferencesUrl) {
+ if (!response.preferences_url) {
lemonToast.error('Failed to generate workflows preferences link')
return null
}
- window.open(newPreferencesUrl, '_blank')
- return newPreferencesUrl
+ window.open(response.preferences_url, '_blank')
+ return response.preferences_url
} catch {
lemonToast.error('Failed to generate workflows preferences link')
return null