@burdenoff/microfe-subscriberbot 2026.1102.4 → 2026.1102.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stories/pages/DashboardPage.stories.d.ts +4 -0
- package/dist/stories/pages/DashboardPage.stories.d.ts.map +1 -1
- package/dist/stories/pages/RelationshipsListPage.stories.d.ts +5 -0
- package/dist/stories/pages/RelationshipsListPage.stories.d.ts.map +1 -1
- package/dist/stories/pages/WorkflowBuilderPage.stories.d.ts +14 -0
- package/dist/stories/pages/WorkflowBuilderPage.stories.d.ts.map +1 -0
- package/dist/stories/pages/WorkflowsPage.stories.d.ts +1 -0
- package/dist/stories/pages/WorkflowsPage.stories.d.ts.map +1 -1
- package/dist/stories/support/fixtures.d.ts +6 -1
- package/dist/stories/support/fixtures.d.ts.map +1 -1
- package/dist/stories/support/handlers.d.ts.map +1 -1
- package/dist/stories/support/phoneViewport.d.ts +4 -0
- package/dist/stories/support/phoneViewport.d.ts.map +1 -0
- package/dist/subscriberbot/SubscriberBotRoutes.d.ts.map +1 -1
- package/dist/subscriberbot/SubscriberBotRoutes.js +27 -23
- package/dist/subscriberbot/SubscriberBotRoutes.js.map +1 -1
- package/dist/subscriberbot/components/PageLayout.d.ts.map +1 -1
- package/dist/subscriberbot/components/PageLayout.js +3 -3
- package/dist/subscriberbot/components/PageLayout.js.map +1 -1
- package/dist/subscriberbot/components/mobile/MobileDashboard.d.ts +18 -0
- package/dist/subscriberbot/components/mobile/MobileDashboard.d.ts.map +1 -0
- package/dist/subscriberbot/components/mobile/MobileDashboard.js +247 -0
- package/dist/subscriberbot/components/mobile/MobileDashboard.js.map +1 -0
- package/dist/subscriberbot/components/mobile/MobileRelationshipList.d.ts +10 -0
- package/dist/subscriberbot/components/mobile/MobileRelationshipList.d.ts.map +1 -0
- package/dist/subscriberbot/components/mobile/MobileRelationshipList.js +217 -0
- package/dist/subscriberbot/components/mobile/MobileRelationshipList.js.map +1 -0
- package/dist/subscriberbot/components/mobile/MobileScreen.d.ts +26 -0
- package/dist/subscriberbot/components/mobile/MobileScreen.d.ts.map +1 -0
- package/dist/subscriberbot/components/mobile/MobileScreen.js +46 -0
- package/dist/subscriberbot/components/mobile/MobileScreen.js.map +1 -0
- package/dist/subscriberbot/components/mobile/RelationshipGlyph.d.ts +10 -0
- package/dist/subscriberbot/components/mobile/RelationshipGlyph.d.ts.map +1 -0
- package/dist/subscriberbot/components/mobile/RelationshipGlyph.js +25 -0
- package/dist/subscriberbot/components/mobile/RelationshipGlyph.js.map +1 -0
- package/dist/subscriberbot/components/mobile/index.d.ts +9 -0
- package/dist/subscriberbot/components/mobile/index.d.ts.map +1 -0
- package/dist/subscriberbot/components/mobile/index.js +4 -0
- package/dist/subscriberbot/hooks/index.d.ts +1 -0
- package/dist/subscriberbot/hooks/index.d.ts.map +1 -1
- package/dist/subscriberbot/hooks/index.js +1 -0
- package/dist/subscriberbot/hooks/useCompactViewport.d.ts +13 -0
- package/dist/subscriberbot/hooks/useCompactViewport.d.ts.map +1 -0
- package/dist/subscriberbot/hooks/useCompactViewport.js +21 -0
- package/dist/subscriberbot/hooks/useCompactViewport.js.map +1 -0
- package/dist/subscriberbot/hooks/useSubscriberBotApi.d.ts +10 -1
- package/dist/subscriberbot/hooks/useSubscriberBotApi.d.ts.map +1 -1
- package/dist/subscriberbot/hooks/useSubscriberBotApi.js +113 -79
- package/dist/subscriberbot/hooks/useSubscriberBotApi.js.map +1 -1
- package/dist/subscriberbot/pages/DashboardPage.d.ts.map +1 -1
- package/dist/subscriberbot/pages/DashboardPage.js +166 -189
- package/dist/subscriberbot/pages/DashboardPage.js.map +1 -1
- package/dist/subscriberbot/pages/WorkflowsPage.d.ts +4 -4
- package/dist/subscriberbot/pages/WorkflowsPage.d.ts.map +1 -1
- package/dist/subscriberbot/pages/WorkflowsPage.js +201 -190
- package/dist/subscriberbot/pages/WorkflowsPage.js.map +1 -1
- package/dist/subscriberbot/pages/relationships/RelationshipDetailPage.d.ts.map +1 -1
- package/dist/subscriberbot/pages/relationships/RelationshipDetailPage.js +120 -119
- package/dist/subscriberbot/pages/relationships/RelationshipDetailPage.js.map +1 -1
- package/dist/subscriberbot/pages/relationships/RelationshipsListPage.d.ts.map +1 -1
- package/dist/subscriberbot/pages/relationships/RelationshipsListPage.js +226 -212
- package/dist/subscriberbot/pages/relationships/RelationshipsListPage.js.map +1 -1
- package/dist/subscriberbot/pages/workflows/WorkflowBuilderPage.d.ts +3 -0
- package/dist/subscriberbot/pages/workflows/WorkflowBuilderPage.d.ts.map +1 -0
- package/dist/subscriberbot/pages/workflows/WorkflowBuilderPage.js +648 -0
- package/dist/subscriberbot/pages/workflows/WorkflowBuilderPage.js.map +1 -0
- package/dist/subscriberbot/pages/workflows/workflowBuilderGraph.d.ts +60 -0
- package/dist/subscriberbot/pages/workflows/workflowBuilderGraph.d.ts.map +1 -0
- package/dist/subscriberbot/pages/workflows/workflowBuilderGraph.js +122 -0
- package/dist/subscriberbot/pages/workflows/workflowBuilderGraph.js.map +1 -0
- package/dist/subscriberbot/types/index.d.ts +65 -0
- package/dist/subscriberbot/types/index.d.ts.map +1 -1
- package/dist/subscriberbot/utils/pageContext.d.ts.map +1 -1
- package/dist/subscriberbot/utils/pageContext.js +21 -13
- package/dist/subscriberbot/utils/pageContext.js.map +1 -1
- package/dist/subscriberbot/utils/portfolio.d.ts +106 -0
- package/dist/subscriberbot/utils/portfolio.d.ts.map +1 -0
- package/dist/subscriberbot/utils/portfolio.js +151 -0
- package/dist/subscriberbot/utils/portfolio.js.map +1 -0
- package/package.json +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageContext.js","names":[],"sources":["../../../src/subscriberbot/utils/pageContext.ts"],"sourcesContent":["/**\n * Page context for the Subscriber Bot assistant.\n *\n * `gatherPageContext()` runs before every assistant turn and its result is sent\n * to the assistant sandbox, which keeps only the keys in the agent's\n * `ALLOWED_CONTEXT_KEYS` (ai-assistant `src/context-loader.ts`). Nothing filters\n * on this side, so every key returned here crosses the wire: return only\n * allow-listed keys, and never a message body, a payment-instrument detail or\n * anything else that identifies a person. `userAgent` and `timestamp` are\n * deliberately absent for the same reason (AI readiness criteria 3.1 and 3.3).\n *\n * `entityType` + `entityId` are what let the agent act on \"this\" in one turn\n * (\"unsubscribe from this\", \"pause this\", \"cancel this\"), so every page that has\n * an addressable entity in its URL must resolve here.\n */\n\n/**\n * The keys the assistant agent forwards to the model. Kept in step with\n * `ALLOWED_CONTEXT_KEYS` in ai-assistant `src/context-loader.ts`; the unit test\n * asserts that `gatherPageContext()` never returns a key outside this list.\n */\nexport const ASSISTANT_ALLOWED_CONTEXT_KEYS = [\n 'currentUrl',\n 'currentPage',\n 'entityType',\n 'entityId',\n 'entityName',\n 'pageTitle',\n 'pageType',\n 'activeTab',\n 'activeTool',\n 'selectedText',\n 'workspaceId',\n 'workspaceName',\n 'projectId',\n 'projectName',\n 'platform',\n 'version',\n 'viewportSize',\n] as const;\n\nexport type AssistantContextKey = (typeof ASSISTANT_ALLOWED_CONTEXT_KEYS)[number];\n\n/** Entity types the Subscriber Bot routes resolve to. The agent guide documents each one. */\nexport const SUBSCRIBERBOT_ENTITY_TYPES = {\n relationship: 'SUBSCRIBERBOT_RELATIONSHIP',\n provider: 'SUBSCRIBERBOT_PROVIDER',\n agent: 'SUBSCRIBERBOT_AGENT',\n decision: 'SUBSCRIBERBOT_DECISION',\n inboxMessage: 'SUBSCRIBERBOT_INBOX_MESSAGE',\n workflow: 'SUBSCRIBERBOT_WORKFLOW',\n} as const;\n\nexport type SubscriberBotEntityType =\n (typeof SUBSCRIBERBOT_ENTITY_TYPES)[keyof typeof SUBSCRIBERBOT_ENTITY_TYPES];\n\nexport interface ConversationContextShape {\n entityType?: SubscriberBotEntityType;\n entityId?: string;\n activeTab?: string;\n}\n\nexport type PageContext = Partial<Record<AssistantContextKey, string>> & {\n currentUrl: string;\n currentPage: string;\n platform: string;\n version: string;\n viewportSize: string;\n};\n\n/**\n * Route segment → entity type, for every route that carries one entity id.\n * Each entry mirrors a route in `SubscriberBotRoutes.tsx`; a pattern for a\n * route the app does not define would never match a real page.\n */\nconst ENTITY_ROUTES: ReadonlyArray<readonly [segment: string, type: SubscriberBotEntityType]> = [\n ['relationships', SUBSCRIBERBOT_ENTITY_TYPES.relationship],\n ['providers', SUBSCRIBERBOT_ENTITY_TYPES.provider],\n ['agents', SUBSCRIBERBOT_ENTITY_TYPES.agent],\n ['decisions', SUBSCRIBERBOT_ENTITY_TYPES.decision],\n ['inbox', SUBSCRIBERBOT_ENTITY_TYPES.inboxMessage],\n ['workflows', SUBSCRIBERBOT_ENTITY_TYPES.workflow],\n];\n\n/** Static sub-routes that sit where an id would (\"relationships/new\" is a form, not an entity). */\nconst NON_ENTITY_SEGMENTS: ReadonlySet<string> = new Set(['new']);\n\n/** Ids are opaque, but they are path segments: no separators, no whitespace, bounded length. */\nconst ENTITY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\n/** Tab names are short identifiers; anything else is ignored rather than forwarded. */\nconst TAB_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;\n\nfunction decodeSegment(segment: string): string | undefined {\n try {\n return decodeURIComponent(segment);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve the entity the user is looking at from the router location.\n *\n * `pathname` is the full browser path; the Subscriber Bot routes live under\n * `/subscriberbot`. Anything that is not an entity route resolves to an empty\n * entity, so the agent asks rather than acting on a guessed id.\n */\nexport function resolveSubscriberBotConversationContext(\n pathname: string,\n search: string\n): ConversationContextShape {\n const segments = pathname.split('/').filter(Boolean);\n const root = segments.indexOf('subscriberbot');\n const rest = root === -1 ? [] : segments.slice(root + 1);\n\n const tabParam = new URLSearchParams(search).get('tab');\n const activeTab = tabParam && TAB_PATTERN.test(tabParam) ? tabParam : undefined;\n\n if (rest.length === 2) {\n const [section, rawId] = rest as [string, string];\n const route = ENTITY_ROUTES.find(([segment]) => segment === section);\n const id = decodeSegment(rawId);\n if (route && id && !NON_ENTITY_SEGMENTS.has(id) && ENTITY_ID_PATTERN.test(id)) {\n return { entityType: route[1], entityId: id, ...(activeTab ? { activeTab } : {}) };\n }\n }\n\n return activeTab ? { activeTab } : {};\n}\n\nexport function gatherPageContext(): PageContext {\n const { href, pathname, search } = window.location;\n const currentPage = pathname.split('/').filter(Boolean).slice(0, 3).join('/') || 'home';\n const entity = resolveSubscriberBotConversationContext(pathname, search);\n\n return {\n currentUrl: href,\n currentPage,\n ...(entity.entityType && entity.entityId\n ? { entityType: entity.entityType, entityId: entity.entityId }\n : {}),\n ...(entity.activeTab ? { activeTab: entity.activeTab } : {}),\n platform: 'subscriberbot',\n version: import.meta.env.VITE_APP_VERSION ?? '2026.615.1',\n viewportSize: `${window.innerWidth}x${window.innerHeight}`,\n };\n}\n"],"mappings":";AA4CA,IAAa,IAA6B;CACxC,cAAc;CACd,UAAU;CACV,OAAO;CACP,UAAU;CACV,cAAc;CACd,UAAU;AACZ,GAwBM,IAA0F;CAC9F,CAAC,iBAAiB,EAA2B,YAAY;CACzD,CAAC,aAAa,EAA2B,QAAQ;CACjD,CAAC,UAAU,EAA2B,KAAK;CAC3C,CAAC,aAAa,EAA2B,QAAQ;CACjD,CAAC,SAAS,EAA2B,YAAY;CACjD,CAAC,aAAa,EAA2B,QAAQ;AACnD,
|
|
1
|
+
{"version":3,"file":"pageContext.js","names":[],"sources":["../../../src/subscriberbot/utils/pageContext.ts"],"sourcesContent":["/**\n * Page context for the Subscriber Bot assistant.\n *\n * `gatherPageContext()` runs before every assistant turn and its result is sent\n * to the assistant sandbox, which keeps only the keys in the agent's\n * `ALLOWED_CONTEXT_KEYS` (ai-assistant `src/context-loader.ts`). Nothing filters\n * on this side, so every key returned here crosses the wire: return only\n * allow-listed keys, and never a message body, a payment-instrument detail or\n * anything else that identifies a person. `userAgent` and `timestamp` are\n * deliberately absent for the same reason (AI readiness criteria 3.1 and 3.3).\n *\n * `entityType` + `entityId` are what let the agent act on \"this\" in one turn\n * (\"unsubscribe from this\", \"pause this\", \"cancel this\"), so every page that has\n * an addressable entity in its URL must resolve here.\n */\n\n/**\n * The keys the assistant agent forwards to the model. Kept in step with\n * `ALLOWED_CONTEXT_KEYS` in ai-assistant `src/context-loader.ts`; the unit test\n * asserts that `gatherPageContext()` never returns a key outside this list.\n */\nexport const ASSISTANT_ALLOWED_CONTEXT_KEYS = [\n 'currentUrl',\n 'currentPage',\n 'entityType',\n 'entityId',\n 'entityName',\n 'pageTitle',\n 'pageType',\n 'activeTab',\n 'activeTool',\n 'selectedText',\n 'workspaceId',\n 'workspaceName',\n 'projectId',\n 'projectName',\n 'platform',\n 'version',\n 'viewportSize',\n] as const;\n\nexport type AssistantContextKey = (typeof ASSISTANT_ALLOWED_CONTEXT_KEYS)[number];\n\n/** Entity types the Subscriber Bot routes resolve to. The agent guide documents each one. */\nexport const SUBSCRIBERBOT_ENTITY_TYPES = {\n relationship: 'SUBSCRIBERBOT_RELATIONSHIP',\n provider: 'SUBSCRIBERBOT_PROVIDER',\n agent: 'SUBSCRIBERBOT_AGENT',\n decision: 'SUBSCRIBERBOT_DECISION',\n inboxMessage: 'SUBSCRIBERBOT_INBOX_MESSAGE',\n workflow: 'SUBSCRIBERBOT_WORKFLOW',\n} as const;\n\nexport type SubscriberBotEntityType =\n (typeof SUBSCRIBERBOT_ENTITY_TYPES)[keyof typeof SUBSCRIBERBOT_ENTITY_TYPES];\n\nexport interface ConversationContextShape {\n entityType?: SubscriberBotEntityType;\n entityId?: string;\n activeTab?: string;\n}\n\nexport type PageContext = Partial<Record<AssistantContextKey, string>> & {\n currentUrl: string;\n currentPage: string;\n platform: string;\n version: string;\n viewportSize: string;\n};\n\n/**\n * Route segment → entity type, for every route that carries one entity id.\n * Each entry mirrors a route in `SubscriberBotRoutes.tsx`; a pattern for a\n * route the app does not define would never match a real page.\n */\nconst ENTITY_ROUTES: ReadonlyArray<readonly [segment: string, type: SubscriberBotEntityType]> = [\n ['relationships', SUBSCRIBERBOT_ENTITY_TYPES.relationship],\n ['providers', SUBSCRIBERBOT_ENTITY_TYPES.provider],\n ['agents', SUBSCRIBERBOT_ENTITY_TYPES.agent],\n ['decisions', SUBSCRIBERBOT_ENTITY_TYPES.decision],\n ['inbox', SUBSCRIBERBOT_ENTITY_TYPES.inboxMessage],\n ['workflows', SUBSCRIBERBOT_ENTITY_TYPES.workflow],\n];\n\n/**\n * Sub-views of one entity (`/workflows/:id/builder`): the entity stays the\n * subject and the sub-view is reported as the active tab.\n */\nconst ENTITY_SUBVIEWS: ReadonlyMap<string, ReadonlySet<string>> = new Map([\n ['workflows', new Set(['builder'])],\n]);\n\n/** Static sub-routes that sit where an id would (\"relationships/new\" is a form, not an entity). */\nconst NON_ENTITY_SEGMENTS: ReadonlySet<string> = new Set(['new']);\n\n/** Ids are opaque, but they are path segments: no separators, no whitespace, bounded length. */\nconst ENTITY_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\n/** Tab names are short identifiers; anything else is ignored rather than forwarded. */\nconst TAB_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;\n\nfunction decodeSegment(segment: string): string | undefined {\n try {\n return decodeURIComponent(segment);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve the entity the user is looking at from the router location.\n *\n * `pathname` is the full browser path; the Subscriber Bot routes live under\n * `/subscriberbot`. Anything that is not an entity route resolves to an empty\n * entity, so the agent asks rather than acting on a guessed id.\n */\nexport function resolveSubscriberBotConversationContext(\n pathname: string,\n search: string\n): ConversationContextShape {\n const segments = pathname.split('/').filter(Boolean);\n const root = segments.indexOf('subscriberbot');\n const rest = root === -1 ? [] : segments.slice(root + 1);\n\n const tabParam = new URLSearchParams(search).get('tab');\n const activeTab = tabParam && TAB_PATTERN.test(tabParam) ? tabParam : undefined;\n\n if (rest.length === 3) {\n const [section, rawId, subview] = rest as [string, string, string];\n const route = ENTITY_ROUTES.find(([segment]) => segment === section);\n const id = decodeSegment(rawId);\n if (route && id && ENTITY_SUBVIEWS.get(section)?.has(subview) && ENTITY_ID_PATTERN.test(id)) {\n return { entityType: route[1], entityId: id, activeTab: subview };\n }\n }\n\n if (rest.length === 2) {\n const [section, rawId] = rest as [string, string];\n const route = ENTITY_ROUTES.find(([segment]) => segment === section);\n const id = decodeSegment(rawId);\n if (route && id && !NON_ENTITY_SEGMENTS.has(id) && ENTITY_ID_PATTERN.test(id)) {\n return { entityType: route[1], entityId: id, ...(activeTab ? { activeTab } : {}) };\n }\n }\n\n return activeTab ? { activeTab } : {};\n}\n\nexport function gatherPageContext(): PageContext {\n const { href, pathname, search } = window.location;\n const currentPage = pathname.split('/').filter(Boolean).slice(0, 3).join('/') || 'home';\n const entity = resolveSubscriberBotConversationContext(pathname, search);\n\n return {\n currentUrl: href,\n currentPage,\n ...(entity.entityType && entity.entityId\n ? { entityType: entity.entityType, entityId: entity.entityId }\n : {}),\n ...(entity.activeTab ? { activeTab: entity.activeTab } : {}),\n platform: 'subscriberbot',\n version: import.meta.env.VITE_APP_VERSION ?? '2026.615.1',\n viewportSize: `${window.innerWidth}x${window.innerHeight}`,\n };\n}\n"],"mappings":";AA4CA,IAAa,IAA6B;CACxC,cAAc;CACd,UAAU;CACV,OAAO;CACP,UAAU;CACV,cAAc;CACd,UAAU;AACZ,GAwBM,IAA0F;CAC9F,CAAC,iBAAiB,EAA2B,YAAY;CACzD,CAAC,aAAa,EAA2B,QAAQ;CACjD,CAAC,UAAU,EAA2B,KAAK;CAC3C,CAAC,aAAa,EAA2B,QAAQ;CACjD,CAAC,SAAS,EAA2B,YAAY;CACjD,CAAC,aAAa,EAA2B,QAAQ;AACnD,GAMM,IAA4D,IAAI,IAAI,CACxE,CAAC,aAAa,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CACpC,CAAC,GAGK,IAA2C,IAAI,IAAI,CAAC,KAAK,CAAC,GAG1D,IAAoB,0BAGpB,IAAc;AAEpB,SAAS,EAAc,GAAqC;CAC1D,IAAI;EACF,OAAO,mBAAmB,CAAO;CACnC,QAAQ;EACN;CACF;AACF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AO;EAAS,IAC3D,CAAC;EACL,GAAI,EAAO,YAAY,EAAE,WAAW,EAAO,UAAU,IAAI,CAAC;EAC1D,UAAU;EACV,SAA6C;EAC7C,cAAc,GAAG,OAAO,WAAW,GAAG,OAAO;CAC/C;AACF"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { SubBillingInterval, SubRelationship, SubRelationshipStatus, SubRenewalEvent } from '../types';
|
|
2
|
+
|
|
3
|
+
export declare const MS_PER_DAY: number;
|
|
4
|
+
/** Renewals inside this window are flagged as "soon". */
|
|
5
|
+
export declare const SOON_WINDOW_DAYS = 7;
|
|
6
|
+
/**
|
|
7
|
+
* Approximate monthly multiplier per billing interval, so total recurring
|
|
8
|
+
* spend can be expressed as one comparable "per month" number. Usage-based
|
|
9
|
+
* relationships count at their last known amount; free and lifetime ones
|
|
10
|
+
* do not recur.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MONTHLY_FACTOR: Record<SubBillingInterval, number>;
|
|
13
|
+
/** The relationship's cost normalised to one month. */
|
|
14
|
+
export declare function monthlyAmount(relationship: Pick<SubRelationship, 'amount' | 'interval'>): number;
|
|
15
|
+
export interface RecurringSpend {
|
|
16
|
+
/** Sum of `monthlyAmount` over ACTIVE + TRIAL relationships. */
|
|
17
|
+
monthly: number;
|
|
18
|
+
/** Currency of the first billing relationship (portfolio display currency). */
|
|
19
|
+
currency: string;
|
|
20
|
+
/** Number of relationships that are still billing. */
|
|
21
|
+
activeCount: number;
|
|
22
|
+
}
|
|
23
|
+
/** Total monthly recurring spend over the relationships that still bill. */
|
|
24
|
+
export declare function recurringSpend(relationships: readonly Pick<SubRelationship, 'amount' | 'interval' | 'status' | 'currency'>[]): RecurringSpend;
|
|
25
|
+
/**
|
|
26
|
+
* Whole days from `now` until `date`: anything less than 24 hours away reads
|
|
27
|
+
* as 0 ("today"), 24–48 hours as 1, and so on. Negative (whole days, rounded
|
|
28
|
+
* away from zero) when the date has passed; null when it is missing or
|
|
29
|
+
* unparseable.
|
|
30
|
+
*/
|
|
31
|
+
export declare function daysUntil(date: string | null | undefined, now?: number): number | null;
|
|
32
|
+
/** Translation key, English fallback and params for a renewal countdown. */
|
|
33
|
+
export interface RenewalCountdown {
|
|
34
|
+
key: string;
|
|
35
|
+
fallback: string;
|
|
36
|
+
params?: Record<string, number>;
|
|
37
|
+
tone: 'overdue' | 'soon' | 'later';
|
|
38
|
+
}
|
|
39
|
+
export declare function renewalCountdown(days: number): RenewalCountdown;
|
|
40
|
+
/** One normalised "what charges next" row. */
|
|
41
|
+
export interface UpcomingRenewal {
|
|
42
|
+
id: string;
|
|
43
|
+
relationshipId: string;
|
|
44
|
+
title: string;
|
|
45
|
+
when: string;
|
|
46
|
+
amount: number | null;
|
|
47
|
+
currency: string | null;
|
|
48
|
+
interval: SubBillingInterval | null;
|
|
49
|
+
kind: SubRelationship['kind'] | null;
|
|
50
|
+
soon: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Upcoming renewals, soonest first. Real renewal events win; when the event
|
|
54
|
+
* stream is empty the list is derived from each relationship's own future
|
|
55
|
+
* `renewsAt`, so a freshly-tracked portfolio still shows what renews next.
|
|
56
|
+
* `fallbackTitle` names an event whose relationship is not in the page.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildUpcomingRenewals(relationships: readonly SubRelationship[], events: readonly SubRenewalEvent[], fallbackTitle: (eventType: string) => string, now?: number): UpcomingRenewal[];
|
|
59
|
+
/**
|
|
60
|
+
* Lifecycle state machine — mirrors `RELATIONSHIP_TRANSITIONS` in
|
|
61
|
+
* wspace-subscriberbot-svc (relationships.service.ts). The server stays the
|
|
62
|
+
* authority and re-validates every transition; this copy only decides which
|
|
63
|
+
* actions are worth offering so the UI never shows a button that is certain
|
|
64
|
+
* to fail.
|
|
65
|
+
*/
|
|
66
|
+
export declare const RELATIONSHIP_TRANSITIONS: Record<SubRelationshipStatus, readonly SubRelationshipStatus[]>;
|
|
67
|
+
export declare function canTransition(from: SubRelationshipStatus, to: SubRelationshipStatus): boolean;
|
|
68
|
+
export type QuickActionId = 'activate' | 'resume' | 'pause' | 'cancel';
|
|
69
|
+
export interface QuickAction {
|
|
70
|
+
id: QuickActionId;
|
|
71
|
+
/** Status the relationship moves to. CANCELLED goes through subCancelRelationship. */
|
|
72
|
+
target: SubRelationshipStatus;
|
|
73
|
+
/** Destructive actions ask for confirmation first. */
|
|
74
|
+
destructive: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The everyday actions a phone user reaches for from a list row or the
|
|
78
|
+
* detail page — start, pause/resume, cancel — filtered to what the state
|
|
79
|
+
* machine allows from `status`. Rarer bookkeeping transitions (mark expired,
|
|
80
|
+
* past due, lapsed) stay on the desktop detail page.
|
|
81
|
+
*/
|
|
82
|
+
export declare function quickActionsFor(status: SubRelationshipStatus): QuickAction[];
|
|
83
|
+
/**
|
|
84
|
+
* Swipe-to-reveal geometry for a list row. `dx` is the horizontal drag
|
|
85
|
+
* distance (negative = towards the left). Returns the clamped row offset
|
|
86
|
+
* while dragging.
|
|
87
|
+
*/
|
|
88
|
+
export declare function swipeOffset(dx: number, wasOpen: boolean, revealWidth: number): number;
|
|
89
|
+
/**
|
|
90
|
+
* Whether the row should settle open once the finger lifts: past half the
|
|
91
|
+
* action tray it snaps open, otherwise it snaps shut.
|
|
92
|
+
*/
|
|
93
|
+
export declare function swipeSettlesOpen(offset: number, revealWidth: number): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* How long after a swipe ends the browser's trailing synthetic click is
|
|
96
|
+
* treated as part of the gesture. Browsers dispatch it immediately after
|
|
97
|
+
* `pointerup`, so a short window is enough; a real tap that follows later is
|
|
98
|
+
* never swallowed, and a cancelled swipe (no click at all) leaves nothing
|
|
99
|
+
* pending.
|
|
100
|
+
*/
|
|
101
|
+
export declare const SWIPE_CLICK_WINDOW_MS = 400;
|
|
102
|
+
/** Deadline until which a click counts as the swipe's own trailing click. */
|
|
103
|
+
export declare function swipeClickDeadline(endedAt: number): number;
|
|
104
|
+
/** Whether a click at `now` is the trailing click of a swipe ending by `deadline`. */
|
|
105
|
+
export declare function isSwipeTrailingClick(now: number, deadline: number): boolean;
|
|
106
|
+
//# sourceMappingURL=portfolio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portfolio.d.ts","sourceRoot":"","sources":["../../../src/subscriberbot/utils/portfolio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,UAAU,QAAsB,CAAC;AAE9C,yDAAyD;AACzD,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAS7D,CAAC;AAQF,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG,MAAM,CAEhG;AAED,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAC5B,aAAa,EAAE,SAAS,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC,EAAE,GAC7F,cAAc,CAOhB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,GAAG,GAAE,MAAmB,GACvB,MAAM,GAAG,IAAI,CAOf;AAED,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,E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O,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,WAAW,EAAE,CAgB5E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAGrF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE3E"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
//#region src/subscriberbot/utils/portfolio.ts
|
|
2
|
+
var e = 1e3 * 60 * 60 * 24, t = {
|
|
3
|
+
DAILY: 30,
|
|
4
|
+
WEEKLY: 4.345,
|
|
5
|
+
MONTHLY: 1,
|
|
6
|
+
QUARTERLY: 1 / 3,
|
|
7
|
+
YEARLY: 1 / 12,
|
|
8
|
+
LIFETIME: 0,
|
|
9
|
+
FREE: 0,
|
|
10
|
+
USAGE_BASED: 1
|
|
11
|
+
}, n = new Set(["ACTIVE", "TRIAL"]);
|
|
12
|
+
function r(e) {
|
|
13
|
+
return e.amount * (t[e.interval] ?? 1);
|
|
14
|
+
}
|
|
15
|
+
function i(e) {
|
|
16
|
+
let t = e.filter((e) => n.has(e.status));
|
|
17
|
+
return {
|
|
18
|
+
monthly: t.reduce((e, t) => e + r(t), 0),
|
|
19
|
+
currency: t[0]?.currency ?? e[0]?.currency ?? "USD",
|
|
20
|
+
activeCount: t.length
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function a(t, n = Date.now()) {
|
|
24
|
+
if (!t) return null;
|
|
25
|
+
let r = new Date(t).getTime();
|
|
26
|
+
if (Number.isNaN(r)) return null;
|
|
27
|
+
let i = r - n;
|
|
28
|
+
return i < 0 ? -Math.ceil(-i / e) : Math.floor(i / e);
|
|
29
|
+
}
|
|
30
|
+
function o(e) {
|
|
31
|
+
return e < 0 ? {
|
|
32
|
+
key: "mobile.renewal.overdue",
|
|
33
|
+
fallback: "Renewal overdue",
|
|
34
|
+
tone: "overdue"
|
|
35
|
+
} : e === 0 ? {
|
|
36
|
+
key: "mobile.renewal.today",
|
|
37
|
+
fallback: "Renews today",
|
|
38
|
+
tone: "soon"
|
|
39
|
+
} : e === 1 ? {
|
|
40
|
+
key: "mobile.renewal.tomorrow",
|
|
41
|
+
fallback: "Renews tomorrow",
|
|
42
|
+
tone: "soon"
|
|
43
|
+
} : {
|
|
44
|
+
key: "mobile.renewal.inDays",
|
|
45
|
+
fallback: "Renews in {{count}} days",
|
|
46
|
+
params: { count: e },
|
|
47
|
+
tone: e <= 7 ? "soon" : "later"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function s(t, n, r, i = Date.now()) {
|
|
51
|
+
let a = /* @__PURE__ */ new Map();
|
|
52
|
+
t.forEach((e) => a.set(e.id, e));
|
|
53
|
+
let o = i + 7 * e, s = (e) => new Date(e).getTime();
|
|
54
|
+
return n.length > 0 ? n.filter((e) => !Number.isNaN(s(e.occursAt))).map((e) => {
|
|
55
|
+
let t = a.get(e.relationshipId);
|
|
56
|
+
return {
|
|
57
|
+
id: e.id,
|
|
58
|
+
relationshipId: e.relationshipId,
|
|
59
|
+
title: t?.label ?? r(e.eventType),
|
|
60
|
+
when: e.occursAt,
|
|
61
|
+
amount: e.amount ?? t?.amount ?? null,
|
|
62
|
+
currency: e.currency ?? t?.currency ?? null,
|
|
63
|
+
interval: t?.interval ?? null,
|
|
64
|
+
kind: t?.kind ?? null,
|
|
65
|
+
soon: s(e.occursAt) <= o
|
|
66
|
+
};
|
|
67
|
+
}).sort((e, t) => s(e.when) - s(t.when)) : t.filter((e) => {
|
|
68
|
+
if (!e.renewsAt) return !1;
|
|
69
|
+
let t = s(e.renewsAt);
|
|
70
|
+
return !Number.isNaN(t) && t >= i;
|
|
71
|
+
}).map((e) => {
|
|
72
|
+
let t = e.renewsAt;
|
|
73
|
+
return {
|
|
74
|
+
id: e.id,
|
|
75
|
+
relationshipId: e.id,
|
|
76
|
+
title: e.label,
|
|
77
|
+
when: t,
|
|
78
|
+
amount: e.amount,
|
|
79
|
+
currency: e.currency,
|
|
80
|
+
interval: e.interval,
|
|
81
|
+
kind: e.kind,
|
|
82
|
+
soon: s(t) <= o
|
|
83
|
+
};
|
|
84
|
+
}).sort((e, t) => s(e.when) - s(t.when));
|
|
85
|
+
}
|
|
86
|
+
var c = {
|
|
87
|
+
TRIAL: [
|
|
88
|
+
"ACTIVE",
|
|
89
|
+
"CANCELLED",
|
|
90
|
+
"EXPIRED"
|
|
91
|
+
],
|
|
92
|
+
ACTIVE: [
|
|
93
|
+
"PAUSED",
|
|
94
|
+
"PAST_DUE",
|
|
95
|
+
"CANCELLED",
|
|
96
|
+
"EXPIRED"
|
|
97
|
+
],
|
|
98
|
+
PAUSED: [
|
|
99
|
+
"ACTIVE",
|
|
100
|
+
"CANCELLED",
|
|
101
|
+
"EXPIRED"
|
|
102
|
+
],
|
|
103
|
+
PAST_DUE: [
|
|
104
|
+
"ACTIVE",
|
|
105
|
+
"LAPSED",
|
|
106
|
+
"CANCELLED"
|
|
107
|
+
],
|
|
108
|
+
LAPSED: [
|
|
109
|
+
"ACTIVE",
|
|
110
|
+
"CANCELLED",
|
|
111
|
+
"EXPIRED"
|
|
112
|
+
],
|
|
113
|
+
CANCELLED: [],
|
|
114
|
+
EXPIRED: []
|
|
115
|
+
};
|
|
116
|
+
function l(e, t) {
|
|
117
|
+
return c[e]?.includes(t) ?? !1;
|
|
118
|
+
}
|
|
119
|
+
function u(e) {
|
|
120
|
+
let t = [];
|
|
121
|
+
return l(e, "ACTIVE") && t.push({
|
|
122
|
+
id: e === "TRIAL" ? "activate" : "resume",
|
|
123
|
+
target: "ACTIVE",
|
|
124
|
+
destructive: !1
|
|
125
|
+
}), l(e, "PAUSED") && t.push({
|
|
126
|
+
id: "pause",
|
|
127
|
+
target: "PAUSED",
|
|
128
|
+
destructive: !1
|
|
129
|
+
}), l(e, "CANCELLED") && t.push({
|
|
130
|
+
id: "cancel",
|
|
131
|
+
target: "CANCELLED",
|
|
132
|
+
destructive: !0
|
|
133
|
+
}), t;
|
|
134
|
+
}
|
|
135
|
+
function d(e, t, n) {
|
|
136
|
+
let r = t ? -n : 0;
|
|
137
|
+
return Math.min(0, Math.max(-n, r + e));
|
|
138
|
+
}
|
|
139
|
+
function f(e, t) {
|
|
140
|
+
return t > 0 && -e >= t / 2;
|
|
141
|
+
}
|
|
142
|
+
function p(e) {
|
|
143
|
+
return e + 400;
|
|
144
|
+
}
|
|
145
|
+
function m(e, t) {
|
|
146
|
+
return e <= t;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
export { s as buildUpcomingRenewals, l as canTransition, a as daysUntil, m as isSwipeTrailingClick, u as quickActionsFor, i as recurringSpend, o as renewalCountdown, p as swipeClickDeadline, d as swipeOffset, f as swipeSettlesOpen };
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=portfolio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portfolio.js","names":[],"sources":["../../../src/subscriberbot/utils/portfolio.ts"],"sourcesContent":["/**\n * Portfolio model shared by the desktop and mobile Subscriber Bot screens\n * @module subscriberbot/utils/portfolio\n *\n * Pure functions only (no React, no DOM) so the overview, the relationship\n * list and the relationship detail page compute spend, renewals and lifecycle\n * actions the same way at every viewport. Unit-tested in `portfolio.test.ts`.\n */\n\nimport type {\n SubBillingInterval,\n SubRelationship,\n SubRelationshipStatus,\n SubRenewalEvent,\n} from '../types';\n\nexport const MS_PER_DAY = 1000 * 60 * 60 * 24;\n\n/** Renewals inside this window are flagged as \"soon\". */\nexport const SOON_WINDOW_DAYS = 7;\n\n/**\n * Approximate monthly multiplier per billing interval, so total recurring\n * spend can be expressed as one comparable \"per month\" number. Usage-based\n * relationships count at their last known amount; free and lifetime ones\n * do not recur.\n */\nexport const MONTHLY_FACTOR: Record<SubBillingInterval, number> = {\n DAILY: 30,\n WEEKLY: 4.345,\n MONTHLY: 1,\n QUARTERLY: 1 / 3,\n YEARLY: 1 / 12,\n LIFETIME: 0,\n FREE: 0,\n USAGE_BASED: 1,\n};\n\n/** Statuses that are still being billed. */\nconst BILLING_STATUSES: ReadonlySet<SubRelationshipStatus> = new Set<SubRelationshipStatus>([\n 'ACTIVE',\n 'TRIAL',\n]);\n\n/** The relationship's cost normalised to one month. */\nexport function monthlyAmount(relationship: Pick<SubRelationship, 'amount' | 'interval'>): number {\n return relationship.amount * (MONTHLY_FACTOR[relationship.interval] ?? 1);\n}\n\nexport interface RecurringSpend {\n /** Sum of `monthlyAmount` over ACTIVE + TRIAL relationships. */\n monthly: number;\n /** Currency of the first billing relationship (portfolio display currency). */\n currency: string;\n /** Number of relationships that are still billing. */\n activeCount: number;\n}\n\n/** Total monthly recurring spend over the relationships that still bill. */\nexport function recurringSpend(\n relationships: readonly Pick<SubRelationship, 'amount' | 'interval' | 'status' | 'currency'>[]\n): RecurringSpend {\n const active = relationships.filter((r) => BILLING_STATUSES.has(r.status));\n return {\n monthly: active.reduce((sum, r) => sum + monthlyAmount(r), 0),\n currency: active[0]?.currency ?? relationships[0]?.currency ?? 'USD',\n activeCount: active.length,\n };\n}\n\n/**\n * Whole days from `now` until `date`: anything less than 24 hours away reads\n * as 0 (\"today\"), 24–48 hours as 1, and so on. Negative (whole days, rounded\n * away from zero) when the date has passed; null when it is missing or\n * unparseable.\n */\nexport function daysUntil(\n date: string | null | undefined,\n now: number = Date.now()\n): number | null {\n if (!date) return null;\n const t = new Date(date).getTime();\n if (Number.isNaN(t)) return null;\n const diff = t - now;\n if (diff < 0) return -Math.ceil(-diff / MS_PER_DAY);\n return Math.floor(diff / MS_PER_DAY);\n}\n\n/** Translation key, English fallback and params for a renewal countdown. */\nexport interface RenewalCountdown {\n key: string;\n fallback: string;\n params?: Record<string, number>;\n tone: 'overdue' | 'soon' | 'later';\n}\n\nexport function renewalCountdown(days: number): RenewalCountdown {\n if (days < 0) {\n return { key: 'mobile.renewal.overdue', fallback: 'Renewal overdue', tone: 'overdue' };\n }\n if (days === 0) {\n return { key: 'mobile.renewal.today', fallback: 'Renews today', tone: 'soon' };\n }\n if (days === 1) {\n return { key: 'mobile.renewal.tomorrow', fallback: 'Renews tomorrow', tone: 'soon' };\n }\n return {\n key: 'mobile.renewal.inDays',\n fallback: 'Renews in {{count}} days',\n params: { count: days },\n tone: days <= SOON_WINDOW_DAYS ? 'soon' : 'later',\n };\n}\n\n/** One normalised \"what charges next\" row. */\nexport interface UpcomingRenewal {\n id: string;\n relationshipId: string;\n title: string;\n when: string;\n amount: number | null;\n currency: string | null;\n interval: SubBillingInterval | null;\n kind: SubRelationship['kind'] | null;\n soon: boolean;\n}\n\n/**\n * Upcoming renewals, soonest first. Real renewal events win; when the event\n * stream is empty the list is derived from each relationship's own future\n * `renewsAt`, so a freshly-tracked portfolio still shows what renews next.\n * `fallbackTitle` names an event whose relationship is not in the page.\n */\nexport function buildUpcomingRenewals(\n relationships: readonly SubRelationship[],\n events: readonly SubRenewalEvent[],\n fallbackTitle: (eventType: string) => string,\n now: number = Date.now()\n): UpcomingRenewal[] {\n const byId = new Map<string, SubRelationship>();\n relationships.forEach((r) => byId.set(r.id, r));\n const soonCutoff = now + SOON_WINDOW_DAYS * MS_PER_DAY;\n const time = (iso: string) => new Date(iso).getTime();\n\n if (events.length > 0) {\n return events\n .filter((e) => !Number.isNaN(time(e.occursAt)))\n .map((e) => {\n const rel = byId.get(e.relationshipId);\n return {\n id: e.id,\n relationshipId: e.relationshipId,\n title: rel?.label ?? fallbackTitle(e.eventType),\n when: e.occursAt,\n amount: e.amount ?? rel?.amount ?? null,\n currency: e.currency ?? rel?.currency ?? null,\n interval: rel?.interval ?? null,\n kind: rel?.kind ?? null,\n soon: time(e.occursAt) <= soonCutoff,\n };\n })\n .sort((a, b) => time(a.when) - time(b.when));\n }\n\n return relationships\n .filter((r) => {\n if (!r.renewsAt) return false;\n const t = time(r.renewsAt);\n return !Number.isNaN(t) && t >= now;\n })\n .map((r) => {\n const when = r.renewsAt as string;\n return {\n id: r.id,\n relationshipId: r.id,\n title: r.label,\n when,\n amount: r.amount,\n currency: r.currency,\n interval: r.interval,\n kind: r.kind,\n soon: time(when) <= soonCutoff,\n };\n })\n .sort((a, b) => time(a.when) - time(b.when));\n}\n\n/**\n * Lifecycle state machine — mirrors `RELATIONSHIP_TRANSITIONS` in\n * wspace-subscriberbot-svc (relationships.service.ts). The server stays the\n * authority and re-validates every transition; this copy only decides which\n * actions are worth offering so the UI never shows a button that is certain\n * to fail.\n */\nexport const RELATIONSHIP_TRANSITIONS: Record<\n SubRelationshipStatus,\n readonly SubRelationshipStatus[]\n> = {\n TRIAL: ['ACTIVE', 'CANCELLED', 'EXPIRED'],\n ACTIVE: ['PAUSED', 'PAST_DUE', 'CANCELLED', 'EXPIRED'],\n PAUSED: ['ACTIVE', 'CANCELLED', 'EXPIRED'],\n PAST_DUE: ['ACTIVE', 'LAPSED', 'CANCELLED'],\n LAPSED: ['ACTIVE', 'CANCELLED', 'EXPIRED'],\n CANCELLED: [],\n EXPIRED: [],\n};\n\nexport function canTransition(from: SubRelationshipStatus, to: SubRelationshipStatus): boolean {\n return RELATIONSHIP_TRANSITIONS[from]?.includes(to) ?? false;\n}\n\nexport type QuickActionId = 'activate' | 'resume' | 'pause' | 'cancel';\n\nexport interface QuickAction {\n id: QuickActionId;\n /** Status the relationship moves to. CANCELLED goes through subCancelRelationship. */\n target: SubRelationshipStatus;\n /** Destructive actions ask for confirmation first. */\n destructive: boolean;\n}\n\n/**\n * The everyday actions a phone user reaches for from a list row or the\n * detail page — start, pause/resume, cancel — filtered to what the state\n * machine allows from `status`. Rarer bookkeeping transitions (mark expired,\n * past due, lapsed) stay on the desktop detail page.\n */\nexport function quickActionsFor(status: SubRelationshipStatus): QuickAction[] {\n const actions: QuickAction[] = [];\n if (canTransition(status, 'ACTIVE')) {\n actions.push({\n id: status === 'TRIAL' ? 'activate' : 'resume',\n target: 'ACTIVE',\n destructive: false,\n });\n }\n if (canTransition(status, 'PAUSED')) {\n actions.push({ id: 'pause', target: 'PAUSED', destructive: false });\n }\n if (canTransition(status, 'CANCELLED')) {\n actions.push({ id: 'cancel', target: 'CANCELLED', destructive: true });\n }\n return actions;\n}\n\n/**\n * Swipe-to-reveal geometry for a list row. `dx` is the horizontal drag\n * distance (negative = towards the left). Returns the clamped row offset\n * while dragging.\n */\nexport function swipeOffset(dx: number, wasOpen: boolean, revealWidth: number): number {\n const base = wasOpen ? -revealWidth : 0;\n return Math.min(0, Math.max(-revealWidth, base + dx));\n}\n\n/**\n * Whether the row should settle open once the finger lifts: past half the\n * action tray it snaps open, otherwise it snaps shut.\n */\nexport function swipeSettlesOpen(offset: number, revealWidth: number): boolean {\n return revealWidth > 0 && -offset >= revealWidth / 2;\n}\n\n/**\n * How long after a swipe ends the browser's trailing synthetic click is\n * treated as part of the gesture. Browsers dispatch it immediately after\n * `pointerup`, so a short window is enough; a real tap that follows later is\n * never swallowed, and a cancelled swipe (no click at all) leaves nothing\n * pending.\n */\nexport const SWIPE_CLICK_WINDOW_MS = 400;\n\n/** Deadline until which a click counts as the swipe's own trailing click. */\nexport function swipeClickDeadline(endedAt: number): number {\n return endedAt + SWIPE_CLICK_WINDOW_MS;\n}\n\n/** Whether a click at `now` is the trailing click of a swipe ending by `deadline`. */\nexport function isSwipeTrailingClick(now: number, deadline: number): boolean {\n return now <= deadline;\n}\n"],"mappings":";AAgBA,IAAa,IAAa,MAAO,KAAK,KAAK,IAW9B,IAAqD;CAChE,OAAO;CACP,QAAQ;CACR,SAAS;CACT,W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AU;EAAa;CAAS;CACzC,WAAW,CAAC;CACZ,SAAS,CAAC;AACZ;AAEA,SAAgB,EAAc,GAA6B,GAAoC;CAC7F,OAAO,EAAyB,IAAO,SAAS,CAAE,KAAK;AACzD;AAkBA,SAAgB,EAAgB,GAA8C;CAC5E,IAAM,IAAyB,CAAC;CAchC,OAbI,EAAc,GAAQ,QAAQ,KAChC,EAAQ,KAAK;EACX,IAAI,MAAW,UAAU,aAAa;EACtC,QAAQ;EACR,aAAa;CACf,CAAC,GAEC,EAAc,GAAQ,QAAQ,KAChC,EAAQ,KAAK;EAAE,IAAI;EAAS,QAAQ;EAAU,aAAa;CAAM,CAAC,GAEhE,EAAc,GAAQ,WAAW,KACnC,EAAQ,KAAK;EAAE,IAAI;EAAU,QAAQ;EAAa,aAAa;CAAK,CAAC,GAEhE;AACT;AAOA,SAAgB,EAAY,GAAY,GAAkB,GAA6B;CACrF,IAAM,IAAO,IAAU,CAAC,IAAc;CACtC,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,GAAa,IAAO,CAAE,CAAC;AACtD;AAMA,SAAgB,EAAiB,GAAgB,GAA8B;CAC7E,OAAO,IAAc,KAAK,CAAC,KAAU,IAAc;AACrD;AAYA,SAAgB,EAAmB,GAAyB;CAC1D,OAAO,IAAA;AACT;AAGA,SAAgB,EAAqB,GAAa,GAA2B;CAC3E,OAAO,KAAO;AAChB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@burdenoff/microfe-subscriberbot",
|
|
3
|
-
"version": "2026.1102.
|
|
3
|
+
"version": "2026.1102.6",
|
|
4
4
|
"description": "Burdenoff SubscriberBot Microfrontend",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@apollo/client": "^4.0.11",
|
|
52
52
|
"@burdenoff/fe-libs": "2026.801.1",
|
|
53
53
|
"@tanstack/react-query": "^5.90.16",
|
|
54
|
+
"@xyflow/react": "^12.10.0",
|
|
54
55
|
"clsx": "^2.1.1",
|
|
55
56
|
"graphql": "^16.12.0",
|
|
56
57
|
"lucide-react": "^0.468.0",
|
|
@@ -96,6 +97,7 @@
|
|
|
96
97
|
},
|
|
97
98
|
"peerDependencies": {
|
|
98
99
|
"@apollo/client": "^4.0.11",
|
|
100
|
+
"@xyflow/react": "^12.10.0",
|
|
99
101
|
"react": "^19.0.0",
|
|
100
102
|
"react-dom": "^19.0.0",
|
|
101
103
|
"zustand": "^5.0.0"
|