@mx-cartographer/experiences 9.7.87 → 9.7.89
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/CHANGELOG.md +11 -1
- package/dist/core/stores/InsightsV2Store.d.ts +2 -2
- package/dist/core/stores/InsightsV2Store.es.js.map +1 -1
- package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/TransactionBlock.d.ts +4 -3
- package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/TransactionBlock.es.js +103 -90
- package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/TransactionBlock.es.js.map +1 -1
- package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/layout.d.ts +8 -0
- package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/layout.es.js +12 -4
- package/dist/insights-v2/blocks/ComponentBlocks/TransactionBlock/layout.es.js.map +1 -1
- package/dist/insights-v2/ctaActions/index.d.ts +2 -2
- package/dist/insights-v2/ctaActions/runCtaAction.d.ts +7 -1
- package/dist/insights-v2/ctaActions/runCtaAction.es.js +110 -68
- package/dist/insights-v2/ctaActions/runCtaAction.es.js.map +1 -1
- package/dist/insights-v2/ctaActions/subscriptionAnswer.es.js +53 -49
- package/dist/insights-v2/ctaActions/subscriptionAnswer.es.js.map +1 -1
- package/dist/insights-v2/ctaActions/types.d.ts +6 -2
- package/dist/insights-v2/ctaActions/useCtaAction.es.js.map +1 -1
- package/dist/insights-v2/index.d.ts +2 -2
- package/dist/insights-v2/index.es.js +132 -130
- package/package.json +1 -1
|
@@ -1,106 +1,148 @@
|
|
|
1
|
-
import { sendBeatCta as
|
|
2
|
-
import { ANALYTICS_EVENTS_CONFIG as
|
|
3
|
-
import { resolveAnalyticsEvent as
|
|
4
|
-
import { HOST_ACTIONS as
|
|
5
|
-
import { ctaHandlers as
|
|
6
|
-
import { ctaActions as
|
|
7
|
-
import { resolveCtaMetadata as
|
|
8
|
-
import { hasDrawerBlock as
|
|
9
|
-
var
|
|
10
|
-
const a =
|
|
1
|
+
import { sendBeatCta as y } from "../../common/utils/PostMessage.es.js";
|
|
2
|
+
import { ANALYTICS_EVENTS_CONFIG as p } from "../analytics/analyticsEventsConfig.es.js";
|
|
3
|
+
import { resolveAnalyticsEvent as g } from "../analytics/resolveAnalyticsEvent.es.js";
|
|
4
|
+
import { HOST_ACTIONS as h } from "./hostActions.es.js";
|
|
5
|
+
import { ctaHandlers as w } from "./ctaHandlers.es.js";
|
|
6
|
+
import { ctaActions as S } from "./ctaConfig.es.js";
|
|
7
|
+
import { resolveCtaMetadata as A } from "./ctaPostMessages.es.js";
|
|
8
|
+
import { hasDrawerBlock as k } from "../mappings/hasDrawerBlock.es.js";
|
|
9
|
+
var E = {}, l = ({ cta: t }) => t.action_key && S[t.action_key] || E, D = (t) => {
|
|
10
|
+
const a = l(t), e = t.stores.insightsV2Store.ctaStatus[t.beat.guid] === "pending", r = a.presenter?.(t);
|
|
11
11
|
return {
|
|
12
|
-
disabled:
|
|
13
|
-
...
|
|
12
|
+
disabled: e || (a.disabledWhen?.(t) ?? !1),
|
|
13
|
+
...r && { presentation: r }
|
|
14
14
|
};
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
const { is_mobile_webview:
|
|
19
|
-
|
|
15
|
+
}, T = ({ beat: t, slot: a, stores: e }) => {
|
|
16
|
+
e.insightsV2Store.openCtaDrawer(t.guid, a === "primary" ? "primaryCta" : "secondaryCta");
|
|
17
|
+
}, b = ({ beat: t, stores: a }, e) => {
|
|
18
|
+
const { is_mobile_webview: r, clientConfig: n } = a.appDataStore.appConfig, { event: i, action: s, payload: c } = e;
|
|
19
|
+
y(t, {
|
|
20
20
|
event: i ?? void 0,
|
|
21
|
-
op:
|
|
22
|
-
extras:
|
|
23
|
-
isMobileWebview:
|
|
24
|
-
webviewScheme:
|
|
21
|
+
op: s ?? void 0,
|
|
22
|
+
extras: c ?? void 0,
|
|
23
|
+
isMobileWebview: r,
|
|
24
|
+
webviewScheme: n?.master?.ui_message_webview_url_scheme,
|
|
25
25
|
userGuid: t.insights_payload?.user_guid ?? t.user_guid
|
|
26
26
|
});
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
}, m = (t, a) => {
|
|
28
|
+
const e = t.next ?? (t.run ? "none" : "default");
|
|
29
|
+
return e === "drawer" || e === "default" && k(a.block);
|
|
30
|
+
}, I = (t, { beat: a, stores: e }) => {
|
|
31
|
+
t === "refreshBeat" && e.emitUpdate({ staleBeatGuid: a.guid });
|
|
31
32
|
}, o = (t, a) => {
|
|
32
33
|
try {
|
|
33
|
-
t.hostActions.onAnalyticsEvent?.(
|
|
34
|
-
} catch (
|
|
35
|
-
t.stores.captureException(
|
|
34
|
+
t.hostActions.onAnalyticsEvent?.(g(a, t.beat));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
t.stores.captureException(e, {
|
|
36
37
|
store: "ctaActions",
|
|
37
38
|
template: t.beat.template,
|
|
38
39
|
handler: "sendCtaAnalytics"
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
|
-
},
|
|
42
|
-
const { beat: a, slot:
|
|
43
|
-
|
|
42
|
+
}, O = (t) => {
|
|
43
|
+
const { beat: a, slot: e, hostActions: r, stores: n } = t;
|
|
44
|
+
e !== "primary" || a.cta_clicked_at || (o(t, p.FIRST_TIME_PRIMARY_ACTION_SELECTED), Promise.resolve().then(() => r.onCtaAction?.({
|
|
44
45
|
beatGuid: a.guid,
|
|
45
|
-
name:
|
|
46
|
-
})).catch((i) =>
|
|
46
|
+
name: h.markCtaClicked
|
|
47
|
+
})).catch((i) => n.captureException(i, {
|
|
47
48
|
store: "ctaActions",
|
|
48
49
|
template: a.template,
|
|
49
50
|
handler: "markCtaClicked"
|
|
50
51
|
})));
|
|
51
|
-
},
|
|
52
|
-
o(t, t.slot === "primary" ?
|
|
53
|
-
},
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
56
|
-
await
|
|
57
|
-
for (const
|
|
58
|
-
}, d = async ({ beat: t, stores: a },
|
|
59
|
-
const { insightsV2Store:
|
|
60
|
-
|
|
52
|
+
}, R = (t, { skipCtaClicked: a = !1 } = {}) => {
|
|
53
|
+
o(t, t.slot === "primary" ? p.PRIMARY_ACTION_SELECTED : p.SECONDARY_ACTION_SELECTED), a || O(t);
|
|
54
|
+
}, u = async (t, a, e) => {
|
|
55
|
+
const r = w[a];
|
|
56
|
+
if (!r) throw new Error(`Unknown CTA handler "${a}"`);
|
|
57
|
+
await r(t);
|
|
58
|
+
for (const n of e) I(n, t);
|
|
59
|
+
}, d = async ({ beat: t, stores: a }, e, r = {}) => {
|
|
60
|
+
const { insightsV2Store: n } = a;
|
|
61
|
+
n.setCtaStatus(t.guid, "pending");
|
|
61
62
|
try {
|
|
62
|
-
return await
|
|
63
|
+
return await e(), n.setCtaStatus(t.guid, "done"), !0;
|
|
63
64
|
} catch (i) {
|
|
64
|
-
return
|
|
65
|
+
return n.setCtaStatus(t.guid, "error"), a.captureException(i, {
|
|
65
66
|
store: "ctaActions",
|
|
66
67
|
template: t.template,
|
|
67
|
-
...
|
|
68
|
+
...r
|
|
68
69
|
}), !1;
|
|
69
70
|
}
|
|
70
|
-
},
|
|
71
|
-
const
|
|
72
|
-
|
|
71
|
+
}, C = (t, a) => {
|
|
72
|
+
const e = typeof t.params == "function" ? t.params(a) : t.params;
|
|
73
|
+
return {
|
|
74
|
+
...a,
|
|
73
75
|
params: {
|
|
74
|
-
...
|
|
75
|
-
...
|
|
76
|
+
...e,
|
|
77
|
+
...a.params
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
80
|
+
}, Y = async (t) => {
|
|
81
|
+
const a = l(t), e = C(a, t);
|
|
82
|
+
R(e, { skipCtaClicked: a.skipCtaClicked }), await d(e, async () => {
|
|
83
|
+
a.run && await u(e, a.run, a.onSuccess ?? []), a.analytics && o(e, a.analytics);
|
|
84
|
+
const r = A(e);
|
|
85
|
+
r && b(e, r), m(a, e.cta) && T(e);
|
|
84
86
|
});
|
|
85
|
-
},
|
|
87
|
+
}, U = async ({ beat: t, stores: a, hostActions: e = {} }) => {
|
|
88
|
+
const r = t.insights_payload?.in_description_cta;
|
|
89
|
+
if (!r) return;
|
|
90
|
+
const n = {
|
|
91
|
+
...r,
|
|
92
|
+
block: r.block ?? ""
|
|
93
|
+
}, i = l({ cta: n });
|
|
94
|
+
try {
|
|
95
|
+
const s = C(i, {
|
|
96
|
+
beat: t,
|
|
97
|
+
cta: n,
|
|
98
|
+
slot: "primary",
|
|
99
|
+
stores: a,
|
|
100
|
+
hostActions: e,
|
|
101
|
+
params: {}
|
|
102
|
+
});
|
|
103
|
+
await i.prepare?.(s);
|
|
104
|
+
const { disabled: c, presentation: f } = D(s);
|
|
105
|
+
if (c || f) return;
|
|
106
|
+
if (i.run) {
|
|
107
|
+
const { run: v, onSuccess: _ = [] } = i;
|
|
108
|
+
if (!await d(s, () => u(s, v, _))) return;
|
|
109
|
+
}
|
|
110
|
+
m(i, n) && !a.insightsV2Store.actionDrawer.isDrawerOpen && a.insightsV2Store.openActionDrawer({
|
|
111
|
+
guid: t.guid,
|
|
112
|
+
trigger: "inDescriptionCta",
|
|
113
|
+
cta: {
|
|
114
|
+
block: n.block,
|
|
115
|
+
variant: n.variant,
|
|
116
|
+
action_key: n.action_key
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
} catch (s) {
|
|
120
|
+
a.captureException(s, {
|
|
121
|
+
store: "ctaActions",
|
|
122
|
+
template: t.template,
|
|
123
|
+
handler: "runInDescriptionCta"
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, M = {
|
|
86
127
|
label: "",
|
|
87
128
|
block: ""
|
|
88
|
-
},
|
|
89
|
-
const
|
|
129
|
+
}, W = (t, a, { onSuccess: e = [], analytics: r } = {}) => {
|
|
130
|
+
const n = {
|
|
90
131
|
...t,
|
|
91
|
-
cta:
|
|
132
|
+
cta: M,
|
|
92
133
|
slot: "primary"
|
|
93
134
|
};
|
|
94
|
-
return d(
|
|
95
|
-
await
|
|
135
|
+
return d(n, async () => {
|
|
136
|
+
await u(n, a, e), r && o(n, r);
|
|
96
137
|
}, { handler: a });
|
|
97
138
|
};
|
|
98
139
|
export {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
140
|
+
R as reportCtaClick,
|
|
141
|
+
D as resolveCtaState,
|
|
142
|
+
l as resolveStep,
|
|
143
|
+
Y as runCtaAction,
|
|
144
|
+
W as runCtaHandler,
|
|
145
|
+
U as runInDescriptionCta,
|
|
104
146
|
o as sendCtaAnalytics
|
|
105
147
|
};
|
|
106
148
|
|
|
@@ -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 }: { 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,gBA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AC,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 RunInDescriptionCtaArgs,\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 * Whether the step's target opens the drawer: `drawer` always, `default` only for a real block (a\n * missing block never implies a post message), `none` never. Omitted: `none` with `run`, else `default`.\n */\nconst opensDrawer = (step: CtaStep, cta: { block?: string | null }) => {\n const target = step.next ?? (step.run ? 'none' : 'default')\n\n return target === 'drawer' || (target === 'default' && hasDrawerBlock(cta.block))\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/** The step's params, overridden by the caller's. */\nconst withStepParams = (step: CtaStep, ctx: CtaContext): CtaContext => {\n const stepParams = typeof step.params === 'function' ? step.params(ctx) : step.params\n\n return { ...ctx, params: { ...stepParams, ...ctx.params } }\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 stepCtx = withStepParams(step, ctx)\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 if (opensDrawer(step, stepCtx.cta)) openDrawerForSlot(stepCtx)\n })\n}\n\n/**\n * A pinned beat's auto-open: runs the card action's (`in_description_cta`) step and opens its block,\n * with no press analytics or post message. Does nothing while the step shows a status (e.g. an\n * answered subscription), nothing or a disabled button. Never rejects: failures are reported.\n */\nexport const runInDescriptionCta = async ({\n beat,\n stores,\n hostActions = {},\n}: RunInDescriptionCtaArgs): Promise<void> => {\n const link = beat.insights_payload?.in_description_cta\n\n if (!link) return\n\n const cta = { ...link, block: link.block ?? '' }\n const step = resolveStep({ cta })\n\n try {\n const ctx = withStepParams(step, {\n beat,\n cta,\n slot: 'primary',\n stores,\n hostActions,\n params: {},\n })\n\n await step.prepare?.(ctx)\n\n // Read after the load; `disabled` also covers a press made meanwhile (pending).\n const { disabled, presentation } = resolveCtaState(ctx)\n\n if (disabled || presentation) return\n\n if (step.run) {\n const { run, onSuccess = [] } = step\n\n if (!(await withCtaStatus(ctx, () => runHandlerWithEffects(ctx, run, onSuccess)))) return\n }\n\n // Never replaces a drawer the user opened meanwhile.\n if (opensDrawer(step, cta) && !stores.insightsV2Store.actionDrawer.isDrawerOpen) {\n stores.insightsV2Store.openActionDrawer({\n guid: beat.guid,\n trigger: 'inDescriptionCta',\n cta: { block: cta.block, variant: cta.variant, action_key: cta.action_key },\n })\n }\n } catch (error) {\n stores.captureException(error, {\n store: 'ctaActions',\n template: beat.template,\n handler: 'runInDescriptionCta',\n })\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":";;;;;;;;AAwBA,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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AAAA,MACX,SAAS;AAAA,MACT,KAAK;AAAA,QAAE,OAAO,EAAI;AAAA,QAAO,SAAS,EAAI;AAAA,QAAS,YAAY,EAAI;AAAA,MAAW;AAAA,IAC5E,CAAC;AAAA,EAEL,SAAS,GAAO;AACd,IAAA,EAAO,iBAAiB,GAAO;AAAA,MAC7B,OAAO;AAAA,MACP,UAAU,EAAK;AAAA,MACf,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF,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"}
|
|
@@ -23,24 +23,24 @@ var a = {
|
|
|
23
23
|
["1", a.CANCELLED],
|
|
24
24
|
["2", a.ONE_TIME_PURCHASE],
|
|
25
25
|
["3", a.WRONG_FREQUENCY]
|
|
26
|
-
],
|
|
27
|
-
const
|
|
28
|
-
return typeof
|
|
29
|
-
},
|
|
30
|
-
const
|
|
31
|
-
return
|
|
32
|
-
}, _ = ({ beat: e, stores:
|
|
26
|
+
], d = (e, r) => {
|
|
27
|
+
const n = e.copyStore.copy.insights_feed?.general?.[r];
|
|
28
|
+
return typeof n == "string" && n.trim() ? n : void 0;
|
|
29
|
+
}, p = ({ beat: e, stores: r }) => {
|
|
30
|
+
const n = e.primary_repeating_transaction_guid;
|
|
31
|
+
return n ? r.recurringTransactionsStore.repeatingTransactions.find((t) => t.guid === n) : void 0;
|
|
32
|
+
}, _ = ({ beat: e, stores: r, hostActions: n }, t) => {
|
|
33
33
|
try {
|
|
34
|
-
|
|
34
|
+
n?.onAnalyticsEvent?.(I(t, e));
|
|
35
35
|
} catch (o) {
|
|
36
|
-
|
|
36
|
+
r.captureException(o, {
|
|
37
37
|
store: "ctaActions",
|
|
38
38
|
template: e.template,
|
|
39
39
|
handler: "subscriptionAnswer"
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
}, C = async (e,
|
|
43
|
-
const
|
|
42
|
+
}, C = async (e, r) => {
|
|
43
|
+
const n = {
|
|
44
44
|
beat: e.beat,
|
|
45
45
|
stores: e.stores,
|
|
46
46
|
hostActions: e.hostActions ?? {},
|
|
@@ -50,12 +50,12 @@ var a = {
|
|
|
50
50
|
},
|
|
51
51
|
slot: "primary",
|
|
52
52
|
params: {
|
|
53
|
-
userResponse:
|
|
53
|
+
userResponse: r,
|
|
54
54
|
repeatingTransactionGuid: e.beat.primary_repeating_transaction_guid
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
try {
|
|
58
|
-
return await U.updateRepeatingTransactionResponse(
|
|
58
|
+
return await U.updateRepeatingTransactionResponse(n), !0;
|
|
59
59
|
} catch (t) {
|
|
60
60
|
return e.stores.captureException(t, {
|
|
61
61
|
store: "ctaActions",
|
|
@@ -63,79 +63,83 @@ var a = {
|
|
|
63
63
|
handler: "updateRepeatingTransactionResponse"
|
|
64
64
|
}), !1;
|
|
65
65
|
}
|
|
66
|
-
},
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
},
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
72
|
-
const
|
|
66
|
+
}, g = async (e, r) => {
|
|
67
|
+
const n = O[r];
|
|
68
|
+
if (n && _(e, n), !await C(e, r)) throw new Error("Failed to save the subscription answer");
|
|
69
|
+
}, A = (e) => _(e, i.SUBSCRIPTION_NOT_SUBSCRIBED), u = /* @__PURE__ */ new Set(), f = async (e) => {
|
|
70
|
+
const r = e.beat.primary_repeating_transaction_guid;
|
|
71
|
+
if (!r || u.has(r)) return !1;
|
|
72
|
+
const n = p(e)?.user_response ?? a.UNKNOWN, t = O[n]?.action ?? v[n], o = i.SUBSCRIPTION_UNDO;
|
|
73
73
|
_(e, {
|
|
74
74
|
...o,
|
|
75
75
|
action: `${o.action} - Previous action: ${t}`
|
|
76
|
-
}),
|
|
76
|
+
}), u.add(r);
|
|
77
77
|
try {
|
|
78
78
|
return await C(e, a.UNKNOWN);
|
|
79
79
|
} finally {
|
|
80
|
-
|
|
80
|
+
u.delete(r);
|
|
81
81
|
}
|
|
82
|
-
},
|
|
83
|
-
!e.beat.primary_repeating_transaction_guid ||
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
}, N = /* @__PURE__ */ new WeakMap(), y = (e) => {
|
|
83
|
+
if (!e.beat.primary_repeating_transaction_guid || p(e)) return;
|
|
84
|
+
let r = N.get(e.stores);
|
|
85
|
+
return r || (r = e.stores.recurringTransactionsStore.loadRepeatingTransactions().then(() => {
|
|
86
|
+
p(e) || N.delete(e.stores);
|
|
87
|
+
}, () => {
|
|
88
|
+
N.delete(e.stores);
|
|
89
|
+
}), N.set(e.stores, r)), r;
|
|
90
|
+
}, B = ({ statusLabels: e, sx: r, negativeSx: n, answeredTitle: t, answerCounts: o = () => !0 }) => ({
|
|
87
91
|
prepare: y,
|
|
88
92
|
presenter: (s) => {
|
|
89
|
-
const
|
|
90
|
-
if (!s.beat.primary_transaction_guid || !
|
|
93
|
+
const c = p(s);
|
|
94
|
+
if (!s.beat.primary_transaction_guid || !c) return {
|
|
91
95
|
kind: "hidden",
|
|
92
96
|
hideAll: !0
|
|
93
97
|
};
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
96
|
-
const E =
|
|
97
|
-
return !S || !
|
|
98
|
+
const R = c.user_response;
|
|
99
|
+
if (!R || R === a.UNKNOWN || !o(s, c)) return;
|
|
100
|
+
const E = R === a.CONFIRMED, S = d(s.stores, E ? e.positive : e.negative), l = d(s.stores, "undo");
|
|
101
|
+
return !S || !l ? { kind: "hidden" } : {
|
|
98
102
|
kind: "status",
|
|
99
103
|
tone: E ? "success" : "neutral",
|
|
100
104
|
icon: E ? "check_circle" : "cancel",
|
|
101
105
|
label: S,
|
|
102
|
-
sx: E || !
|
|
103
|
-
...
|
|
104
|
-
...
|
|
106
|
+
sx: E || !n ? r : {
|
|
107
|
+
...r,
|
|
108
|
+
...n
|
|
105
109
|
},
|
|
106
110
|
title: t?.(s.stores.copyStore.copy) || void 0,
|
|
107
111
|
action: {
|
|
108
|
-
label:
|
|
112
|
+
label: l,
|
|
109
113
|
onPress: () => f(s)
|
|
110
114
|
}
|
|
111
115
|
};
|
|
112
116
|
}
|
|
113
|
-
}),
|
|
114
|
-
const
|
|
115
|
-
const s =
|
|
117
|
+
}), h = (e, r) => {
|
|
118
|
+
const n = T.flatMap(([t, o]) => {
|
|
119
|
+
const s = r.reason_options?.[t];
|
|
116
120
|
return s ? [{
|
|
117
121
|
label: s,
|
|
118
122
|
userResponse: o
|
|
119
123
|
}] : [];
|
|
120
124
|
});
|
|
121
125
|
return {
|
|
122
|
-
reasonOptions:
|
|
126
|
+
reasonOptions: n.map(({ label: t }) => t),
|
|
123
127
|
onSubmit: async (t) => {
|
|
124
|
-
const o = t ===
|
|
128
|
+
const o = t === r.yes_label ? a.CONFIRMED : n.find(({ label: s }) => s === t)?.userResponse;
|
|
125
129
|
if (!o) throw new Error(`No subscription answer for "${t}"`);
|
|
126
|
-
await
|
|
130
|
+
await g(e, o);
|
|
127
131
|
},
|
|
128
|
-
onReasonsOpen: () =>
|
|
132
|
+
onReasonsOpen: () => A(e),
|
|
129
133
|
showDetailField: !1
|
|
130
134
|
};
|
|
131
135
|
};
|
|
132
136
|
export {
|
|
133
137
|
a as USER_RESPONSE,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
g as answerSubscription,
|
|
139
|
+
p as repeatingTransactionOf,
|
|
140
|
+
A as reportSubscriptionMarkedIncorrect,
|
|
141
|
+
B as subscriptionEntryStep,
|
|
142
|
+
h as subscriptionSurvey
|
|
139
143
|
};
|
|
140
144
|
|
|
141
145
|
//# sourceMappingURL=subscriptionAnswer.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptionAnswer.es.js","names":[],"sources":["../../../src/insights-v2/ctaActions/subscriptionAnswer.ts"],"sourcesContent":["import type { SxProps, Theme } from '@mui/material/styles'\nimport type { GlobalCopy } from '../../core/types/GlobalCopy'\nimport 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 /** Status bar overrides for this step (e.g. a taller bar). */\n sx?: SxProps<Theme>\n /** Extra overrides for a negative answer's bar (on top of `sx`), e.g. its own neutral look. */\n negativeSx?: SxProps<Theme>\n /** The card's title once answered, from copy (mini and micro retitle; full keeps its title). */\n answeredTitle?: (copy: GlobalCopy) => string | undefined\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 sx,\n negativeSx,\n answeredTitle,\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 sx: positive || !negativeSx ? sx : ({ ...sx, ...negativeSx } as SxProps<Theme>),\n title: answeredTitle?.(ctx.stores.copyStore.copy) || undefined,\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":";;;AA8BA,IAAa,IAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,WAAW;AAAA,EACX,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,OAAO;A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EAAe,QAAA,CAAS,CAAC,GAAW,CAAA,MAAkB;AACpE,UAAM,IAAQ,EAAK,iBAAiB,CAAA;AAEpC,WAAO,IAAQ,CAAC;AAAA,MAAE,OAAA;AAAA,MAAO,cAAA;AAAA,IAAa,CAAC,IAAI,CAAC;AAAA,EAC9C,CAAC;AAED,SAAO;AAAA,IACL,eAAe,EAAQ,IAAA,CAAK,EAAE,OAAA,EAAA,MAAY,CAAK;AAAA,IAC/C,UAAU,OAAO,MAAW;AAC1B,YAAM,IACJ,MAAW,EAAK,YACZ,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
|
+
{"version":3,"file":"subscriptionAnswer.es.js","names":[],"sources":["../../../src/insights-v2/ctaActions/subscriptionAnswer.ts"],"sourcesContent":["import type { SxProps, Theme } from '@mui/material/styles'\nimport type { GlobalCopy } from '../../core/types/GlobalCopy'\nimport 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 loads = new WeakMap<GlobalStore, Promise<void>>()\n\nconst ensureRepeatingTransactions = (ctx: StateCtx): Promise<void> | undefined => {\n if (!ctx.beat.primary_repeating_transaction_guid || repeatingTransactionOf(ctx)) return\n\n let load = loads.get(ctx.stores)\n\n if (!load) {\n // The store reports a failure itself; while the record is still missing, the next card retries.\n load = ctx.stores.recurringTransactionsStore.loadRepeatingTransactions().then(\n () => {\n if (!repeatingTransactionOf(ctx)) loads.delete(ctx.stores)\n },\n () => {\n loads.delete(ctx.stores)\n },\n )\n loads.set(ctx.stores, load)\n }\n\n return load\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 /** Status bar overrides for this step (e.g. a taller bar). */\n sx?: SxProps<Theme>\n /** Extra overrides for a negative answer's bar (on top of `sx`), e.g. its own neutral look. */\n negativeSx?: SxProps<Theme>\n /** The card's title once answered, from copy (mini and micro retitle; full keeps its title). */\n answeredTitle?: (copy: GlobalCopy) => string | undefined\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 sx,\n negativeSx,\n answeredTitle,\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 sx: positive || !negativeSx ? sx : ({ ...sx, ...negativeSx } as SxProps<Theme>),\n title: answeredTitle?.(ctx.stores.copyStore.copy) || undefined,\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":";;;AA8BA,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,EAClD,CAAA,EAAc,iBAAA,GAAoB,EAAwB;AAAA,EAC1D,CAAA,EAAc,eAAA,GAAkB,EAAwB;AAC3D,GAGM,IAAwD;AAAA,EAC3D,CAAA,EAAc,KAAA,GAAQ;AAAA,EACtB,CAAA,EAAc,OAAA,GAAU;AAC3B,GAGM,IAA8D;AAAA,EAClE,CAAC,KAAK,EAAc,gBAAgB;AAAA,EACpC,CAAC,KAAK,EAAc,SAAS;AAAA,EAC7B,CAAC,KAAK,EAAc,iBAAiB;AAAA,EACrC,CAAC,KAAK,EAAc,eAAe;AACrC,GAGM,IAAA,CAAe,GAAqB,MAA4C;AACpF,QAAM,IAAQ,EAAO,UAAU,KAAK,eAAe,UAAU,CAAA;AAE7D,SAAO,OAAO,KAAU,YAAY,EAAM,KAAK,IAAI,IAAQ;AAC7D,GAGa,IAAA,CAA0B,EACrC,MAA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,EACnB;AACF"}
|
|
@@ -61,8 +61,8 @@ export interface CtaStep {
|
|
|
61
61
|
disabledWhen?: (ctx: CtaStateContext) => boolean;
|
|
62
62
|
/** Draw a status or nothing instead of the button; undefined = the button. */
|
|
63
63
|
presenter?: (ctx: CtaStateContext) => CtaPresentation | undefined;
|
|
64
|
-
/** Loads what `presenter` reads, once per beat on mount. */
|
|
65
|
-
prepare?: (ctx: Pick<CtaStateContext, 'beat' | 'stores'>) => void;
|
|
64
|
+
/** Loads what `presenter` reads, once per beat on mount (resolving when loaded). */
|
|
65
|
+
prepare?: (ctx: Pick<CtaStateContext, 'beat' | 'stores'>) => Promise<void> | void;
|
|
66
66
|
/**
|
|
67
67
|
* Mini and micro mirror this step's `presenter` when their card action (`in_description_cta`)
|
|
68
68
|
* names it: the status's action word as the label and its `title`. Default: they keep the link.
|
|
@@ -88,5 +88,9 @@ export interface RunHandlerOptions {
|
|
|
88
88
|
/** Catalogue entry (e.g. ANALYTICS_EVENTS_CONFIG.X) fired after the handler resolves (drawer Saves). */
|
|
89
89
|
analytics?: AnalyticsEventConfigEntry;
|
|
90
90
|
}
|
|
91
|
+
/** `runInDescriptionCta`'s input: the beat's micro envelope and the host actions of the pinned beat. */
|
|
92
|
+
export interface RunInDescriptionCtaArgs extends Pick<CtaContext, 'beat' | 'stores'> {
|
|
93
|
+
hostActions?: BeatActions;
|
|
94
|
+
}
|
|
91
95
|
/** A named side effect. Must throw (or reject) on failure so the runner can report it. */
|
|
92
96
|
export type CtaHandler = (ctx: CtaContext) => Promise<void> | void;
|
|
@@ -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 { CtaPresentation, 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 /** The link step's presentation when it mirrors on mini (`compactStatus`); otherwise undefined. */\n linkPresentation?: CtaPresentation\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, and\n * a `compactStatus` step's presentation comes back as `linkPresentation`.\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 linkStep = linkCta?.action_key ? resolveStep({ cta: linkCta }) : undefined\n const prepare = resolveStep({ cta: primaryCta }).prepare ?? linkStep?.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 // Display only (mini runs nothing), so the presentation alone: no disabled / pending state.\n linkPresentation: linkStep?.compactStatus\n ? linkStep.presenter?.({ ...stateCtx, cta: { ...EMPTY_CTA, ...linkCta }, slot: 'primary' })\n : undefined,\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,GAoBxC,IAAA,CACX,GACA,IAA2B,CAAC,GAC5B,IAAwC,GACxC,IAA0C,GAC1C,MACmB;AACnB,QAAM,IAAS,EAAe,GACxB,IAAW,GAAS,aAAa,EAAY,EAAE,KAAK,EAAQ,CAAC,IAAI,QACjE,IAAU,EAAY,EAAE,KAAK,EAAW,CAAC,EAAE,WAAW,GAAU,SAChE,IAAW;AAAA,IAAE,MAAA;AAAA,IAAM,QAAA;AAAA,IAAQ,aAAa;AAAA,EAAY;AAG1D,SAAA,EAAA,MAAgB;AACd,IAAA,
|
|
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 { CtaPresentation, 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 /** The link step's presentation when it mirrors on mini (`compactStatus`); otherwise undefined. */\n linkPresentation?: CtaPresentation\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, and\n * a `compactStatus` step's presentation comes back as `linkPresentation`.\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 linkStep = linkCta?.action_key ? resolveStep({ cta: linkCta }) : undefined\n const prepare = resolveStep({ cta: primaryCta }).prepare ?? linkStep?.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 void 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 // Display only (mini runs nothing), so the presentation alone: no disabled / pending state.\n linkPresentation: linkStep?.compactStatus\n ? linkStep.presenter?.({ ...stateCtx, cta: { ...EMPTY_CTA, ...linkCta }, slot: 'primary' })\n : undefined,\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,GAoBxC,IAAA,CACX,GACA,IAA2B,CAAC,GAC5B,IAAwC,GACxC,IAA0C,GAC1C,MACmB;AACnB,QAAM,IAAS,EAAe,GACxB,IAAW,GAAS,aAAa,EAAY,EAAE,KAAK,EAAQ,CAAC,IAAI,QACjE,IAAU,EAAY,EAAE,KAAK,EAAW,CAAC,EAAE,WAAW,GAAU,SAChE,IAAW;AAAA,IAAE,MAAA;AAAA,IAAM,QAAA;AAAA,IAAQ,aAAa;AAAA,EAAY;AAG1D,SAAA,EAAA,MAAgB;AACd,IAAA,IAAe;AAAA,MAAE,MAAA;AAAA,MAAM,QAAA;AAAA,IAAO,CAAC;AAAA,EAEjC,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,IAEhF,kBAAkB,GAAU,gBACxB,EAAS,YAAY;AAAA,MAAE,GAAG;AAAA,MAAU,KAAK;AAAA,QAAE,GAAG;AAAA,QAAW,GAAG;AAAA,MAAQ;AAAA,MAAG,MAAM;AAAA,IAAU,CAAC,IACxF;AAAA,EACN;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"}
|
|
@@ -30,8 +30,8 @@ export { default as FeedbackModal, type FeedbackModalContent } from './component
|
|
|
30
30
|
export { default as SurveyModal, type SurveyModalContent, type SurveyModalOption, } from './components/SurveyModal';
|
|
31
31
|
export { default as StatusSnackbar, type StatusSnackbarProps, } from './components/shared/StatusSnackbar';
|
|
32
32
|
export { ObsolesceBanner, type ObsolesceBannerProps, type ObsolesceBannerState, type ObsolesceBannerCopy, } from './components/ObsolesceBanner';
|
|
33
|
-
export { HOST_ACTIONS, useBeatCtaActions, useCtaHandler } from './ctaActions';
|
|
34
|
-
export type { BeatCtaActions, CtaContext, CtaEffect, CtaHandlerName, CtaParams, CtaStateContext, CtaStep, HostActionName, RunHandlerOptions, } from './ctaActions';
|
|
33
|
+
export { HOST_ACTIONS, runInDescriptionCta, useBeatCtaActions, useCtaHandler } from './ctaActions';
|
|
34
|
+
export type { BeatCtaActions, CtaContext, CtaEffect, CtaHandlerName, CtaParams, CtaStateContext, CtaStep, HostActionName, RunHandlerOptions, RunInDescriptionCtaArgs, } from './ctaActions';
|
|
35
35
|
export { useBeatActions, type BeatActions, type CtaActionParams, type MenuActionHandlers, type UpdateParams, type FeedbackParams, type DismissParams, type InsightMenuAction, type InsightRating, } from './beatActions';
|
|
36
36
|
export { default as LogoTile } from './components/LogoTile';
|
|
37
37
|
export { default as MerchantHighlightCard } from './components/MerchantHighlightCard';
|