@mx-cartographer/experiences 9.7.74 → 9.7.76

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/core/types/Insights.d.ts +2 -7
  3. package/dist/core/types/Insights.es.js.map +1 -1
  4. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js +37 -37
  5. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js.map +1 -1
  6. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/layout.d.ts +10 -0
  7. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/layout.es.js +12 -7
  8. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/layout.es.js.map +1 -1
  9. package/dist/insights-v2/actionBlocks/SurveyModalActionBlock.es.js +28 -20
  10. package/dist/insights-v2/actionBlocks/SurveyModalActionBlock.es.js.map +1 -1
  11. package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/TransactionHistoryBlock.es.js +11 -11
  12. package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/useTransactionHistoryPrepare.es.js +3 -3
  13. package/dist/insights-v2/blocks/ComponentBlocks/SavingsOpportunityBlock/SavingsOpportunityBlock.d.ts +7 -14
  14. package/dist/insights-v2/blocks/ComponentBlocks/SavingsOpportunityBlock/SavingsOpportunityBlock.es.js +11 -27
  15. package/dist/insights-v2/blocks/ComponentBlocks/SavingsOpportunityBlock/SavingsOpportunityBlock.es.js.map +1 -1
  16. package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/TransactionBlock.es.js +75 -68
  17. package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/TransactionBlock.es.js.map +1 -1
  18. package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/layout.d.ts +4 -1
  19. package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/layout.es.js +2 -1
  20. package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/layout.es.js.map +1 -1
  21. package/dist/insights-v2/blocks/ComponentBlocks/UpcomingSubscriptionBlock/UpcomingSubscriptionBlock.es.js +4 -4
  22. package/dist/insights-v2/components/BaseLayout.es.js +40 -40
  23. package/dist/insights-v2/components/BaseLayout.es.js.map +1 -1
  24. package/dist/insights-v2/components/CtaStatus.d.ts +2 -2
  25. package/dist/insights-v2/components/CtaStatus.es.js +23 -14
  26. package/dist/insights-v2/components/CtaStatus.es.js.map +1 -1
  27. package/dist/insights-v2/components/FeedbackDialog.d.ts +3 -1
  28. package/dist/insights-v2/components/FeedbackDialog.es.js +28 -28
  29. package/dist/insights-v2/components/FeedbackDialog.es.js.map +1 -1
  30. package/dist/insights-v2/components/FeedbackModal.d.ts +3 -1
  31. package/dist/insights-v2/components/FeedbackModal.es.js +17 -16
  32. package/dist/insights-v2/components/FeedbackModal.es.js.map +1 -1
  33. package/dist/insights-v2/components/InsightTransactionRow.d.ts +3 -1
  34. package/dist/insights-v2/components/InsightTransactionRow.es.js +36 -19
  35. package/dist/insights-v2/components/InsightTransactionRow.es.js.map +1 -1
  36. package/dist/insights-v2/components/SavingsOpportunityCard.es.js +6 -4
  37. package/dist/insights-v2/components/SavingsOpportunityCard.es.js.map +1 -1
  38. package/dist/insights-v2/components/SubscriptionStatus/subscriptionFrequency.d.ts +4 -0
  39. package/dist/insights-v2/components/SubscriptionStatus/subscriptionFrequency.es.js +11 -0
  40. package/dist/insights-v2/components/SubscriptionStatus/subscriptionFrequency.es.js.map +1 -0
  41. package/dist/insights-v2/components/SurveyModal.d.ts +5 -1
  42. package/dist/insights-v2/components/SurveyModal.es.js +46 -38
  43. package/dist/insights-v2/components/SurveyModal.es.js.map +1 -1
  44. package/dist/insights-v2/ctaActions/ctaConfig.es.js +19 -11
  45. package/dist/insights-v2/ctaActions/ctaConfig.es.js.map +1 -1
  46. package/dist/insights-v2/ctaActions/index.d.ts +1 -1
  47. package/dist/insights-v2/ctaActions/runCtaAction.d.ts +5 -1
  48. package/dist/insights-v2/ctaActions/runCtaAction.es.js +4 -4
  49. package/dist/insights-v2/ctaActions/runCtaAction.es.js.map +1 -1
  50. package/dist/insights-v2/ctaActions/subscriptionAnswer.d.ts +4 -2
  51. package/dist/insights-v2/ctaActions/subscriptionAnswer.es.js +136 -0
  52. package/dist/insights-v2/ctaActions/subscriptionAnswer.es.js.map +1 -0
  53. package/dist/insights-v2/ctaActions/types.d.ts +12 -0
  54. package/dist/insights-v2/ctaActions/useCtaAction.d.ts +4 -1
  55. package/dist/insights-v2/ctaActions/useCtaAction.es.js +33 -33
  56. package/dist/insights-v2/ctaActions/useCtaAction.es.js.map +1 -1
  57. package/dist/insights-v2/mappings/actionBlocksKey.d.ts +1 -0
  58. package/dist/insights-v2/mappings/actionBlocksKey.es.js +1 -0
  59. package/dist/insights-v2/mappings/actionBlocksKey.es.js.map +1 -1
  60. package/dist/insights-v2/mappings/blocks.es.js +69 -64
  61. package/dist/insights-v2/mappings/blocks.es.js.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/insights-v2/blocks/ComponentBlocks/SavingsOpportunityBlock/layout.d.ts +0 -18
  64. package/dist/insights-v2/blocks/ComponentBlocks/SavingsOpportunityBlock/layout.es.js +0 -13
  65. package/dist/insights-v2/blocks/ComponentBlocks/SavingsOpportunityBlock/layout.es.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"runCtaAction.es.js","names":[],"sources":["../../../src/insights-v2/ctaActions/runCtaAction.ts"],"sourcesContent":["import { sendBeatCta } from '../../common/utils/PostMessage'\nimport {\n ANALYTICS_EVENTS_CONFIG,\n type AnalyticsEventConfigEntry,\n} from '../analytics/analyticsEventsConfig'\nimport { resolveAnalyticsEvent } from '../analytics/resolveAnalyticsEvent'\nimport { hasDrawerBlock } from '../mappings/hasDrawerBlock'\nimport { ctaActions } from './ctaConfig'\nimport { resolveCtaMetadata } from './ctaPostMessages'\nimport { ctaHandlers, type CtaHandlerName } from './ctaHandlers'\nimport { HOST_ACTIONS } from './hostActions'\nimport type { CtaPostMessageMetadata } from '../../core'\nimport type {\n CtaContext,\n CtaEffect,\n CtaHandler,\n CtaHandlerContext,\n CtaState,\n CtaStateContext,\n CtaStep,\n RunHandlerOptions,\n} from './types'\n\nconst DEFAULT_STEP: CtaStep = {}\n\n// ─── Resolution ─────────────────────────────────────────────────────────────\n\n/** The beat's own context (input a block collected for it), `{}` until something is written. */\nexport const beatContextOf = ({ beat, stores }: Pick<CtaStateContext, 'beat' | 'stores'>) =>\n stores.insightsV2Store.beatContext[beat.guid] ?? {}\n\n/** The step named by the CTA's `action_key`, or the empty default (no key / unknown key). */\nexport const resolveStep = ({ cta }: Pick<CtaStateContext, 'cta'>): CtaStep =>\n (cta.action_key && ctaActions[cta.action_key]) || DEFAULT_STEP\n\n/** Pending always disables, as may the step's `disabledWhen`; its `presenter` may replace the button. */\nexport const resolveCtaState = (ctx: CtaStateContext): CtaState => {\n const step = resolveStep(ctx)\n const pending = ctx.stores.insightsV2Store.ctaStatus[ctx.beat.guid] === 'pending'\n const presentation = step.presenter?.(ctx)\n\n return {\n disabled: pending || (step.disabledWhen?.(ctx) ?? false),\n ...(presentation && { presentation }),\n }\n}\n\n// ─── Targets and effects ────────────────────────────────────────────────────\n\n/** Opens the beat's drawer for whichever slot triggered the current step. */\nconst openDrawerForSlot = ({\n beat,\n slot,\n stores,\n}: Pick<CtaContext, 'beat' | 'slot' | 'stores'>) => {\n stores.insightsV2Store.openCtaDrawer(\n beat.guid,\n slot === 'primary' ? 'primaryCta' : 'secondaryCta',\n )\n}\n\n/**\n * Posts this CTA's resolved message (event, op and beat-specific payload, from the backend's\n * `cta.metadata` or the template's `ctaPostMessages` entry) to the host.\n */\nconst postCtaMessage = ({ beat, stores }: CtaContext, metadata: CtaPostMessageMetadata) => {\n const { is_mobile_webview, clientConfig } = stores.appDataStore.appConfig\n const { event, action, payload } = metadata\n\n sendBeatCta(beat, {\n event: event ?? undefined,\n op: action ?? undefined,\n extras: payload ?? undefined,\n isMobileWebview: is_mobile_webview,\n webviewScheme: clientConfig?.master?.ui_message_webview_url_scheme,\n userGuid: beat.insights_payload?.user_guid ?? beat.user_guid,\n })\n}\n\n/**\n * Default target: open the drawer for a real block, otherwise nothing. A post message is never\n * implied by a missing block; it is sent only when one resolves (see runCtaAction).\n */\nconst runDefaultTarget = (ctx: CtaContext) => {\n if (hasDrawerBlock(ctx.cta.block)) openDrawerForSlot(ctx)\n}\n\nconst runEffect = (effect: CtaEffect, { beat, stores }: CtaContext) => {\n switch (effect) {\n case 'refreshBeat':\n stores.emitUpdate({ staleBeatGuid: beat.guid })\n break\n }\n}\n\ntype AnalyticsCtx = Pick<CtaContext, 'beat' | 'stores' | 'hostActions'>\n\n/**\n * The one way to fire a catalogued analytics event. Takes the catalogue entry itself (e.g.\n * `ANALYTICS_EVENTS_CONFIG.PRIMARY_ACTION_SELECTED`), not a lookup key — the call site already\n * has the entry via property access, so there is no key to look up or mistype. Resolves the\n * payload and hands it to the host directly. Never throws: a failed fire is captured, it\n * cannot fail or disable anything.\n */\nexport const sendCtaAnalytics = (ctx: AnalyticsCtx, event: AnalyticsEventConfigEntry): void => {\n try {\n ctx.hostActions.onAnalyticsEvent?.(resolveAnalyticsEvent(event, ctx.beat))\n } catch (error) {\n ctx.stores.captureException(error, {\n store: 'ctaActions',\n template: ctx.beat.template,\n handler: 'sendCtaAnalytics',\n })\n }\n}\n\n// First primary click: fires FIRST_TIME_PRIMARY_ACTION_SELECTED and records cta_clicked_at.\nconst markCtaClicked = (ctx: AnalyticsCtx & Pick<CtaContext, 'slot'>): void => {\n const { beat, slot, hostActions, stores } = ctx\n\n if (slot !== 'primary' || beat.cta_clicked_at) return\n\n sendCtaAnalytics(ctx, ANALYTICS_EVENTS_CONFIG.FIRST_TIME_PRIMARY_ACTION_SELECTED)\n\n // Fire-and-forget; a failed write must not fail the user's action, but still report it.\n Promise.resolve()\n .then(() =>\n hostActions.onCtaAction?.({ beatGuid: beat.guid, name: HOST_ACTIONS.markCtaClicked }),\n )\n .catch((error) =>\n stores.captureException(error, {\n store: 'ctaActions',\n template: beat.template,\n handler: 'markCtaClicked',\n }),\n )\n}\n\n/**\n * Trigger 1 + the first-click bookkeeping together: every CTA press's generic analytics\n * (`Primary/Secondary Action Selected`), plus `FIRST_TIME_PRIMARY_ACTION_SELECTED` /\n * `cta_clicked_at` on the first primary press. The one call site for \"a CTA got pressed\",\n * used by the runner and by the contact-support bypass in `BaseLayout`.\n */\nexport const reportCtaClick = (\n ctx: AnalyticsCtx & Pick<CtaContext, 'slot'>,\n { skipCtaClicked = false }: { skipCtaClicked?: boolean } = {},\n): void => {\n sendCtaAnalytics(\n ctx,\n ctx.slot === 'primary'\n ? ANALYTICS_EVENTS_CONFIG.PRIMARY_ACTION_SELECTED\n : ANALYTICS_EVENTS_CONFIG.SECONDARY_ACTION_SELECTED,\n )\n\n if (!skipCtaClicked) markCtaClicked(ctx)\n}\n\n// ─── Shared bookkeeping ─────────────────────────────────────────────────────\n\n/** Runs a named handler, then its `onSuccess` effects. Shared by card CTAs and drawer saves. */\nconst runHandlerWithEffects = async (\n ctx: CtaContext,\n handlerName: CtaHandlerName,\n onSuccess: CtaEffect[],\n): Promise<void> => {\n // Names are typed, but the map is still indexed defensively: config can come from anywhere.\n const handler = (ctaHandlers as Record<string, CtaHandler>)[handlerName]\n\n if (!handler) throw new Error(`Unknown CTA handler \"${handlerName}\"`)\n\n await handler(ctx)\n\n for (const effect of onSuccess) runEffect(effect, ctx)\n}\n\n/** Per-beat status around `work`: `pending` -> `done` | `error` (+ captureException). */\nconst withCtaStatus = async (\n { beat, stores }: Pick<CtaContext, 'beat' | 'stores'>,\n work: () => Promise<void>,\n captureContext: Record<string, string> = {},\n): Promise<boolean> => {\n const { insightsV2Store } = stores\n\n insightsV2Store.setCtaStatus(beat.guid, 'pending')\n\n try {\n await work()\n insightsV2Store.setCtaStatus(beat.guid, 'done')\n\n return true\n } catch (error) {\n insightsV2Store.setCtaStatus(beat.guid, 'error')\n stores.captureException(error, {\n store: 'ctaActions',\n template: beat.template,\n ...captureContext,\n })\n\n return false\n }\n}\n\n// ─── Entry points ───────────────────────────────────────────────────────────\n\n// Runs the CTA's step: handler, onSuccess effects, post message, then the next target.\nexport const runCtaAction = async (ctx: CtaContext): Promise<void> => {\n const step = resolveStep(ctx)\n const stepParams = typeof step.params === 'function' ? step.params(ctx) : step.params\n const stepCtx: CtaContext = { ...ctx, params: { ...stepParams, ...ctx.params } }\n\n reportCtaClick(stepCtx, { skipCtaClicked: step.skipCtaClicked })\n\n await withCtaStatus(stepCtx, async () => {\n if (step.run) await runHandlerWithEffects(stepCtx, step.run, step.onSuccess ?? [])\n\n // A step's own event, e.g. select_savings_account (Saved) / open_savings_account (Created).\n if (step.analytics) sendCtaAnalytics(stepCtx, step.analytics)\n\n const metadata = resolveCtaMetadata(stepCtx)\n\n if (metadata) postCtaMessage(stepCtx, metadata)\n\n const target = step.next ?? (step.run ? 'none' : 'default')\n\n if (target === 'default') runDefaultTarget(stepCtx)\n else if (target === 'drawer') openDrawerForSlot(stepCtx)\n })\n}\n\n/** Placeholder CTA for handlers run from inside a drawer, where no card slot is involved. */\nconst DIRECT_CTA = { label: '', block: '' }\n\n/** Runs a handler directly (drawer Save buttons). True on success. */\nexport const runCtaHandler = (\n ctx: CtaHandlerContext,\n handlerName: CtaHandlerName,\n { onSuccess = [], analytics }: RunHandlerOptions = {},\n): Promise<boolean> => {\n const fullCtx: CtaContext = { ...ctx, cta: DIRECT_CTA, slot: 'primary' }\n\n return withCtaStatus(\n fullCtx,\n async () => {\n await runHandlerWithEffects(fullCtx, handlerName, onSuccess)\n\n // Success-time analytics for drawer Saves.\n if (analytics) sendCtaAnalytics(fullCtx, analytics)\n },\n { handler: handlerName },\n )\n}\n"],"mappings":";;;;;;;;AAuBA,IAAM,IAAwB,CAAC,GASlB,IAAA,CAAe,EAAE,KAAA,EAAA,MAC3B,EAAI,cAAc,EAAW,EAAI,UAAA,KAAgB,GAGvC,IAAA,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A,MACf,GAAG;AAAA,IACL,CAAC,GAEM;AAAA,EACT;AACF,GAKa,IAAe,OAAO,MAAmC;AACpE,QAAM,IAAO,EAAY,CAAG,GACtB,IAAa,OAAO,EAAK,UAAW,aAAa,EAAK,OAAO,CAAG,IAAI,EAAK,QACzE,IAAsB;AAAA,IAAE,GAAG;AAAA,IAAK,QAAQ;AAAA,MAAE,GAAG;AAAA,MAAY,GAAG,EAAI;AAAA,IAAO;AAAA,EAAE;AAE/E,EAAA,EAAe,GAAS,EAAE,gBAAgB,EAAK,eAAe,CAAC,GAE/D,MAAM,EAAc,GAAS,YAAY;AACvC,IAAI,EAAK,OAAK,MAAM,EAAsB,GAAS,EAAK,KAAK,EAAK,aAAa,CAAC,CAAC,GAG7E,EAAK,aAAW,EAAiB,GAAS,EAAK,SAAS;AAE5D,UAAM,IAAW,EAAmB,CAAO;AAE3C,IAAI,KAAU,EAAe,GAAS,CAAQ;AAE9C,UAAM,IAAS,EAAK,SAAS,EAAK,MAAM,SAAS;AAEjD,IAAI,MAAW,YAAW,EAAiB,CAAO,IACzC,MAAW,YAAU,EAAkB,CAAO;AAAA,EACzD,CAAC;AACH,GAGM,IAAa;AAAA,EAAE,OAAO;AAAA,EAAI,OAAO;AAAG,GAG7B,IAAA,CACX,GACA,GACA,EAAE,WAAA,IAAY,CAAC,GAAG,WAAA,EAAA,IAAiC,CAAC,MAC/B;AACrB,QAAM,IAAsB;AAAA,IAAE,GAAG;AAAA,IAAK,KAAK;AAAA,IAAY,MAAM;AAAA,EAAU;AAEvE,SAAO,EACL,GACA,YAAY;AACV,UAAM,EAAsB,GAAS,GAAa,CAAS,GAGvD,KAAW,EAAiB,GAAS,CAAS;AAAA,EACpD,GACA,EAAE,SAAS,EAAY,CACzB;AACF"}
1
+ {"version":3,"file":"runCtaAction.es.js","names":[],"sources":["../../../src/insights-v2/ctaActions/runCtaAction.ts"],"sourcesContent":["import { sendBeatCta } from '../../common/utils/PostMessage'\nimport {\n ANALYTICS_EVENTS_CONFIG,\n type AnalyticsEventConfigEntry,\n} from '../analytics/analyticsEventsConfig'\nimport { resolveAnalyticsEvent } from '../analytics/resolveAnalyticsEvent'\nimport { hasDrawerBlock } from '../mappings/hasDrawerBlock'\nimport { ctaActions } from './ctaConfig'\nimport { resolveCtaMetadata } from './ctaPostMessages'\nimport { ctaHandlers, type CtaHandlerName } from './ctaHandlers'\nimport { HOST_ACTIONS } from './hostActions'\nimport type { CtaPostMessageMetadata } from '../../core'\nimport type {\n CtaContext,\n CtaEffect,\n CtaHandler,\n CtaHandlerContext,\n CtaState,\n CtaStateContext,\n CtaStep,\n RunHandlerOptions,\n} from './types'\n\nconst DEFAULT_STEP: CtaStep = {}\n\n// ─── Resolution ─────────────────────────────────────────────────────────────\n\n/** The beat's own context (input a block collected for it), `{}` until something is written. */\nexport const beatContextOf = ({ beat, stores }: Pick<CtaStateContext, 'beat' | 'stores'>) =>\n stores.insightsV2Store.beatContext[beat.guid] ?? {}\n\n/** The step named by the CTA's `action_key`, or the empty default (no key / unknown key). */\nexport const resolveStep = ({ cta }: { cta: { action_key?: string | null } }): CtaStep =>\n (cta.action_key && ctaActions[cta.action_key]) || DEFAULT_STEP\n\n/** Pending always disables, as may the step's `disabledWhen`; its `presenter` may replace the button. */\nexport const resolveCtaState = (ctx: CtaStateContext): CtaState => {\n const step = resolveStep(ctx)\n const pending = ctx.stores.insightsV2Store.ctaStatus[ctx.beat.guid] === 'pending'\n const presentation = step.presenter?.(ctx)\n\n return {\n disabled: pending || (step.disabledWhen?.(ctx) ?? false),\n ...(presentation && { presentation }),\n }\n}\n\n// ─── Targets and effects ────────────────────────────────────────────────────\n\n/** Opens the beat's drawer for whichever slot triggered the current step. */\nconst openDrawerForSlot = ({\n beat,\n slot,\n stores,\n}: Pick<CtaContext, 'beat' | 'slot' | 'stores'>) => {\n stores.insightsV2Store.openCtaDrawer(\n beat.guid,\n slot === 'primary' ? 'primaryCta' : 'secondaryCta',\n )\n}\n\n/**\n * Posts this CTA's resolved message (event, op and beat-specific payload, from the backend's\n * `cta.metadata` or the template's `ctaPostMessages` entry) to the host.\n */\nconst postCtaMessage = ({ beat, stores }: CtaContext, metadata: CtaPostMessageMetadata) => {\n const { is_mobile_webview, clientConfig } = stores.appDataStore.appConfig\n const { event, action, payload } = metadata\n\n sendBeatCta(beat, {\n event: event ?? undefined,\n op: action ?? undefined,\n extras: payload ?? undefined,\n isMobileWebview: is_mobile_webview,\n webviewScheme: clientConfig?.master?.ui_message_webview_url_scheme,\n userGuid: beat.insights_payload?.user_guid ?? beat.user_guid,\n })\n}\n\n/**\n * Default target: open the drawer for a real block, otherwise nothing. A post message is never\n * implied by a missing block; it is sent only when one resolves (see runCtaAction).\n */\nconst runDefaultTarget = (ctx: CtaContext) => {\n if (hasDrawerBlock(ctx.cta.block)) openDrawerForSlot(ctx)\n}\n\nconst runEffect = (effect: CtaEffect, { beat, stores }: CtaContext) => {\n switch (effect) {\n case 'refreshBeat':\n stores.emitUpdate({ staleBeatGuid: beat.guid })\n break\n }\n}\n\ntype AnalyticsCtx = Pick<CtaContext, 'beat' | 'stores' | 'hostActions'>\n\n/**\n * The one way to fire a catalogued analytics event. Takes the catalogue entry itself (e.g.\n * `ANALYTICS_EVENTS_CONFIG.PRIMARY_ACTION_SELECTED`), not a lookup key — the call site already\n * has the entry via property access, so there is no key to look up or mistype. Resolves the\n * payload and hands it to the host directly. Never throws: a failed fire is captured, it\n * cannot fail or disable anything.\n */\nexport const sendCtaAnalytics = (ctx: AnalyticsCtx, event: AnalyticsEventConfigEntry): void => {\n try {\n ctx.hostActions.onAnalyticsEvent?.(resolveAnalyticsEvent(event, ctx.beat))\n } catch (error) {\n ctx.stores.captureException(error, {\n store: 'ctaActions',\n template: ctx.beat.template,\n handler: 'sendCtaAnalytics',\n })\n }\n}\n\n// First primary click: fires FIRST_TIME_PRIMARY_ACTION_SELECTED and records cta_clicked_at.\nconst markCtaClicked = (ctx: AnalyticsCtx & Pick<CtaContext, 'slot'>): void => {\n const { beat, slot, hostActions, stores } = ctx\n\n if (slot !== 'primary' || beat.cta_clicked_at) return\n\n sendCtaAnalytics(ctx, ANALYTICS_EVENTS_CONFIG.FIRST_TIME_PRIMARY_ACTION_SELECTED)\n\n // Fire-and-forget; a failed write must not fail the user's action, but still report it.\n Promise.resolve()\n .then(() =>\n hostActions.onCtaAction?.({ beatGuid: beat.guid, name: HOST_ACTIONS.markCtaClicked }),\n )\n .catch((error) =>\n stores.captureException(error, {\n store: 'ctaActions',\n template: beat.template,\n handler: 'markCtaClicked',\n }),\n )\n}\n\n/**\n * Trigger 1 + the first-click bookkeeping together: every CTA press's generic analytics\n * (`Primary/Secondary Action Selected`), plus `FIRST_TIME_PRIMARY_ACTION_SELECTED` /\n * `cta_clicked_at` on the first primary press. The one call site for \"a CTA got pressed\",\n * used by the runner and by the contact-support bypass in `BaseLayout`.\n */\nexport const reportCtaClick = (\n ctx: AnalyticsCtx & Pick<CtaContext, 'slot'>,\n { skipCtaClicked = false }: { skipCtaClicked?: boolean } = {},\n): void => {\n sendCtaAnalytics(\n ctx,\n ctx.slot === 'primary'\n ? ANALYTICS_EVENTS_CONFIG.PRIMARY_ACTION_SELECTED\n : ANALYTICS_EVENTS_CONFIG.SECONDARY_ACTION_SELECTED,\n )\n\n if (!skipCtaClicked) markCtaClicked(ctx)\n}\n\n// ─── Shared bookkeeping ─────────────────────────────────────────────────────\n\n/** Runs a named handler, then its `onSuccess` effects. Shared by card CTAs and drawer saves. */\nconst runHandlerWithEffects = async (\n ctx: CtaContext,\n handlerName: CtaHandlerName,\n onSuccess: CtaEffect[],\n): Promise<void> => {\n // Names are typed, but the map is still indexed defensively: config can come from anywhere.\n const handler = (ctaHandlers as Record<string, CtaHandler>)[handlerName]\n\n if (!handler) throw new Error(`Unknown CTA handler \"${handlerName}\"`)\n\n await handler(ctx)\n\n for (const effect of onSuccess) runEffect(effect, ctx)\n}\n\n/** Per-beat status around `work`: `pending` -> `done` | `error` (+ captureException). */\nconst withCtaStatus = async (\n { beat, stores }: Pick<CtaContext, 'beat' | 'stores'>,\n work: () => Promise<void>,\n captureContext: Record<string, string> = {},\n): Promise<boolean> => {\n const { insightsV2Store } = stores\n\n insightsV2Store.setCtaStatus(beat.guid, 'pending')\n\n try {\n await work()\n insightsV2Store.setCtaStatus(beat.guid, 'done')\n\n return true\n } catch (error) {\n insightsV2Store.setCtaStatus(beat.guid, 'error')\n stores.captureException(error, {\n store: 'ctaActions',\n template: beat.template,\n ...captureContext,\n })\n\n return false\n }\n}\n\n// ─── Entry points ───────────────────────────────────────────────────────────\n\n// Runs the CTA's step: handler, onSuccess effects, post message, then the next target.\nexport const runCtaAction = async (ctx: CtaContext): Promise<void> => {\n const step = resolveStep(ctx)\n const stepParams = typeof step.params === 'function' ? step.params(ctx) : step.params\n const stepCtx: CtaContext = { ...ctx, params: { ...stepParams, ...ctx.params } }\n\n reportCtaClick(stepCtx, { skipCtaClicked: step.skipCtaClicked })\n\n await withCtaStatus(stepCtx, async () => {\n if (step.run) await runHandlerWithEffects(stepCtx, step.run, step.onSuccess ?? [])\n\n // A step's own event, e.g. select_savings_account (Saved) / open_savings_account (Created).\n if (step.analytics) sendCtaAnalytics(stepCtx, step.analytics)\n\n const metadata = resolveCtaMetadata(stepCtx)\n\n if (metadata) postCtaMessage(stepCtx, metadata)\n\n const target = step.next ?? (step.run ? 'none' : 'default')\n\n if (target === 'default') runDefaultTarget(stepCtx)\n else if (target === 'drawer') openDrawerForSlot(stepCtx)\n })\n}\n\n/** Placeholder CTA for handlers run from inside a drawer, where no card slot is involved. */\nconst DIRECT_CTA = { label: '', block: '' }\n\n/** Runs a handler directly (drawer Save buttons). True on success. */\nexport const runCtaHandler = (\n ctx: CtaHandlerContext,\n handlerName: CtaHandlerName,\n { onSuccess = [], analytics }: RunHandlerOptions = {},\n): Promise<boolean> => {\n const fullCtx: CtaContext = { ...ctx, cta: DIRECT_CTA, slot: 'primary' }\n\n return withCtaStatus(\n fullCtx,\n async () => {\n await runHandlerWithEffects(fullCtx, handlerName, onSuccess)\n\n // Success-time analytics for drawer Saves.\n if (analytics) sendCtaAnalytics(fullCtx, analytics)\n },\n { handler: handlerName },\n )\n}\n"],"mappings":";;;;;;;;AAuBA,IAAM,IAAwB,CAAC,GASlB,IAAA,CAAe,EAAE,KAAA,EAAA,MAC3B,EAAI,cAAc,EAAW,EAAI,UAAA,KAAgB,GAGvC,IAAA,CAAmB,MAAmC;AACjE,QAAM,IAAO,EAAY,CAAG,GACtB,IAAU,EAAI,OAAO,gBAAgB,UAAU,EAAI,KAAK,IAAA,MAAU,WAClE,IAAe,EAAK,YAAY,CAAG;AAEzC,SAAO;AAAA,IACL,UAAU,MAAY,EAAK,eAAe,CAAG,KAAK;AAAA,IAClD,GAAI,KAAgB,EAAE,cAAA,EAAa;AAAA,EACrC;AACF,GAKM,IAAA,CAAqB,EACzB,MAAA,GACA,MAAA,GACA,QAAA,EAAA,MACkD;AAClD,EAAA,EAAO,gBAAgB,cACrB,EAAK,MACL,MAAS,YAAY,eAAe,cACtC;AACF,GAMM,IAAA,CAAkB,EAAE,MAAA,GAAM,QAAA,EAAA,GAAsB,MAAqC;AACzF,QAAM,EAAE,mBAAA,GAAmB,cAAA,EAAA,IAAiB,EAAO,aAAa,WAC1D,EAAE,OAAA,GAAO,QAAA,GAAQ,SAAA,EAAA,IAAY;AAEnC,EAAA,EAAY,GAAM;AAAA,IAChB,OAAO,KAAS;AAAA,IAChB,IAAI,KAAU;AAAA,IACd,QAAQ,KAAW;AAAA,IACnB,iBAAiB;AAAA,IACjB,eAAe,GAAc,QAAQ;AAAA,IACrC,UAAU,EAAK,kBAAkB,aAAa,EAAK;AAAA,EACrD,CAAC;AACH,GAMM,IAAA,CAAoB,MAAoB;AAC5C,EAAI,EAAe,EAAI,IAAI,KAAK,KAAG,EAAkB,CAAG;AAC1D,GAEM,IAAA,CAAa,GAAmB,EAAE,MAAA,GAAM,QAAA,EAAA,MAAyB;AACrE,EAAQ,MACD,iBACH,EAAO,WAAW,EAAE,eAA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AAS,GAAa,CAAS,GAGvD,KAAW,EAAiB,GAAS,CAAS;AAAA,EACpD,GACA,EAAE,SAAS,EAAY,CACzB;AACF"}
@@ -1,7 +1,7 @@
1
- import { InsightsFeedCopy } from '../../core/types/localization/InsightsFeedCopy';
1
+ import { InsightsFeedCopy, SurveyModalCopy } from '../../core/types/localization/InsightsFeedCopy';
2
2
  import { RepeatingTransaction } from '../../core/types/RepeatingTransaction';
3
3
  import { BeatActions } from '../beatActions';
4
- import { CtaStateContext, CtaStep } from './types';
4
+ import { CtaStateContext, CtaStep, CtaSurveyAnswer } from './types';
5
5
  /**
6
6
  * The shared subscription status CTA. The answer lives on the repeating transaction
7
7
  * (`user_response`), read at render time; the words are general copy, as pulse's were. Imports
@@ -43,4 +43,6 @@ export interface SubscriptionEntryOptions {
43
43
  * repeating transaction or transaction: no CTAs, as pulse. A missing word draws nothing.
44
44
  */
45
45
  export declare const subscriptionEntryStep: ({ statusLabels, answerCounts, }: SubscriptionEntryOptions) => CtaStep;
46
+ /** A subscription entry's `surveyAnswer`: Yes writes CONFIRMED, a reason its value. */
47
+ export declare const subscriptionSurvey: (ctx: WriteCtx, copy: SurveyModalCopy) => CtaSurveyAnswer;
46
48
  export {};
@@ -0,0 +1,136 @@
1
+ import { ANALYTICS_EVENTS_CONFIG as i } from "../analytics/analyticsEventsConfig.es.js";
2
+ import { resolveAnalyticsEvent as l } from "../analytics/resolveAnalyticsEvent.es.js";
3
+ import { ctaHandlers as O } from "./ctaHandlers.es.js";
4
+ var a = {
5
+ UNKNOWN: "USER_RESPONSE_UNKNOWN",
6
+ CONFIRMED: "CONFIRMED",
7
+ CANCELLED: "CANCELLED",
8
+ NEVER_SUBSCRIBED: "NEVER_SUBSCRIBED",
9
+ WRONG_FREQUENCY: "WRONG_FREQUENCY",
10
+ ONE_TIME_PURCHASE: "ONE_TIME_PURCHASE",
11
+ OTHER: "OTHER"
12
+ }, S = {
13
+ [a.CONFIRMED]: i.SUBSCRIPTION_CONFIRMED,
14
+ [a.NEVER_SUBSCRIBED]: i.SUBSCRIPTION_NEVER_SUBSCRIBED,
15
+ [a.CANCELLED]: i.SUBSCRIPTION_CANCELLED,
16
+ [a.ONE_TIME_PURCHASE]: i.SUBSCRIPTION_ONE_TIME_PURCHASE,
17
+ [a.WRONG_FREQUENCY]: i.SUBSCRIPTION_WRONG_FREQUENCY
18
+ }, C = {
19
+ [a.OTHER]: "Other",
20
+ [a.UNKNOWN]: "Default - Response Unknown"
21
+ }, I = [
22
+ ["0", a.NEVER_SUBSCRIBED],
23
+ ["1", a.CANCELLED],
24
+ ["2", a.ONE_TIME_PURCHASE],
25
+ ["3", a.WRONG_FREQUENCY]
26
+ ], _ = (e, n) => {
27
+ const r = e.copyStore.copy.insights_feed?.general?.[n];
28
+ return typeof r == "string" && r.trim() ? r : void 0;
29
+ }, E = ({ beat: e, stores: n }) => {
30
+ const r = e.primary_repeating_transaction_guid;
31
+ return r ? n.recurringTransactionsStore.repeatingTransactions.find((t) => t.guid === r) : void 0;
32
+ }, c = ({ beat: e, stores: n, hostActions: r }, t) => {
33
+ try {
34
+ r?.onAnalyticsEvent?.(l(t, e));
35
+ } catch (s) {
36
+ n.captureException(s, {
37
+ store: "ctaActions",
38
+ template: e.template,
39
+ handler: "subscriptionAnswer"
40
+ });
41
+ }
42
+ }, d = async (e, n) => {
43
+ const r = {
44
+ beat: e.beat,
45
+ stores: e.stores,
46
+ hostActions: e.hostActions ?? {},
47
+ cta: {
48
+ label: "",
49
+ block: ""
50
+ },
51
+ slot: "primary",
52
+ params: {
53
+ userResponse: n,
54
+ repeatingTransactionGuid: e.beat.primary_repeating_transaction_guid
55
+ }
56
+ };
57
+ try {
58
+ return await O.updateRepeatingTransactionResponse(r), !0;
59
+ } catch (t) {
60
+ return e.stores.captureException(t, {
61
+ store: "ctaActions",
62
+ template: e.beat.template,
63
+ handler: "updateRepeatingTransactionResponse"
64
+ }), !1;
65
+ }
66
+ }, U = async (e, n) => {
67
+ const r = S[n];
68
+ if (r && c(e, r), !await d(e, n)) throw new Error("Failed to save the subscription answer");
69
+ }, v = (e) => c(e, i.SUBSCRIPTION_NOT_SUBSCRIBED), N = /* @__PURE__ */ new Set(), T = async (e) => {
70
+ const n = e.beat.primary_repeating_transaction_guid;
71
+ if (!n || N.has(n)) return !1;
72
+ const r = E(e)?.user_response ?? a.UNKNOWN, t = S[r]?.action ?? C[r], s = i.SUBSCRIPTION_UNDO;
73
+ c(e, {
74
+ ...s,
75
+ action: `${s.action} - Previous action: ${t}`
76
+ }), N.add(n);
77
+ try {
78
+ return await d(e, a.UNKNOWN);
79
+ } finally {
80
+ N.delete(n);
81
+ }
82
+ }, p = /* @__PURE__ */ new WeakSet(), g = (e) => {
83
+ !e.beat.primary_repeating_transaction_guid || E(e) || p.has(e.stores) || (p.add(e.stores), e.stores.recurringTransactionsStore.loadRepeatingTransactions().then(() => {
84
+ E(e) || p.delete(e.stores);
85
+ }));
86
+ }, y = ({ statusLabels: e, answerCounts: n = () => !0 }) => ({
87
+ prepare: g,
88
+ presenter: (r) => {
89
+ const t = E(r);
90
+ if (!r.beat.primary_transaction_guid || !t) return {
91
+ kind: "hidden",
92
+ hideAll: !0
93
+ };
94
+ const s = t.user_response;
95
+ if (!s || s === a.UNKNOWN || !n(r, t)) return;
96
+ const o = s === a.CONFIRMED, R = _(r.stores, o ? e.positive : e.negative), u = _(r.stores, "undo");
97
+ return !R || !u ? { kind: "hidden" } : {
98
+ kind: "status",
99
+ tone: o ? "success" : "neutral",
100
+ icon: o ? "check_circle" : "cancel",
101
+ label: R,
102
+ action: {
103
+ label: u,
104
+ onPress: () => T(r)
105
+ }
106
+ };
107
+ }
108
+ }), D = (e, n) => {
109
+ const r = I.flatMap(([t, s]) => {
110
+ const o = n.reason_options?.[t];
111
+ return o ? [{
112
+ label: o,
113
+ userResponse: s
114
+ }] : [];
115
+ });
116
+ return {
117
+ reasonOptions: r.map(({ label: t }) => t),
118
+ onSubmit: async (t) => {
119
+ const s = t === n.yes_label ? a.CONFIRMED : r.find(({ label: o }) => o === t)?.userResponse;
120
+ if (!s) throw new Error(`No subscription answer for "${t}"`);
121
+ await U(e, s);
122
+ },
123
+ onReasonsOpen: () => v(e),
124
+ showDetailField: !1
125
+ };
126
+ };
127
+ export {
128
+ a as USER_RESPONSE,
129
+ U as answerSubscription,
130
+ E as repeatingTransactionOf,
131
+ v as reportSubscriptionMarkedIncorrect,
132
+ y as subscriptionEntryStep,
133
+ D as subscriptionSurvey
134
+ };
135
+
136
+ //# sourceMappingURL=subscriptionAnswer.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptionAnswer.es.js","names":[],"sources":["../../../src/insights-v2/ctaActions/subscriptionAnswer.ts"],"sourcesContent":["import type { GlobalStore } from '../../core/stores/GlobalStore'\nimport type {\n InsightsFeedCopy,\n SurveyModalCopy,\n} from '../../core/types/localization/InsightsFeedCopy'\nimport type { RepeatingTransaction } from '../../core/types/RepeatingTransaction'\nimport {\n ANALYTICS_EVENTS_CONFIG,\n type AnalyticsEventConfigEntry,\n} from '../analytics/analyticsEventsConfig'\nimport { resolveAnalyticsEvent } from '../analytics/resolveAnalyticsEvent'\nimport type { BeatActions } from '../beatActions'\nimport { ctaHandlers } from './ctaHandlers'\nimport type {\n CtaContext,\n CtaPresentation,\n CtaStateContext,\n CtaStep,\n CtaSurveyAnswer,\n} from './types'\n\n/**\n * The shared subscription status CTA. The answer lives on the repeating transaction\n * (`user_response`), read at render time; the words are general copy, as pulse's were. Imports\n * nothing from runCtaAction, so ctaConfig can build entries at load time.\n */\n\n/** firefly's `user_response` names (Atlas::Sherlock::RepeatingTransaction::UserResponse). */\nexport const USER_RESPONSE = {\n UNKNOWN: 'USER_RESPONSE_UNKNOWN',\n CONFIRMED: 'CONFIRMED',\n CANCELLED: 'CANCELLED',\n NEVER_SUBSCRIBED: 'NEVER_SUBSCRIBED',\n WRONG_FREQUENCY: 'WRONG_FREQUENCY',\n ONE_TIME_PURCHASE: 'ONE_TIME_PURCHASE',\n OTHER: 'OTHER',\n} as const\n\ntype StateCtx = Pick<CtaStateContext, 'beat' | 'stores'>\ntype WriteCtx = StateCtx & { hostActions?: BeatActions }\n\n/** A key of `insights_feed.general` naming a status word, e.g. `confirmed`. */\ntype GeneralCopyKey = keyof InsightsFeedCopy['general']\n\n// Pulse's Subscription Confirmation event per answer.\nconst ANSWER_EVENTS: Record<string, AnalyticsEventConfigEntry> = {\n [USER_RESPONSE.CONFIRMED]: ANALYTICS_EVENTS_CONFIG.SUBSCRIPTION_CONFIRMED,\n [USER_RESPONSE.NEVER_SUBSCRIBED]: ANALYTICS_EVENTS_CONFIG.SUBSCRIPTION_NEVER_SUBSCRIBED,\n [USER_RESPONSE.CANCELLED]: ANALYTICS_EVENTS_CONFIG.SUBSCRIPTION_CANCELLED,\n [USER_RESPONSE.ONE_TIME_PURCHASE]: ANALYTICS_EVENTS_CONFIG.SUBSCRIPTION_ONE_TIME_PURCHASE,\n [USER_RESPONSE.WRONG_FREQUENCY]: ANALYTICS_EVENTS_CONFIG.SUBSCRIPTION_WRONG_FREQUENCY,\n}\n\n// Undo's \"Previous action\" for answers with no event of their own (pulse's wording).\nconst UNDO_PREVIOUS_ACTION_FALLBACK: Record<string, string> = {\n [USER_RESPONSE.OTHER]: 'Other',\n [USER_RESPONSE.UNKNOWN]: 'Default - Response Unknown',\n}\n\n// `survey_modal.reason_options` keys in pulse's order; no \"Other\" (no free text).\nconst REASON_ANSWERS: [optionKey: string, userResponse: string][] = [\n ['0', USER_RESPONSE.NEVER_SUBSCRIBED],\n ['1', USER_RESPONSE.CANCELLED],\n ['2', USER_RESPONSE.ONE_TIME_PURCHASE],\n ['3', USER_RESPONSE.WRONG_FREQUENCY],\n]\n\n/** A non-empty `insights_feed.general` word, or undefined. */\nconst generalWord = (stores: GlobalStore, key: GeneralCopyKey): string | undefined => {\n const value = stores.copyStore.copy.insights_feed?.general?.[key]\n\n return typeof value === 'string' && value.trim() ? value : undefined\n}\n\n/** The beat's repeating transaction, or undefined until loaded / when absent. */\nexport const repeatingTransactionOf = ({\n beat,\n stores,\n}: StateCtx): RepeatingTransaction | undefined => {\n const guid = beat.primary_repeating_transaction_guid\n\n return guid\n ? stores.recurringTransactionsStore.repeatingTransactions.find((rt) => rt.guid === guid)\n : undefined\n}\n\nconst reportEvent = ({ beat, stores, hostActions }: WriteCtx, event: AnalyticsEventConfigEntry) => {\n try {\n hostActions?.onAnalyticsEvent?.(resolveAnalyticsEvent(event, beat))\n } catch (error) {\n stores.captureException(error, {\n store: 'ctaActions',\n template: beat.template,\n handler: 'subscriptionAnswer',\n })\n }\n}\n\n/** Writes the beat's `user_response`; true on success, never throws. */\nconst writeUserResponse = async (ctx: WriteCtx, userResponse: string): Promise<boolean> => {\n const handlerCtx: CtaContext = {\n beat: ctx.beat,\n stores: ctx.stores,\n hostActions: ctx.hostActions ?? {},\n cta: { label: '', block: '' },\n slot: 'primary',\n params: { userResponse, repeatingTransactionGuid: ctx.beat.primary_repeating_transaction_guid },\n }\n\n try {\n await ctaHandlers.updateRepeatingTransactionResponse(handlerCtx)\n\n return true\n } catch (error) {\n ctx.stores.captureException(error, {\n store: 'ctaActions',\n template: ctx.beat.template,\n handler: 'updateRepeatingTransactionResponse',\n })\n\n return false\n }\n}\n\n/** Reports the answer (as pulse), then saves it; rejects on failure so a survey can offer Try Again. */\nexport const answerSubscription = async (ctx: WriteCtx, userResponse: string): Promise<void> => {\n const event = ANSWER_EVENTS[userResponse]\n\n if (event) reportEvent(ctx, event)\n if (!(await writeUserResponse(ctx, userResponse))) {\n throw new Error('Failed to save the subscription answer')\n }\n}\n\n/** The \"No\" press, before a reason is picked (pulse's DATA_IS_INCORRECT). */\nexport const reportSubscriptionMarkedIncorrect = (ctx: WriteCtx): void =>\n reportEvent(ctx, ANALYTICS_EVENTS_CONFIG.SUBSCRIPTION_NOT_SUBSCRIBED)\n\n// Repeating transactions with an Undo in flight; a second press is ignored.\nconst undoing = new Set<string>()\n\n/** Undo: writes USER_RESPONSE_UNKNOWN, reporting the answer it undoes. */\nconst undoSubscriptionAnswer = async (ctx: WriteCtx): Promise<boolean> => {\n const guid = ctx.beat.primary_repeating_transaction_guid\n\n if (!guid || undoing.has(guid)) return false\n\n const previous = repeatingTransactionOf(ctx)?.user_response ?? USER_RESPONSE.UNKNOWN\n const previousAction = ANSWER_EVENTS[previous]?.action ?? UNDO_PREVIOUS_ACTION_FALLBACK[previous]\n const undo = ANALYTICS_EVENTS_CONFIG.SUBSCRIPTION_UNDO\n\n reportEvent(ctx, { ...undo, action: `${undo.action} - Previous action: ${previousAction}` })\n undoing.add(guid)\n\n try {\n return await writeUserResponse(ctx, USER_RESPONSE.UNKNOWN)\n } finally {\n undoing.delete(guid)\n }\n}\n\n// One load per store, shared by every subscription card on the page.\nconst loadedStores = new WeakSet<GlobalStore>()\n\nconst ensureRepeatingTransactions = (ctx: StateCtx): void => {\n if (!ctx.beat.primary_repeating_transaction_guid || repeatingTransactionOf(ctx)) return\n if (loadedStores.has(ctx.stores)) return\n\n loadedStores.add(ctx.stores)\n // The store reports a failure itself; while the record is still missing, the next card retries.\n void ctx.stores.recurringTransactionsStore.loadRepeatingTransactions().then(() => {\n if (!repeatingTransactionOf(ctx)) loadedStores.delete(ctx.stores)\n })\n}\n\nexport interface SubscriptionEntryOptions {\n /** The `insights_feed.general` words for a positive (`CONFIRMED`) and any other answer. */\n statusLabels: { positive: GeneralCopyKey; negative: GeneralCopyKey }\n /** Whether the stored answer applies to this beat (default: every answer counts). */\n answerCounts?: (ctx: CtaStateContext, repeating: RepeatingTransaction) => boolean\n}\n\n/**\n * The step a beat's `action_key` names: the button until answered, then the status with Undo. No\n * repeating transaction or transaction: no CTAs, as pulse. A missing word draws nothing.\n */\nexport const subscriptionEntryStep = ({\n statusLabels,\n answerCounts = () => true,\n}: SubscriptionEntryOptions): CtaStep => ({\n // Every card loads it, mini too, for the row's live frequency (WEC-2147).\n prepare: ensureRepeatingTransactions,\n presenter: (ctx): CtaPresentation | undefined => {\n const repeating = repeatingTransactionOf(ctx)\n\n if (!ctx.beat.primary_transaction_guid || !repeating) return { kind: 'hidden', hideAll: true }\n\n const answer = repeating.user_response\n\n if (!answer || answer === USER_RESPONSE.UNKNOWN || !answerCounts(ctx, repeating)) {\n return undefined\n }\n\n const positive = answer === USER_RESPONSE.CONFIRMED\n const label = generalWord(ctx.stores, positive ? statusLabels.positive : statusLabels.negative)\n const undoLabel = generalWord(ctx.stores, 'undo')\n\n if (!label || !undoLabel) return { kind: 'hidden' }\n\n return {\n kind: 'status',\n tone: positive ? 'success' : 'neutral',\n icon: positive ? 'check_circle' : 'cancel',\n label,\n action: { label: undoLabel, onPress: () => undoSubscriptionAnswer(ctx) },\n }\n },\n})\n\n/** A subscription entry's `surveyAnswer`: Yes writes CONFIRMED, a reason its value. */\nexport const subscriptionSurvey = (ctx: WriteCtx, copy: SurveyModalCopy): CtaSurveyAnswer => {\n const reasons = REASON_ANSWERS.flatMap(([optionKey, userResponse]) => {\n const label = copy.reason_options?.[optionKey]\n\n return label ? [{ label, userResponse }] : []\n })\n\n return {\n reasonOptions: reasons.map(({ label }) => label),\n onSubmit: async (option) => {\n const userResponse =\n option === copy.yes_label\n ? USER_RESPONSE.CONFIRMED\n : reasons.find(({ label }) => label === option)?.userResponse\n\n if (!userResponse) throw new Error(`No subscription answer for \"${option}\"`)\n\n await answerSubscription(ctx, userResponse)\n },\n onReasonsOpen: () => reportSubscriptionMarkedIncorrect(ctx),\n showDetailField: false,\n }\n}\n"],"mappings":";;;AA4BA,IAAa,IAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,WAAW;AAAA,EACX,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,OAAO;AACT,GASM,IAA2D;AAAA,EAC9D,CAAA,EAAc,SAAA,GAAY,EAAwB;AAAA,EAClD,CAAA,EAAc,gBAAA,GAAmB,EAAwB;AAAA,EACzD,CAAA,EAAc,SAAA,GAAY,EAAwB;AAAA,EACl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,EAAc,YACd,EAAQ,KAAA,CAAM,EAAE,OAAA,EAAA,MAAY,MAAU,CAAM,GAAG;AAErD,UAAI,CAAC,EAAc,OAAM,IAAI,MAAM,+BAA+B,CAAA,GAAS;AAE3E,YAAM,EAAmB,GAAK,CAAY;AAAA,IAC5C;AAAA,IACA,eAAA,MAAqB,EAAkC,CAAG;AAAA,IAC1D,iBAAiB;AAAA,EACnB;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { Beat, PrimaryCTA, SecondaryCTA } from '../../core';
2
2
  import { GlobalStore } from '../../core/stores/GlobalStore';
3
+ import { SurveyModalCopy } from '../../core/types/localization/InsightsFeedCopy';
3
4
  import { AnalyticsEventConfigEntry } from '../analytics/analyticsEventsConfig';
4
5
  import { BeatActions } from '../beatActions';
5
6
  import { CtaStatusProps } from '../components/CtaStatus';
@@ -59,6 +60,17 @@ export interface CtaStep {
59
60
  presenter?: (ctx: CtaStateContext) => CtaPresentation | undefined;
60
61
  /** Loads what `presenter` reads, once per beat on mount. */
61
62
  prepare?: (ctx: Pick<CtaStateContext, 'beat' | 'stores'>) => void;
63
+ /** Its own reasons and save for `survey_modal_block`; default: beat feedback. */
64
+ surveyAnswer?: (ctx: Pick<CtaContext, 'beat' | 'stores' | 'hostActions'>, copy: SurveyModalCopy) => CtaSurveyAnswer;
65
+ }
66
+ /** A step's own survey, in the general survey copy. */
67
+ export interface CtaSurveyAnswer {
68
+ reasonOptions: string[];
69
+ /** Rejects on failure, so the survey offers Try Again. */
70
+ onSubmit: (option: string, detail?: string) => Promise<void>;
71
+ onReasonsOpen?: () => void;
72
+ /** Default true: the last reason reveals a free-text field. */
73
+ showDetailField?: boolean;
62
74
  }
63
75
  /** Context for a handler run directly from a drawer (no card CTA / slot involved). */
64
76
  export type CtaHandlerContext = Omit<CtaContext, 'cta' | 'slot'>;
@@ -10,8 +10,11 @@ export interface BeatCtaActions {
10
10
  /**
11
11
  * The card's click runner plus per-slot enabled state. Call from an `observer` so `disabledWhen`
12
12
  * store reads re-render. `beatActions` is a parameter: BaseLayout mounts its provider below this.
13
+ * `linkCta`: mini and micro send the card's action as the link, so its step's `prepare` runs too.
13
14
  */
14
- export declare const useBeatCtaActions: (beat: Beat, beatActions?: BeatActions, primaryCta?: PrimaryCTA | SecondaryCTA, secondaryCta?: PrimaryCTA | SecondaryCTA) => BeatCtaActions;
15
+ export declare const useBeatCtaActions: (beat: Beat, beatActions?: BeatActions, primaryCta?: PrimaryCTA | SecondaryCTA, secondaryCta?: PrimaryCTA | SecondaryCTA, linkCta?: {
16
+ action_key?: string | null;
17
+ }) => BeatCtaActions;
15
18
  /**
16
19
  * Runs a handler from inside a drawer, e.g. `runHandler('createBudget', { categoryGuid, amount },
17
20
  * { onSuccess: ['refreshBeat'] })`. Inside a block, pass `useBeatActions()` as `beatActions`.
@@ -1,56 +1,56 @@
1
- import { useGlobalStore as p } from "../../common/context/hooks.es.js";
2
- import { resolveCtaState as c, resolveStep as C, runCtaAction as d, runCtaHandler as f } from "./runCtaAction.es.js";
3
- import { useEffect as v } from "react";
4
- var l = {
1
+ import { useGlobalStore as i } from "../../common/context/hooks.es.js";
2
+ import { resolveCtaState as p, resolveStep as l, runCtaAction as f, runCtaHandler as v } from "./runCtaAction.es.js";
3
+ import { useEffect as A } from "react";
4
+ var u = {
5
5
  label: "",
6
6
  block: ""
7
- }, S = (t, o = {}, s = l, a = l) => {
8
- const r = p(), e = C({ cta: s }).prepare, n = {
9
- beat: t,
10
- stores: r,
7
+ }, x = (r, o = {}, e = u, a = u, s) => {
8
+ const t = i(), c = l({ cta: e }).prepare ?? (s && l({ cta: s }).prepare), n = {
9
+ beat: r,
10
+ stores: t,
11
11
  hostActions: o
12
12
  };
13
- return v(() => {
14
- e?.({
15
- beat: t,
16
- stores: r
13
+ return A(() => {
14
+ c?.({
15
+ beat: r,
16
+ stores: t
17
17
  });
18
18
  }, [
19
- t.guid,
20
- e,
21
- r
19
+ r.guid,
20
+ c,
21
+ t
22
22
  ]), {
23
- runCta: (u, i, m = {}) => d({
24
- beat: t,
25
- cta: i,
26
- slot: u,
27
- stores: r,
23
+ runCta: (m, C, d = {}) => f({
24
+ beat: r,
25
+ cta: C,
26
+ slot: m,
27
+ stores: t,
28
28
  hostActions: o,
29
- params: m
29
+ params: d
30
30
  }),
31
- primary: c({
31
+ primary: p({
32
32
  ...n,
33
- cta: s,
33
+ cta: e,
34
34
  slot: "primary"
35
35
  }),
36
- secondary: c({
36
+ secondary: p({
37
37
  ...n,
38
38
  cta: a,
39
39
  slot: "secondary"
40
40
  })
41
41
  };
42
- }, x = (t, o = {}) => {
43
- const s = p();
44
- return (a, r = {}, e) => f({
45
- beat: t,
46
- stores: s,
42
+ }, E = (r, o = {}) => {
43
+ const e = i();
44
+ return (a, s = {}, t) => v({
45
+ beat: r,
46
+ stores: e,
47
47
  hostActions: o,
48
- params: r
49
- }, a, e);
48
+ params: s
49
+ }, a, t);
50
50
  };
51
51
  export {
52
- S as useBeatCtaActions,
53
- x as useCtaHandler
52
+ x as useBeatCtaActions,
53
+ E as useCtaHandler
54
54
  };
55
55
 
56
56
  //# sourceMappingURL=useCtaAction.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCtaAction.es.js","names":[],"sources":["../../../src/insights-v2/ctaActions/useCtaAction.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nimport type { Beat, PrimaryCTA, SecondaryCTA } from '../../core'\nimport { useGlobalStore } from '../../common'\nimport type { BeatActions } from '../beatActions'\nimport type { CtaHandlerName } from './ctaHandlers'\nimport { resolveCtaState, resolveStep, runCtaAction, runCtaHandler } from './runCtaAction'\nimport type { CtaSlot, CtaState, RunHandlerOptions } from './types'\n\nconst EMPTY_CTA: PrimaryCTA = { label: '', block: '' }\n\nexport interface BeatCtaActions {\n runCta: (\n slot: CtaSlot,\n cta: PrimaryCTA | SecondaryCTA,\n params?: Record<string, unknown>,\n ) => Promise<void>\n primary: CtaState\n secondary: CtaState\n}\n\n/**\n * The card's click runner plus per-slot enabled state. Call from an `observer` so `disabledWhen`\n * store reads re-render. `beatActions` is a parameter: BaseLayout mounts its provider below this.\n */\nexport const useBeatCtaActions = (\n beat: Beat,\n beatActions: BeatActions = {},\n primaryCta: PrimaryCTA | SecondaryCTA = EMPTY_CTA,\n secondaryCta: PrimaryCTA | SecondaryCTA = EMPTY_CTA,\n): BeatCtaActions => {\n const stores = useGlobalStore()\n const prepare = resolveStep({ cta: primaryCta }).prepare\n const stateCtx = { beat, stores, hostActions: beatActions }\n\n // Once per beat (beat.guid; the beat object can be new each render): load what the step reads.\n useEffect(() => {\n prepare?.({ beat, stores })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [beat.guid, prepare, stores])\n\n return {\n runCta: (slot, cta, params = {}) =>\n runCtaAction({ beat, cta, slot, stores, hostActions: beatActions, params }),\n primary: resolveCtaState({ ...stateCtx, cta: primaryCta, slot: 'primary' }),\n secondary: resolveCtaState({ ...stateCtx, cta: secondaryCta, slot: 'secondary' }),\n }\n}\n\n/**\n * Runs a handler from inside a drawer, e.g. `runHandler('createBudget', { categoryGuid, amount },\n * { onSuccess: ['refreshBeat'] })`. Inside a block, pass `useBeatActions()` as `beatActions`.\n */\nexport const useCtaHandler = (beat: Beat, beatActions: BeatActions = {}) => {\n const stores = useGlobalStore()\n\n return (\n handlerName: CtaHandlerName,\n params: Record<string, unknown> = {},\n options?: RunHandlerOptions,\n ) => runCtaHandler({ beat, stores, hostActions: beatActions, params }, handlerName, options)\n}\n"],"mappings":";;;AASA,IAAM,IAAwB;AAAA,EAAE,OAAO;AAAA,EAAI,OAAO;AAAG,GAgBxC,IAAA,CACX,GACA,IAA2B,CAAC,GAC5B,IAAwC,GACxC,IAA0C,MACvB;AACnB,QAAM,IAAS,EAAe,GACxB,IAAU,EAAY,EAAE,KAAK,EAAW,CAAC,EAAE,SAC3C,IAAW;AAAA,IAAE,MAAA;AAAA,IAAM,QAAA;AAAA,IAAQ,aAAa;AAAA,EAAY;AAG1D,SAAA,EAAA,MAAgB;AACd,IAAA,IAAU;AAAA,MAAE,MAAA;AAAA,MAAM,QAAA;AAAA,IAAO,CAAC;AAAA,EAE5B,GAAG;AAAA,IAAC,EAAK;AAAA,IAAM;AAAA,IAAS;AAAA,EAAM,CAAC,GAExB;AAAA,IACL,QAAA,CAAS,GAAM,GAAK,IAAS,CAAC,MAC5B,EAAa;AAAA,MAAE,MAAA;AAAA,MAAM,KAAA;AAAA,MAAK,MAAA;AAAA,MAAM,QAAA;AAAA,MAAQ,aAAa;AAAA,MAAa,QAAA;AAAA,IAAO,CAAC;AAAA,IAC5E,SAAS,EAAgB;AAAA,MAAE,GAAG;AAAA,MAAU,KAAK;AAAA,MAAY,MAAM;AAAA,IAAU,CAAC;AAAA,IAC1E,WAAW,EAAgB;AAAA,MAAE,GAAG;AAAA,MAAU,KAAK;AAAA,MAAc,MAAM;AAAA,IAAY,CAAC;AAAA,EAClF;AACF,GAMa,IAAA,CAAiB,GAAY,IAA2B,CAAC,MAAM;AAC1E,QAAM,IAAS,EAAe;AAE9B,SAAA,CACE,GACA,IAAkC,CAAC,GACnC,MACG,EAAc;AAAA,IAAE,MAAA;AAAA,IAAM,QAAA;AAAA,IAAQ,aAAa;AAAA,IAAa,QAAA;AAAA,EAAO,GAAG,GAAa,CAAO;AAC7F"}
1
+ {"version":3,"file":"useCtaAction.es.js","names":[],"sources":["../../../src/insights-v2/ctaActions/useCtaAction.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nimport type { Beat, PrimaryCTA, SecondaryCTA } from '../../core'\nimport { useGlobalStore } from '../../common'\nimport type { BeatActions } from '../beatActions'\nimport type { CtaHandlerName } from './ctaHandlers'\nimport { resolveCtaState, resolveStep, runCtaAction, runCtaHandler } from './runCtaAction'\nimport type { CtaSlot, CtaState, RunHandlerOptions } from './types'\n\nconst EMPTY_CTA: PrimaryCTA = { label: '', block: '' }\n\nexport interface BeatCtaActions {\n runCta: (\n slot: CtaSlot,\n cta: PrimaryCTA | SecondaryCTA,\n params?: Record<string, unknown>,\n ) => Promise<void>\n primary: CtaState\n secondary: CtaState\n}\n\n/**\n * The card's click runner plus per-slot enabled state. Call from an `observer` so `disabledWhen`\n * store reads re-render. `beatActions` is a parameter: BaseLayout mounts its provider below this.\n * `linkCta`: mini and micro send the card's action as the link, so its step's `prepare` runs too.\n */\nexport const useBeatCtaActions = (\n beat: Beat,\n beatActions: BeatActions = {},\n primaryCta: PrimaryCTA | SecondaryCTA = EMPTY_CTA,\n secondaryCta: PrimaryCTA | SecondaryCTA = EMPTY_CTA,\n linkCta?: { action_key?: string | null },\n): BeatCtaActions => {\n const stores = useGlobalStore()\n const prepare =\n resolveStep({ cta: primaryCta }).prepare ?? (linkCta && resolveStep({ cta: linkCta }).prepare)\n const stateCtx = { beat, stores, hostActions: beatActions }\n\n // Once per beat (beat.guid; the beat object can be new each render): load what the step reads.\n useEffect(() => {\n prepare?.({ beat, stores })\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [beat.guid, prepare, stores])\n\n return {\n runCta: (slot, cta, params = {}) =>\n runCtaAction({ beat, cta, slot, stores, hostActions: beatActions, params }),\n primary: resolveCtaState({ ...stateCtx, cta: primaryCta, slot: 'primary' }),\n secondary: resolveCtaState({ ...stateCtx, cta: secondaryCta, slot: 'secondary' }),\n }\n}\n\n/**\n * Runs a handler from inside a drawer, e.g. `runHandler('createBudget', { categoryGuid, amount },\n * { onSuccess: ['refreshBeat'] })`. Inside a block, pass `useBeatActions()` as `beatActions`.\n */\nexport const useCtaHandler = (beat: Beat, beatActions: BeatActions = {}) => {\n const stores = useGlobalStore()\n\n return (\n handlerName: CtaHandlerName,\n params: Record<string, unknown> = {},\n options?: RunHandlerOptions,\n ) => runCtaHandler({ beat, stores, hostActions: beatActions, params }, handlerName, options)\n}\n"],"mappings":";;;AASA,IAAM,IAAwB;AAAA,EAAE,OAAO;AAAA,EAAI,OAAO;AAAG,GAiBxC,IAAA,CACX,GACA,IAA2B,CAAC,GAC5B,IAAwC,GACxC,IAA0C,GAC1C,MACmB;AAC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K: string;
16
17
  CREDIT_UTILIZATION_ACTION_BLOCK: string;
17
18
  EMERGENCY_SAVINGS_ACTION_BLOCK: string;
@@ -12,6 +12,7 @@ var _ = {
12
12
  TRANSACTION_LIST_ACTION_BLOCK: "transaction_list_block",
13
13
  REMAINING_CASH_ACTION_BLOCK: "remaining_cash_block",
14
14
  AMOUNT_INPUT_MODAL_ACTION_BLOCK: "amount_input_modal_block",
15
+ SAFETY_NET_ACTION_BLOCK: "safety_net_block",
15
16
  OVERDRAFT_ACTION_BLOCK: "transparent_overdraft_block",
16
17
  CREDIT_UTILIZATION_ACTION_BLOCK: "credit_utilization_block",
17
18
  EMERGENCY_SAVINGS_ACTION_BLOCK: "emergency_savings_block",
@@ -1 +1 @@
1
- {"version":3,"file":"actionBlocksKey.es.js","names":[],"sources":["../../../src/insights-v2/mappings/actionBlocksKey.ts"],"sourcesContent":["// Keys for the drawer drilldown registry in `blocks.ts`, extracted into their own module.\n//\n// Why: chart blocks (e.g. BarchartBlock, DoubleBarChartBlock) need\n// `TRANSCATION_HISTORY_ACTION_BLOCK` to tag a chart bar's drilldown context, but they are\n// themselves re-exported through `../blocks` -> `mappings/blocks.ts` imports from that same\n// barrel to build its `blocks` registry. Importing the key straight from `mappings/blocks.ts`\n// closed that loop into a circular import: evaluating `mappings/blocks.ts` pulled in the\n// `blocks` barrel, which (before it got to `ComponentBlocks`/`AccountBlock`) loaded\n// `BarchartBlock`, which imported back into the still-initializing `mappings/blocks.ts` —\n// tripping a \"Cannot access 'AccountBlock' before initialization\" TDZ error in Storybook/Vite.\n//\n// Keeping the keys here (no dependency on `mappings/blocks.ts`) lets chart blocks reference\n// them without re-entering that module.\n//\n// Names follow ditto: its registry ends every CTA block in `_block` and the V2 envelope copies those\n// names verbatim (`transaction_details_block`, `contact_support_block`, `make_transfer_block`).\nexport const actionBlocksKey = {\n PLACEHOLDER_ACTION_BLOCK: 'placeholder_block',\n MAKE_TRANSFER_ACTION_BLOCK: 'make_transfer_block',\n TRANSCATION_HISTORY_ACTION_BLOCK: 'transaction_history_block',\n TRANSACTION_DETAILS_ACTION_BLOCK: 'transaction_details_block',\n CONTACT_SUPPORT_ACTION_BLOCK: 'contact_support_block',\n FEEDBACK_MODAL_ACTION_BLOCK: 'feedback_modal_block',\n CONNECTION_DETAIL_ACTION_BLOCK: 'connection_detail_block',\n CONNECT_WIDGET_ACTION_BLOCK: 'connect_widget_block',\n SURVEY_MODAL_ACTION_BLOCK: 'survey_modal_block',\n RECURRING_TRANSACTION_ACTION_BLOCK: 'recurring_transaction_block',\n TRANSACTION_LIST_ACTION_BLOCK: 'transaction_list_block',\n REMAINING_CASH_ACTION_BLOCK: 'remaining_cash_block',\n AMOUNT_INPUT_MODAL_ACTION_BLOCK: 'amount_input_modal_block',\n OVERDRAFT_ACTION_BLOCK: 'transparent_overdraft_block',\n CREDIT_UTILIZATION_ACTION_BLOCK: 'credit_utilization_block',\n EMERGENCY_SAVINGS_ACTION_BLOCK: 'emergency_savings_block',\n PAYOFF_CALCULATOR_ACTION_BLOCK: 'payoff_calculator_block',\n BUDGET_DETAILS_ACTION_BLOCK: 'budget_details_block',\n ACCOUNT_DETAILS_ACTION_BLOCK: 'account_details_block',\n ACCOUNT_LIST_ACTION_BLOCK: 'account_list_block',\n}\n"],"mappings":"AAgBA,IAAa,IAAkB;AAAA,EAC7B,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAC5B,kCAAkC;AAAA,EAClC,kCAAkC;AAAA,EAClC,8BAA8B;AAAA,EAC9B,6BAA6B;AAAA,EAC7B,gCAAgC;AAAA,EAChC,6BAA6B;AAAA,EAC7B,2BAA2B;AAAA,EAC3B,oCAAoC;AAAA,EACpC,+BAA+B;AAAA,EAC/B,6BAA6B;AAAA,EAC7B,iCAAiC;AAAA,EACjC,wBAAwB;AAAA,EACxB,iCAAiC;AAAA,EACjC,gCAAgC;AAAA,EAChC,gCAAgC;AAAA,EAChC,6BAA6B;AAAA,EAC7B,8BAA8B;AAAA,EAC9B,2BAA2B;AAC7B"}
1
+ {"version":3,"file":"actionBlocksKey.es.js","names":[],"sources":["../../../src/insights-v2/mappings/actionBlocksKey.ts"],"sourcesContent":["// Keys for the drawer drilldown registry in `blocks.ts`, extracted into their own module.\n//\n// Why: chart blocks (e.g. BarchartBlock, DoubleBarChartBlock) need\n// `TRANSCATION_HISTORY_ACTION_BLOCK` to tag a chart bar's drilldown context, but they are\n// themselves re-exported through `../blocks` -> `mappings/blocks.ts` imports from that same\n// barrel to build its `blocks` registry. Importing the key straight from `mappings/blocks.ts`\n// closed that loop into a circular import: evaluating `mappings/blocks.ts` pulled in the\n// `blocks` barrel, which (before it got to `ComponentBlocks`/`AccountBlock`) loaded\n// `BarchartBlock`, which imported back into the still-initializing `mappings/blocks.ts` —\n// tripping a \"Cannot access 'AccountBlock' before initialization\" TDZ error in Storybook/Vite.\n//\n// Keeping the keys here (no dependency on `mappings/blocks.ts`) lets chart blocks reference\n// them without re-entering that module.\n//\n// Names follow ditto: its registry ends every CTA block in `_block` and the V2 envelope copies those\n// names verbatim (`transaction_details_block`, `contact_support_block`, `make_transfer_block`).\nexport const actionBlocksKey = {\n PLACEHOLDER_ACTION_BLOCK: 'placeholder_block',\n MAKE_TRANSFER_ACTION_BLOCK: 'make_transfer_block',\n TRANSCATION_HISTORY_ACTION_BLOCK: 'transaction_history_block',\n TRANSACTION_DETAILS_ACTION_BLOCK: 'transaction_details_block',\n CONTACT_SUPPORT_ACTION_BLOCK: 'contact_support_block',\n FEEDBACK_MODAL_ACTION_BLOCK: 'feedback_modal_block',\n CONNECTION_DETAIL_ACTION_BLOCK: 'connection_detail_block',\n CONNECT_WIDGET_ACTION_BLOCK: 'connect_widget_block',\n SURVEY_MODAL_ACTION_BLOCK: 'survey_modal_block',\n RECURRING_TRANSACTION_ACTION_BLOCK: 'recurring_transaction_block',\n TRANSACTION_LIST_ACTION_BLOCK: 'transaction_list_block',\n REMAINING_CASH_ACTION_BLOCK: 'remaining_cash_block',\n AMOUNT_INPUT_MODAL_ACTION_BLOCK: 'amount_input_modal_block',\n SAFETY_NET_ACTION_BLOCK: 'safety_net_block',\n OVERDRAFT_ACTION_BLOCK: 'transparent_overdraft_block',\n CREDIT_UTILIZATION_ACTION_BLOCK: 'credit_utilization_block',\n EMERGENCY_SAVINGS_ACTION_BLOCK: 'emergency_savings_block',\n PAYOFF_CALCULATOR_ACTION_BLOCK: 'payoff_calculator_block',\n BUDGET_DETAILS_ACTION_BLOCK: 'budget_details_block',\n ACCOUNT_DETAILS_ACTION_BLOCK: 'account_details_block',\n ACCOUNT_LIST_ACTION_BLOCK: 'account_list_block',\n}\n"],"mappings":"AAgBA,IAAa,IAAkB;AAAA,EAC7B,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAC5B,kCAAkC;AAAA,EAClC,kCAAkC;AAAA,EAClC,8BAA8B;AAAA,EAC9B,6BAA6B;AAAA,EAC7B,gCAAgC;AAAA,EAChC,6BAA6B;AAAA,EAC7B,2BAA2B;AAAA,EAC3B,oCAAoC;AAAA,EACpC,+BAA+B;AAAA,EAC/B,6BAA6B;AAAA,EAC7B,iCAAiC;AAAA,EACjC,yBAAyB;AAAA,EACzB,wBAAwB;AAAA,EACxB,iCAAiC;AAAA,EACjC,gCAAgC;AAAA,EAChC,gCAAgC;AAAA,EAChC,6BAA6B;AAAA,EAC7B,8BAA8B;AAAA,EAC9B,2BAA2B;AAC7B"}