@taskforcehq/taskforce 0.3.302 → 0.3.303

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/Taskforce.module.css +11 -0
  2. package/dist/TaskforceCore.js +59 -9
  3. package/dist/TaskforceCore.test.js +717 -14
  4. package/dist/components/task/TaskKanban.test.js +17 -0
  5. package/dist/components/views/PlansPage.d.ts +3 -1
  6. package/dist/components/views/PlansPage.js +110 -51
  7. package/dist/components/views/PlansPage.test.d.ts +1 -0
  8. package/dist/components/views/PlansPage.test.js +100 -0
  9. package/dist/components/views/StandaloneLayout.d.ts +1 -0
  10. package/dist/components/views/StandaloneLayout.js +106 -151
  11. package/dist/components/views/standalone/modals/AccountHubModal.d.ts +8 -3
  12. package/dist/components/views/standalone/modals/AccountHubModal.js +16 -2
  13. package/dist/components/views/standalone/modals/AccountHubModal.test.d.ts +1 -0
  14. package/dist/components/views/standalone/modals/AccountHubModal.test.js +26 -0
  15. package/dist/core/EntitlementsPolicy.test.js +2 -2
  16. package/dist/core/GlobalSettingsService.js +78 -18
  17. package/dist/core/PlanEntitlementService.d.ts +29 -5
  18. package/dist/core/PlanEntitlementService.js +297 -219
  19. package/dist/core/SignupMonetizationSettings.test.js +173 -49
  20. package/dist/core/SystemAdmin.test.js +186 -96
  21. package/dist/core/Taskforce.d.ts +51 -10
  22. package/dist/core/Taskforce.js +218 -49
  23. package/dist/core/Taskforce.mcpAuth.test.js +0 -2
  24. package/dist/core/UserProfileAvatarDrafts.test.js +12 -3
  25. package/dist/core/types.d.ts +11 -12
  26. package/dist/hooks/useSyncOrchestrator.js +17 -3
  27. package/dist/hooks/useSyncOrchestrator.retry-closure.test.js +97 -5
  28. package/dist/hooks/useTaskforce.d.ts +3 -0
  29. package/dist/hooks/useTaskforce.js +9 -4
  30. package/dist/mcp/runtime.js +90 -29
  31. package/dist/mcp/runtime.test.js +272 -81
  32. package/dist/migrations/billingSchemaParity.test.js +3 -0
  33. package/dist/migrations/taskSchemaMigrations.js +15 -0
  34. package/dist/server/index.cookieProxy.test.js +1 -0
  35. package/dist/server/index.js +2 -0
  36. package/dist/server/index.test.js +2 -1
  37. package/dist/server/mockStripe.d.ts +1 -0
  38. package/dist/server/mockStripe.js +2 -0
  39. package/dist/server/routes/admin.js +80 -23
  40. package/dist/server/routes/auth.d.ts +1 -0
  41. package/dist/server/routes/auth.js +194 -53
  42. package/dist/server/routes/billing.js +506 -23
  43. package/dist/server/routes/billing.test.js +937 -45
  44. package/dist/server/routes/shared.js +5 -3
  45. package/dist/server/routes/sync.integration.test.js +160 -0
  46. package/dist/server/routes/sync.js +15 -5
  47. package/dist/server/routes.js +3 -3
  48. package/dist/server/routes.test.js +287 -76
  49. package/dist/sync/cloudSyncApi.d.ts +1 -0
  50. package/dist/sync/contentSyncState.d.ts +10 -0
  51. package/dist/sync/contentSyncState.js +277 -16
  52. package/dist/sync/syncService.d.ts +1 -0
  53. package/dist/sync/syncService.js +21 -8
  54. package/dist/sync/workspacePullFeed.d.ts +10 -0
  55. package/dist/sync/workspacePullFeed.js +111 -63
  56. package/dist/sync/workspacePullFeed.test.js +112 -0
  57. package/dist/ui/assets/{AgentsModule-JG5jc3he.js → AgentsModule-CpsTmrIW.js} +1 -1
  58. package/dist/ui/assets/{AnnotatedAttachmentWorkspace-Dvi02Y7q.js → AnnotatedAttachmentWorkspace-C_TmXZwA.js} +1 -1
  59. package/dist/ui/assets/{DocumentWorkspace-iys3zfca.js → DocumentWorkspace-C3GyzrWm.js} +1 -1
  60. package/dist/ui/assets/{InitiativesModule-DJvLJI3A.js → InitiativesModule-4-Rh2K2n.js} +1 -1
  61. package/dist/ui/assets/PlansPage-BP7AYOqr.js +1 -0
  62. package/dist/ui/assets/{TaskSettings-Bqd4cCzW.js → TaskSettings-BOC5F6Ag.js} +1 -1
  63. package/dist/ui/assets/{WorkflowsModule-BguHeQaV.js → WorkflowsModule-CGk9s3NJ.js} +1 -1
  64. package/dist/ui/assets/index-CLIMgR6g.js +6 -0
  65. package/dist/ui/assets/index-DneETxcu.css +1 -0
  66. package/dist/ui/assets/{vendor-icons-C8EED3Oh.js → vendor-icons-pWocEipT.js} +1 -1
  67. package/dist/ui/index.html +3 -3
  68. package/dist/utils/accountProfileSummaryCache.d.ts +31 -0
  69. package/dist/utils/accountProfileSummaryCache.js +97 -0
  70. package/dist/utils/accountProfileSummaryCache.test.d.ts +1 -0
  71. package/dist/utils/accountProfileSummaryCache.test.js +63 -0
  72. package/package.json +3 -3
  73. package/dist/ui/assets/PlansPage-BMPlpFpw.js +0 -1
  74. package/dist/ui/assets/index-MXeWoebC.css +0 -1
  75. package/dist/ui/assets/index-YJ4k5QNa.js +0 -6
  76. package/dist/utils/billingStatusCache.d.ts +0 -21
  77. package/dist/utils/billingStatusCache.js +0 -70
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { fireEvent, render, screen } from '@testing-library/react';
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import { AccountHubModal } from './AccountHubModal';
5
+ vi.mock('../../../ui/Modal', () => ({
6
+ Modal: ({ isOpen, children, title }) => (isOpen ? _jsxs("div", { children: [_jsx("h1", { children: title }), children] }) : null)
7
+ }));
8
+ describe('AccountHubModal', () => {
9
+ it('shows checkout recovery guidance and a plan-selection CTA for expired checkout attempts', () => {
10
+ const onStartCheckout = vi.fn();
11
+ render(_jsx(AccountHubModal, { isOpen: true, theme: "dark", runtimeMode: "cloud", authRequiredForApi: true, isAuthenticated: true, hasAuthIdentity: true, authIdentityLabel: "owner@example.com", billingLoading: false, billingError: null, billingActionError: null, billingNotice: null, billingActionBusy: false, billingIntervalChoice: "month", accountProfileSummary: {
12
+ planId: 'pro',
13
+ planName: 'Pro Plan',
14
+ entitlementState: 'pending_plan_selection',
15
+ gate: 'plan_selection_required',
16
+ message: 'Your latest checkout expired. Choose a plan to continue.',
17
+ billingConflictCode: 'CHECKOUT_SESSION_EXPIRED',
18
+ planSelectionRequired: true
19
+ }, currentWorkspaceId: "workspace-1", canOpenTeamManagement: false, canManageWorkspaceSync: false, workspaceCloudSyncEnabled: false, syncStatusLabel: "Disabled", workspaceSyncError: null, syncControlBusy: false, onClose: () => { }, onOpenWorkspaceAudit: () => { }, onBillingIntervalChange: () => { }, onRefreshBilling: () => { }, onUpdateInterval: () => { }, onManageBilling: () => { }, onStartCheckout: onStartCheckout, onToggleWorkspaceSync: () => { }, onOpenHelp: () => { } }));
20
+ expect(screen.getByText('Your latest checkout expired. Choose a plan to continue.')).toBeInTheDocument();
21
+ expect(screen.getByText('Pro Plan')).toBeInTheDocument();
22
+ const cta = screen.getByRole('button', { name: 'Choose Plan' });
23
+ fireEvent.click(cta);
24
+ expect(onStartCheckout).toHaveBeenCalledTimes(1);
25
+ });
26
+ });
@@ -171,8 +171,8 @@ describe('Taskforce entitlements policy engine', () => {
171
171
  email: 'member3@example.com',
172
172
  role: 'member'
173
173
  });
174
- }).toThrowError(TaskforceRuleError);
175
- expect(() => core.assertSeatAvailable('workspace-cap')).toThrowError(TaskforceRuleError);
174
+ }).toThrowError(/Seat limit reached/);
175
+ expect(() => core.assertSeatAvailable('workspace-cap')).toThrowError(/Seat limit reached/);
176
176
  }
177
177
  finally {
178
178
  core.close();
@@ -11,6 +11,9 @@ function splitGlobalSettingsPayload(settings) {
11
11
  if (settings.site && typeof settings.site === 'object') {
12
12
  system.site = { ...settings.site };
13
13
  }
14
+ if (settings.billing && typeof settings.billing === 'object') {
15
+ system.billing = { ...settings.billing };
16
+ }
14
17
  if (settings.setup && typeof settings.setup === 'object') {
15
18
  system.setup = { ...settings.setup };
16
19
  }
@@ -98,6 +101,17 @@ export function getGlobalSettingsService(deps) {
98
101
  const global = readGlobalConfigService(deps);
99
102
  const sourcePrefs = global.schedulePreferences || {};
100
103
  const sourceCapacity = sourcePrefs.dailyCapacity || {};
104
+ const billingOnboardingPolicy = global.billing?.onboardingPolicy && typeof global.billing.onboardingPolicy === 'object'
105
+ && (global.billing.onboardingPolicy.mode === 'require_plan_selection'
106
+ || global.billing.onboardingPolicy.mode === 'auto_grant_free'
107
+ || global.billing.onboardingPolicy.mode === 'auto_start_trial')
108
+ ? {
109
+ mode: global.billing.onboardingPolicy.mode,
110
+ planVersionId: typeof global.billing.onboardingPolicy.planVersionId === 'string'
111
+ ? (global.billing.onboardingPolicy.planVersionId.trim() || null)
112
+ : null
113
+ }
114
+ : null;
101
115
  const schedulePreferences = {
102
116
  ...(typeof sourcePrefs.showWeekends === 'boolean' ? { showWeekends: sourcePrefs.showWeekends } : {}),
103
117
  ...(typeof sourcePrefs.isCalendarSidebarOpen === 'boolean' ? { isCalendarSidebarOpen: sourcePrefs.isCalendarSidebarOpen } : {}),
@@ -163,14 +177,6 @@ export function getGlobalSettingsService(deps) {
163
177
  ...(typeof global.auth.authRateLimitWindowMs === 'number' && Number.isFinite(global.auth.authRateLimitWindowMs)
164
178
  ? { authRateLimitWindowMs: Math.max(1000, Math.floor(global.auth.authRateLimitWindowMs)) }
165
179
  : {}),
166
- ...((global.auth.signupMonetizationStrategy === 'auto_assign_default' || global.auth.signupMonetizationStrategy === 'plan_selection_required')
167
- ? { signupMonetizationStrategy: global.auth.signupMonetizationStrategy }
168
- : {}),
169
- ...(typeof global.auth.defaultSignupPlanVersionId === 'string'
170
- ? { defaultSignupPlanVersionId: global.auth.defaultSignupPlanVersionId.trim() || null }
171
- : global.auth.defaultSignupPlanVersionId === null
172
- ? { defaultSignupPlanVersionId: null }
173
- : {})
174
180
  }
175
181
  }
176
182
  : {}),
@@ -186,6 +192,13 @@ export function getGlobalSettingsService(deps) {
186
192
  }
187
193
  }
188
194
  : {}),
195
+ ...(billingOnboardingPolicy
196
+ ? {
197
+ billing: {
198
+ onboardingPolicy: billingOnboardingPolicy
199
+ }
200
+ }
201
+ : {}),
189
202
  ...(global.setup && typeof global.setup === 'object'
190
203
  ? {
191
204
  setup: {
@@ -289,7 +302,24 @@ export function updateGlobalSettingsService(deps, settings) {
289
302
  const currentAuth = next.auth && typeof next.auth === 'object' ? next.auth : {};
290
303
  const incoming = settings.auth;
291
304
  next.auth = {
292
- ...currentAuth,
305
+ ...(typeof currentAuth.allowSelfRegistration === 'boolean'
306
+ ? { allowSelfRegistration: currentAuth.allowSelfRegistration }
307
+ : {}),
308
+ ...(typeof currentAuth.requireVerifiedEmail === 'boolean'
309
+ ? { requireVerifiedEmail: currentAuth.requireVerifiedEmail }
310
+ : {}),
311
+ ...(typeof currentAuth.defaultNewUserBetaAccess === 'boolean'
312
+ ? { defaultNewUserBetaAccess: currentAuth.defaultNewUserBetaAccess }
313
+ : {}),
314
+ ...(typeof currentAuth.authRateLimitEnabled === 'boolean'
315
+ ? { authRateLimitEnabled: currentAuth.authRateLimitEnabled }
316
+ : {}),
317
+ ...(typeof currentAuth.authRateLimitMaxRequests === 'number' && Number.isFinite(currentAuth.authRateLimitMaxRequests)
318
+ ? { authRateLimitMaxRequests: Math.max(1, Math.floor(currentAuth.authRateLimitMaxRequests)) }
319
+ : {}),
320
+ ...(typeof currentAuth.authRateLimitWindowMs === 'number' && Number.isFinite(currentAuth.authRateLimitWindowMs)
321
+ ? { authRateLimitWindowMs: Math.max(1000, Math.floor(currentAuth.authRateLimitWindowMs)) }
322
+ : {}),
293
323
  ...(typeof incoming.allowSelfRegistration === 'boolean'
294
324
  ? { allowSelfRegistration: incoming.allowSelfRegistration }
295
325
  : {}),
@@ -307,15 +337,7 @@ export function updateGlobalSettingsService(deps, settings) {
307
337
  : {}),
308
338
  ...(typeof incoming.authRateLimitWindowMs === 'number' && Number.isFinite(incoming.authRateLimitWindowMs)
309
339
  ? { authRateLimitWindowMs: Math.max(1000, Math.floor(incoming.authRateLimitWindowMs)) }
310
- : {}),
311
- ...((incoming.signupMonetizationStrategy === 'auto_assign_default' || incoming.signupMonetizationStrategy === 'plan_selection_required')
312
- ? { signupMonetizationStrategy: incoming.signupMonetizationStrategy }
313
- : {}),
314
- ...(typeof incoming.defaultSignupPlanVersionId === 'string'
315
- ? { defaultSignupPlanVersionId: incoming.defaultSignupPlanVersionId.trim() || null }
316
- : incoming.defaultSignupPlanVersionId === null
317
- ? { defaultSignupPlanVersionId: null }
318
- : {})
340
+ : {})
319
341
  };
320
342
  }
321
343
  if (settings.site && typeof settings.site === 'object') {
@@ -331,6 +353,44 @@ export function updateGlobalSettingsService(deps, settings) {
331
353
  : {})
332
354
  };
333
355
  }
356
+ if (settings.billing && typeof settings.billing === 'object') {
357
+ const currentBilling = next.billing && typeof next.billing === 'object' ? next.billing : {};
358
+ const incoming = settings.billing;
359
+ const currentOnboardingPolicy = currentBilling.onboardingPolicy && typeof currentBilling.onboardingPolicy === 'object'
360
+ && (currentBilling.onboardingPolicy.mode === 'require_plan_selection'
361
+ || currentBilling.onboardingPolicy.mode === 'auto_grant_free'
362
+ || currentBilling.onboardingPolicy.mode === 'auto_start_trial')
363
+ ? {
364
+ mode: currentBilling.onboardingPolicy.mode,
365
+ planVersionId: typeof currentBilling.onboardingPolicy.planVersionId === 'string'
366
+ ? (currentBilling.onboardingPolicy.planVersionId.trim() || null)
367
+ : null
368
+ }
369
+ : null;
370
+ const incomingOnboardingPolicy = incoming.onboardingPolicy && typeof incoming.onboardingPolicy === 'object'
371
+ && (incoming.onboardingPolicy.mode === 'require_plan_selection'
372
+ || incoming.onboardingPolicy.mode === 'auto_grant_free'
373
+ || incoming.onboardingPolicy.mode === 'auto_start_trial')
374
+ ? {
375
+ mode: incoming.onboardingPolicy.mode,
376
+ planVersionId: typeof incoming.onboardingPolicy.planVersionId === 'string'
377
+ ? (incoming.onboardingPolicy.planVersionId.trim() || null)
378
+ : null
379
+ }
380
+ : null;
381
+ next.billing = {
382
+ ...(currentOnboardingPolicy
383
+ ? {
384
+ onboardingPolicy: currentOnboardingPolicy
385
+ }
386
+ : {}),
387
+ ...(incomingOnboardingPolicy
388
+ ? {
389
+ onboardingPolicy: incomingOnboardingPolicy
390
+ }
391
+ : {})
392
+ };
393
+ }
334
394
  if (settings.setup && typeof settings.setup === 'object') {
335
395
  const currentSetup = next.setup && typeof next.setup === 'object' ? next.setup : {};
336
396
  const incoming = settings.setup;
@@ -1,10 +1,11 @@
1
1
  import type { DatabaseAdapter } from '../storage/databaseAdapter.js';
2
- import type { EntitlementState, PlanFeatureAccess, PlanFeatureSnapshot, PlanFeatureCatalogItem, PlanVersionSnapshot, PlanCatalogSnapshot, AccountEntitlementSnapshot, SeatUsageSnapshot, FeatureEvaluationResult, AccountAccessStatus, GlobalTaskforceSettings, SignupMonetizationSettings, SignupMonetizationValidationResult } from './types.js';
2
+ import type { EntitlementState, PlanFeatureAccess, PlanFeatureSnapshot, PlanFeatureCatalogItem, PlanVersionSnapshot, PlanCatalogSnapshot, AccountEntitlementSnapshot, SeatUsageSnapshot, FeatureEvaluationResult, AccountAccessStatus, GlobalTaskforceSettings, OnboardingPolicy, OnboardingPolicyValidationResult } from './types.js';
3
3
  export interface PlanEntitlementServiceDeps {
4
4
  getWorkspaceOwnerUserId: (workspaceId: string) => string | null;
5
5
  readGlobalConfig: () => GlobalTaskforceSettings;
6
6
  writeGlobalConfig: (config: GlobalTaskforceSettings) => void;
7
7
  }
8
+ type CommercialStateTransitionSource = 'registration' | 'checkout-start' | 'checkout-confirm' | 'stripe-webhook' | 'backfill' | 'legacy-plan-mode' | 'admin' | 'system';
8
9
  /**
9
10
  * Handles all plan catalog, plan version, and account entitlement logic.
10
11
  * Extracted from Taskforce.ts to reduce monolith size.
@@ -24,9 +25,15 @@ export declare class PlanEntitlementService {
24
25
  private applyPlanVersionTrialDaysMetadata;
25
26
  private sanitizePlanFeatureConfig;
26
27
  private isEntitlementStateAllowed;
28
+ private isIsoTimestampExpired;
29
+ private readAccountEntitlementRow;
30
+ private normalizeExpiredCheckoutPendingRow;
31
+ private isBillingConfirmedTransitionSource;
32
+ private resolveCanonicalTransitionSource;
33
+ private resolvePendingPlanVersionId;
34
+ private buildBlockedAccessStatus;
27
35
  private repairPlanDefaultVersionIfNeeded;
28
36
  repairPlanCatalogDefaultsIfNeeded(): void;
29
- repairSignupMonetizationSettingsIfNeeded(): void;
30
37
  normalizeLegacyPlanDataIfNeeded(): void;
31
38
  private removeLegacyPlanFeatureRows;
32
39
  private migrateLegacySeatLimitFeatureConfigToVersionSeatLimit;
@@ -34,6 +41,18 @@ export declare class PlanEntitlementService {
34
41
  backfillAccountEntitlements(): void;
35
42
  private getRequiredDefaultPlanVersion;
36
43
  private resolveCanonicalEntitlementStateFromBilling;
44
+ transitionCanonicalCommercialState(input: {
45
+ accountId: string;
46
+ planVersionId?: string | null;
47
+ state: EntitlementState;
48
+ effectiveAt?: string | null;
49
+ effectiveUntil?: string | null;
50
+ billingMirrorPlanId?: string | null;
51
+ source: CommercialStateTransitionSource;
52
+ updatedBy: string;
53
+ createdAt?: string | null;
54
+ updatedAt?: string | null;
55
+ }): AccountEntitlementSnapshot;
37
56
  upsertCanonicalEntitlementRecord(input: {
38
57
  accountId: string;
39
58
  planVersionId: string;
@@ -55,12 +74,18 @@ export declare class PlanEntitlementService {
55
74
  feature: PlanFeatureSnapshot | null;
56
75
  };
57
76
  private planHasAnyActivePricing;
77
+ private planVersionHasActiveFreePricing;
78
+ private planVersionIsTrialEligible;
58
79
  private tryGetDefaultPlanVersionByPlanId;
59
80
  private getActiveDefaultPlanVersions;
60
81
  private getDefaultPlanVersionByMode;
61
82
  private tryGetDefaultPlanVersionByMode;
62
- resolveRegistrationPlanAssignment(selectedPlanVersionIdRaw?: string): {
83
+ getOnboardingPolicy(): OnboardingPolicy;
84
+ validateOnboardingPolicy(input?: Partial<OnboardingPolicy>): OnboardingPolicyValidationResult;
85
+ resolveRegistrationOnboardingOutcome(selectedPlanVersionIdRaw?: string): {
63
86
  requiresPlanSelection: boolean;
87
+ checkoutPending: boolean;
88
+ commercialState: EntitlementState;
64
89
  planVersionId: string | null;
65
90
  planId: string | null;
66
91
  };
@@ -98,8 +123,6 @@ export declare class PlanEntitlementService {
98
123
  planId: string;
99
124
  entitlementState: EntitlementState;
100
125
  };
101
- getSignupMonetizationSettings(): SignupMonetizationSettings;
102
- validateSignupMonetizationSettings(input?: Partial<SignupMonetizationSettings>): SignupMonetizationValidationResult;
103
126
  private isValidEntitlementTransition;
104
127
  addEntitlementAuditLog(input: {
105
128
  actorUserId: string;
@@ -199,3 +222,4 @@ export declare class PlanEntitlementService {
199
222
  }>;
200
223
  };
201
224
  }
225
+ export {};