@tumbaland/frontend-core 1.9.0 → 1.10.0

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/index.d.ts CHANGED
@@ -6,6 +6,8 @@ export { createGroupService } from './groupService';
6
6
  export type { GroupServiceConfig, GroupService } from './groupService';
7
7
  export { createEntitlementsService, isUnlimited, usageRatio, UNLIMITED } from './entitlementsService';
8
8
  export type { EntitlementsServiceConfig, EntitlementsService, Entitlements, PlanLimits, MeterKey, FeatureKey } from './entitlementsService';
9
+ export { createPlansService } from './plansService';
10
+ export type { CatalogPlan, PlansServiceConfig, PlansService } from './plansService';
9
11
  export type { User, AuthResponse, Group, ApiResponse } from './types';
10
12
  export { TENANT_STORAGE_KEY, clearSessionScopedStorage } from './sessionStorage';
11
13
  export { initMonitoring, captureException, captureMessage, setUser, setTag, startTransaction, recordMetric, initWebVitals, flushLogs, initConsoleInterception, generateCorrelationId, getCorrelationId, getSessionId, logger } from './monitoring';
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export { createApiClient, ApiError } from './apiClient';
3
3
  export { createAuthService, createAppAuthService } from './authService';
4
4
  export { createGroupService } from './groupService';
5
5
  export { createEntitlementsService, isUnlimited, usageRatio, UNLIMITED } from './entitlementsService';
6
+ export { createPlansService } from './plansService';
6
7
  export { TENANT_STORAGE_KEY, clearSessionScopedStorage } from './sessionStorage';
7
8
  // Monitoring: headless logging, error capture, correlation IDs, and web-vitals
8
9
  export { initMonitoring, captureException, captureMessage, setUser, setTag, startTransaction, recordMetric, initWebVitals, flushLogs, initConsoleInterception, generateCorrelationId, getCorrelationId, getSessionId, logger } from './monitoring';
@@ -0,0 +1,51 @@
1
+ import { PlanLimits } from './entitlementsService';
2
+ /**
3
+ * The public plan catalog, as the pricing page renders it.
4
+ *
5
+ * **The numbers are never duplicated here.** `effectiveLimits` arrives from the
6
+ * API already resolved by the same `normalizeLimits` the entitlement middleware
7
+ * enforces from, so the ceiling on the card and the ceiling that produces a 402
8
+ * are the same value read from the same place. A hardcoded pricing table is the
9
+ * exact defect Phase 0 removed — `PlansPage` advertised six limits no service
10
+ * enforced — and re-creating it at the moment money changes hands would attach
11
+ * a payment to the claim.
12
+ *
13
+ * What a front *may* own is copy: a plan's tagline and which card is
14
+ * highlighted are presentation, not entitlement.
15
+ */
16
+ export interface CatalogPlan {
17
+ code: string;
18
+ name: string;
19
+ /** Admin-editable tagline. Absent on plans nobody has written copy for. */
20
+ description?: string;
21
+ /** Cents, so there is never a float in a price. */
22
+ priceMonthlyCents: number;
23
+ priceYearlyCents?: number;
24
+ /** Marketing bullets. Deliberately unused by the limit rows — see above. */
25
+ features?: string[];
26
+ isPublic?: boolean;
27
+ /** Whether the plan can be bought at all; a priced plan without one returns 503 at checkout. */
28
+ stripePriceId?: string;
29
+ /** Limits after code defaults fill whatever the plan document leaves unset. */
30
+ effectiveLimits: PlanLimits;
31
+ }
32
+ export interface PlansServiceConfig {
33
+ /** Read fresh at call time (config may not be resolved yet at module load). */
34
+ getPaymentApiUrl: () => string;
35
+ }
36
+ /**
37
+ * Builds a per-front plans service.
38
+ *
39
+ * export const { getPlans } = createPlansService({
40
+ * getPaymentApiUrl: () => getGlobalConfig().PAYMENT_API_URL!
41
+ * });
42
+ *
43
+ * `GET /api/plans` is optionally authenticated: a signed-out visitor gets the
44
+ * public catalog, and a signed-in one additionally gets the hidden plan they
45
+ * are actually on. No `onUnauthorized` redirect, therefore — the landing page
46
+ * is reachable without an account and must stay that way.
47
+ */
48
+ export declare function createPlansService(config: PlansServiceConfig): {
49
+ getPlans(): Promise<CatalogPlan[]>;
50
+ };
51
+ export type PlansService = ReturnType<typeof createPlansService>;
@@ -0,0 +1,25 @@
1
+ import { createApiClient } from './apiClient';
2
+ /**
3
+ * Builds a per-front plans service.
4
+ *
5
+ * export const { getPlans } = createPlansService({
6
+ * getPaymentApiUrl: () => getGlobalConfig().PAYMENT_API_URL!
7
+ * });
8
+ *
9
+ * `GET /api/plans` is optionally authenticated: a signed-out visitor gets the
10
+ * public catalog, and a signed-in one additionally gets the hidden plan they
11
+ * are actually on. No `onUnauthorized` redirect, therefore — the landing page
12
+ * is reachable without an account and must stay that way.
13
+ */
14
+ export function createPlansService(config) {
15
+ const client = createApiClient({ baseUrl: () => config.getPaymentApiUrl() });
16
+ return {
17
+ async getPlans() {
18
+ const body = await client.get('/api/plans');
19
+ const plans = body?.plans ?? [];
20
+ // A plan without resolved limits cannot be rendered honestly — every line
21
+ // on its card is a limit — so drop it rather than draw a card with holes.
22
+ return plans.filter(plan => Boolean(plan?.effectiveLimits?.meters));
23
+ }
24
+ };
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tumbaland/frontend-core",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Shared frontend auth/group/API-client logic for Tumbaland frontends",
5
5
  "author": "Tumbaland",
6
6
  "license": "MIT",