diff --git a/platform/starbase/src/jsonrpc/methods/publishApp.ts b/platform/starbase/src/jsonrpc/methods/publishApp.ts index a7c652d348..5d1acc290f 100644 --- a/platform/starbase/src/jsonrpc/methods/publishApp.ts +++ b/platform/starbase/src/jsonrpc/methods/publishApp.ts @@ -61,19 +61,19 @@ export const publishApp = async ({ await appDO.class.publish(input.published) - const { edges: ownershipEdges } = await caller.edges.getEdges({ - query: { - tag: EDGE_APPLICATION, - dst: { baseUrn: appURN }, - }, - }) - if (ownershipEdges.length === 0) { - throw new InternalServerError({ - message: 'App ownership edge not found', + const buildAnalyticsEvent = async () => { + const { edges: ownershipEdges } = await caller.edges.getEdges({ + query: { + tag: EDGE_APPLICATION, + dst: { baseUrn: appURN }, + }, }) - } + if (ownershipEdges.length === 0) { + throw new InternalServerError({ + message: 'App ownership edge not found', + }) + } - ctx.waitUntil?.( createAnalyticsEvent({ distinctId: ctx.identityURN as IdentityURN, eventName: input.published @@ -89,7 +89,9 @@ export const publishApp = async ({ }, }, }) - ) + } + + ctx.waitUntil?.(buildAnalyticsEvent()) return { published: true, diff --git a/platform/starbase/src/jsonrpc/methods/setAppPlan.ts b/platform/starbase/src/jsonrpc/methods/setAppPlan.ts index 38cd8db78f..4bdc275bb1 100644 --- a/platform/starbase/src/jsonrpc/methods/setAppPlan.ts +++ b/platform/starbase/src/jsonrpc/methods/setAppPlan.ts @@ -82,19 +82,19 @@ export const setAppPlan = async ({ }) ) - const { edges: ownershipEdges } = await caller.edges.getEdges({ - query: { - tag: EDGE_APPLICATION, - dst: { baseUrn: appURN }, - }, - }) - if (ownershipEdges.length === 0) { - throw new InternalServerError({ - message: 'App ownership edge not found', + const buildAnalyticsEvent = async () => { + const { edges: ownershipEdges } = await caller.edges.getEdges({ + query: { + tag: EDGE_APPLICATION, + dst: { baseUrn: appURN }, + }, }) - } + if (ownershipEdges.length === 0) { + throw new InternalServerError({ + message: 'App ownership edge not found', + }) + } - ctx.waitUntil?.( createAnalyticsEvent({ eventName: `app_set_${plan}_plan`, apiKey: ctx.POSTHOG_API_KEY, @@ -108,5 +108,7 @@ export const setAppPlan = async ({ }, }, }) - ) + } + + ctx.waitUntil?.(buildAnalyticsEvent()) }