@antelopejs/dms-saas 0.5.1 → 0.6.1
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/README.md +61 -1003
- package/dist/billing-state/recovery.js +2 -2
- package/dist/billing-state/recovery.js.map +1 -1
- package/dist/operator-actions/db/lifecycle-delivery.model.d.ts +1 -0
- package/dist/operator-actions/db/operator-action.model.d.ts +1 -0
- package/dist/pages/tenant/general.js +1 -0
- package/dist/pages/tenant/general.js.map +1 -1
- package/dist/stripe/client.d.ts +3 -0
- package/dist/stripe/client.js +16 -1
- package/dist/stripe/client.js.map +1 -1
- package/dist/stripe/customer-billing.js +1 -1
- package/dist/stripe/customer-billing.js.map +1 -1
- package/dist/stripe/subscription-cancellation.js +1 -1
- package/dist/stripe/subscription-cancellation.js.map +1 -1
- package/dist/stripe/upcoming-invoice.js +3 -3
- package/dist/stripe/upcoming-invoice.js.map +1 -1
- package/dist/types/config.d.ts +2 -0
- package/dist/types/config.js.map +1 -1
- package/dist/upcoming-invoice/db/preview-cache.model.d.ts +1 -0
- package/dist/workspaces/db/provisioning-attempt.model.d.ts +1 -0
- package/dist/workspaces/db/trial-identity.model.d.ts +1 -0
- package/frontend-vue/app/build/PayInvoicePanel.vue +4 -8
- package/frontend-vue/app/build/PlanChangeReview.vue +3 -6
- package/frontend-vue/app/build/segments/useSegmentCatalog.ts +7 -12
- package/frontend-vue/app/build/useWorkspaceName.ts +1 -2
- package/frontend-vue/app/build/users/useUserDetail.ts +8 -10
- package/frontend-vue/app/build/workspace-detail/ComplimentaryDialog.vue +5 -3
- package/frontend-vue/app/build/workspace-detail/CreditDialog.vue +5 -3
- package/frontend-vue/app/build/workspace-detail/UpgradeDialog.vue +14 -7
- package/frontend-vue/app/build/workspace-detail/useWorkspaceActions.ts +11 -10
- package/frontend-vue/app/build/workspace-detail/useWorkspaceOverview.ts +16 -30
- package/frontend-vue/app/components/CustomerPortalButton.vue +6 -4
- package/frontend-vue/app/components/DataExport.vue +34 -54
- package/frontend-vue/app/components/DataExportHistory.vue +2 -7
- package/frontend-vue/app/components/IssueCreditNoteModal.vue +5 -4
- package/frontend-vue/app/components/MigrationStripeCheck.vue +11 -8
- package/frontend-vue/app/components/PastDueAlert.vue +8 -6
- package/frontend-vue/app/components/PastDueBanner.vue +4 -4
- package/frontend-vue/app/components/PaymentMethodCard.vue +6 -11
- package/frontend-vue/app/components/PlanAccessEditor.vue +31 -30
- package/frontend-vue/app/components/PlanCard.vue +2 -3
- package/frontend-vue/app/components/PlanEditorPreview.vue +27 -36
- package/frontend-vue/app/components/PlanUpgradeModal.vue +1 -1
- package/frontend-vue/app/components/PlatformNotes.vue +27 -28
- package/frontend-vue/app/components/Pricing.vue +16 -23
- package/frontend-vue/app/components/RefundButton.vue +61 -46
- package/frontend-vue/app/components/RetirePlanModal.vue +13 -7
- package/frontend-vue/app/components/SeatQuotaBanner.vue +9 -10
- package/frontend-vue/app/components/SegmentConditionsBuilder.vue +0 -1
- package/frontend-vue/app/components/SegmentRulesText.vue +1 -3
- package/frontend-vue/app/components/TenantBillingForm.vue +14 -19
- package/frontend-vue/app/components/TenantPlanCard.vue +18 -21
- package/frontend-vue/app/components/TrialEndingBanner.vue +5 -10
- package/frontend-vue/app/components/UserPlatformRoleCard.vue +8 -9
- package/frontend-vue/app/components/UserSegmentMatches.vue +8 -16
- package/frontend-vue/app/components/UserSummaryCard.vue +2 -4
- package/frontend-vue/app/components/WorkspaceAdminCreateModal.vue +13 -5
- package/frontend-vue/app/components/WorkspaceCreateModal.vue +5 -1
- package/frontend-vue/app/components/WorkspaceDangerZone.vue +10 -9
- package/frontend-vue/app/components/WorkspaceDetailHeader.vue +14 -4
- package/frontend-vue/app/components/WorkspaceSuspended.vue +27 -32
- package/frontend-vue/app/components/WorkspaceSwitcherWidget.vue +5 -18
- package/frontend-vue/app/composables/useBillingIdentity.ts +9 -5
- package/frontend-vue/app/composables/useBillingStatus.ts +8 -7
- package/frontend-vue/app/composables/useCurrentWorkspace.ts +6 -8
- package/frontend-vue/app/composables/useExportHistory.ts +67 -78
- package/frontend-vue/app/composables/useMountedData.ts +27 -0
- package/frontend-vue/app/composables/useMyWorkspaces.ts +26 -28
- package/frontend-vue/app/composables/useNextInvoice.ts +7 -6
- package/frontend-vue/app/composables/useOnDemandRead.ts +49 -0
- package/frontend-vue/app/composables/usePendingCheckout.ts +2 -1
- package/frontend-vue/app/composables/usePlanCatalog.ts +3 -9
- package/frontend-vue/app/composables/usePublicPricing.ts +24 -0
- package/frontend-vue/app/composables/useSaasRegistration.ts +2 -0
- package/frontend-vue/app/composables/useSeatQuota.ts +2 -6
- package/frontend-vue/app/composables/useTenantPlan.ts +26 -9
- package/frontend-vue/app/composables/useWorkspaceOverview.ts +2 -6
- package/frontend-vue/app/custom-pages/auth/no-workspace.vue +3 -1
- package/frontend-vue/dms.server.ts +22 -0
- package/frontend-vue/package.json +1 -1
- package/package.json +36 -18
- package/skills/dms-saas/SKILL.md +56 -0
- package/frontend-vue/app/composables/useServerConfirm.ts +0 -44
- package/frontend-vue/app/composables/useSharedRequest.ts +0 -54
- package/frontend-vue/app/composables/useWorkspaceAccessCache.ts +0 -52
- package/frontend-vue/app/composables/useWorkspaceRenamed.ts +0 -33
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { computed, type ComputedRef } from 'vue'
|
|
1
|
+
import { computed, ref, type ComputedRef } from 'vue'
|
|
2
2
|
|
|
3
3
|
const EXPORT_ENDPOINT = '/api/saas/data-export'
|
|
4
4
|
const HISTORY_ENDPOINT = `${EXPORT_ENDPOINT}/history`
|
|
5
5
|
const START_ENDPOINT = `${EXPORT_ENDPOINT}/start`
|
|
6
|
-
|
|
6
|
+
/** Where an export's progress is read, by job id. */
|
|
7
|
+
export const EXPORT_STATUS_ENDPOINT = `${EXPORT_ENDPOINT}/status`
|
|
7
8
|
const DOWNLOAD_ENDPOINT = `${EXPORT_ENDPOINT}/download`
|
|
8
9
|
const HISTORY_PAGE_SIZE = 10
|
|
9
10
|
const FIRST_PAGE = 1
|
|
10
|
-
const
|
|
11
|
+
const HISTORY_KEY = 'saas-export-history'
|
|
12
|
+
const STARTING_STATE_KEY = 'saas-export-starting'
|
|
11
13
|
const FILENAME_HEADER_PATTERN = /filename="([^"]+)"/i
|
|
12
14
|
const FALLBACK_EXTENSION = 'zip'
|
|
13
15
|
|
|
@@ -66,18 +68,6 @@ interface ExportHistoryState {
|
|
|
66
68
|
hasMore: boolean
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
function initialState(): ExportHistoryState {
|
|
70
|
-
return {
|
|
71
|
-
entries: [],
|
|
72
|
-
isLoading: false,
|
|
73
|
-
hasLoaded: false,
|
|
74
|
-
hasFailed: false,
|
|
75
|
-
isStarting: false,
|
|
76
|
-
page: FIRST_PAGE,
|
|
77
|
-
hasMore: false,
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
71
|
function parseFilename(header: string | null): string | null {
|
|
82
72
|
return header?.match(FILENAME_HEADER_PATTERN)?.[1] ?? null
|
|
83
73
|
}
|
|
@@ -98,101 +88,101 @@ export function isExportExpired(
|
|
|
98
88
|
return !!entry.expiresAt && new Date(entry.expiresAt).getTime() <= nowMs
|
|
99
89
|
}
|
|
100
90
|
|
|
101
|
-
/** The history reload both blocks of the page share while it runs. */
|
|
102
|
-
let pendingRefresh: Promise<void> | null = null
|
|
103
|
-
|
|
104
91
|
interface ExportHistoryHandle {
|
|
105
|
-
|
|
92
|
+
/** The page of the history this block shows, read with the page. */
|
|
93
|
+
state: ComputedRef<ExportHistoryState>
|
|
106
94
|
/** The export still being built, if the newest page holds one. */
|
|
107
95
|
running: ComputedRef<ExportHistoryEntry | null>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
goToPage: (targetPage: number) =>
|
|
96
|
+
/** Reads the newest page again, and the page shown. */
|
|
97
|
+
load: () => Promise<void>
|
|
98
|
+
goToPage: (targetPage: number) => void
|
|
111
99
|
start: () => Promise<void>
|
|
112
|
-
readStatus: (jobId: string) => Promise<ExportJobStatus>
|
|
113
100
|
download: (jobId: string, naming?: ExportDownloadNaming) => Promise<void>
|
|
114
101
|
}
|
|
115
102
|
|
|
116
103
|
/**
|
|
117
104
|
* The caller's exports of the current workspace, shared by the request card
|
|
118
105
|
* and the history list of the Data export page: one export runs at a time, so
|
|
119
|
-
* both read the same running entry.
|
|
106
|
+
* both read the same running entry, from the newest page. The history list
|
|
107
|
+
* pages through the rest; the request card stays on the newest page.
|
|
120
108
|
*/
|
|
121
109
|
export function useExportHistory(): ExportHistoryHandle {
|
|
122
110
|
const { $authFetch } = useAuthFetch()
|
|
123
|
-
const
|
|
111
|
+
const isStarting = useDmsState<boolean>(STARTING_STATE_KEY, () => false)
|
|
112
|
+
const page = ref(FIRST_PAGE)
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A page past the first that comes back empty falls back to the first
|
|
116
|
+
* rather than showing the "no export yet" state, which would be a lie —
|
|
117
|
+
* exports expiring under the reader is enough to empty the page they were on.
|
|
118
|
+
*/
|
|
119
|
+
function readPage(target: () => number) {
|
|
120
|
+
return useApiData<ExportHistoryPage>(
|
|
121
|
+
() => `${HISTORY_KEY}:${target()}`,
|
|
122
|
+
async ({ $authFetch: fetch, signal }) => {
|
|
123
|
+
const read = (pageNumber: number) =>
|
|
124
|
+
fetch<ExportHistoryPage>(HISTORY_ENDPOINT, {
|
|
125
|
+
query: { page: pageNumber, pageSize: HISTORY_PAGE_SIZE },
|
|
126
|
+
signal,
|
|
127
|
+
})
|
|
128
|
+
const result = await read(target())
|
|
129
|
+
return !result.items.length && result.page > FIRST_PAGE
|
|
130
|
+
? read(FIRST_PAGE)
|
|
131
|
+
: result
|
|
132
|
+
},
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const newest = readPage(() => FIRST_PAGE)
|
|
137
|
+
const shown = readPage(() => page.value)
|
|
124
138
|
|
|
125
139
|
const running = computed(
|
|
126
140
|
() =>
|
|
127
|
-
|
|
141
|
+
newest.data.value?.items.find(
|
|
128
142
|
(entry) => entry.status === EXPORT_STATUS.pending,
|
|
129
143
|
) ?? null,
|
|
130
144
|
)
|
|
131
145
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
})
|
|
143
|
-
if (!result.items.length && result.page > FIRST_PAGE) {
|
|
144
|
-
return await load(FIRST_PAGE)
|
|
145
|
-
}
|
|
146
|
-
Object.assign(state.value, {
|
|
147
|
-
entries: result.items,
|
|
148
|
-
page: result.page,
|
|
149
|
-
hasMore: result.hasMore,
|
|
150
|
-
hasFailed: false,
|
|
151
|
-
hasLoaded: true,
|
|
152
|
-
})
|
|
153
|
-
} catch {
|
|
154
|
-
state.value.hasFailed = true
|
|
155
|
-
} finally {
|
|
156
|
-
state.value.isLoading = false
|
|
146
|
+
const state = computed<ExportHistoryState>(() => {
|
|
147
|
+
const current = shown.data.value
|
|
148
|
+
return {
|
|
149
|
+
entries: current?.items ?? [],
|
|
150
|
+
isLoading: shown.pending.value,
|
|
151
|
+
hasLoaded: !!current,
|
|
152
|
+
hasFailed: shown.status.value === 'error',
|
|
153
|
+
isStarting: isStarting.value,
|
|
154
|
+
page: current?.page ?? page.value,
|
|
155
|
+
hasMore: current?.hasMore ?? false,
|
|
157
156
|
}
|
|
158
|
-
}
|
|
157
|
+
})
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
pendingRefresh ??= load().finally(() => {
|
|
167
|
-
pendingRefresh = null
|
|
168
|
-
})
|
|
169
|
-
return pendingRefresh
|
|
159
|
+
async function load(): Promise<void> {
|
|
160
|
+
await Promise.all(
|
|
161
|
+
page.value === FIRST_PAGE
|
|
162
|
+
? [newest.refresh()]
|
|
163
|
+
: [newest.refresh(), shown.refresh()],
|
|
164
|
+
)
|
|
170
165
|
}
|
|
171
166
|
|
|
172
|
-
function goToPage(targetPage: number):
|
|
173
|
-
if (targetPage < FIRST_PAGE ||
|
|
174
|
-
|
|
175
|
-
return load(targetPage)
|
|
167
|
+
function goToPage(targetPage: number): void {
|
|
168
|
+
if (targetPage < FIRST_PAGE || shown.pending.value) return
|
|
169
|
+
page.value = targetPage
|
|
176
170
|
}
|
|
177
171
|
|
|
178
172
|
/** Rejects with the server's refusal, for the caller to word. */
|
|
179
173
|
async function start(): Promise<void> {
|
|
180
|
-
if (
|
|
181
|
-
|
|
174
|
+
if (isStarting.value) return
|
|
175
|
+
isStarting.value = true
|
|
182
176
|
try {
|
|
183
177
|
await $authFetch(START_ENDPOINT, { method: 'POST' })
|
|
184
178
|
} finally {
|
|
185
|
-
|
|
186
|
-
|
|
179
|
+
page.value = FIRST_PAGE
|
|
180
|
+
// The new export is listed before the button comes back.
|
|
181
|
+
await refreshPageBlocks()
|
|
182
|
+
isStarting.value = false
|
|
187
183
|
}
|
|
188
184
|
}
|
|
189
185
|
|
|
190
|
-
function readStatus(jobId: string): Promise<ExportJobStatus> {
|
|
191
|
-
return $authFetch<ExportJobStatus>(
|
|
192
|
-
`${STATUS_ENDPOINT}/${encodeURIComponent(jobId)}`,
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
186
|
/**
|
|
197
187
|
* Takes a job id rather than a history row: a link delivered by e-mail may
|
|
198
188
|
* point at an export older than the window the history lists. The id is
|
|
@@ -202,6 +192,7 @@ export function useExportHistory(): ExportHistoryHandle {
|
|
|
202
192
|
jobId: string,
|
|
203
193
|
naming?: ExportDownloadNaming,
|
|
204
194
|
): Promise<void> {
|
|
195
|
+
// A file to save, not data to show: fetched as it is, never kept.
|
|
205
196
|
const response = await $authFetch.raw(
|
|
206
197
|
`${DOWNLOAD_ENDPOINT}/${encodeURIComponent(jobId)}`,
|
|
207
198
|
{ responseType: 'blob' },
|
|
@@ -223,10 +214,8 @@ export function useExportHistory(): ExportHistoryHandle {
|
|
|
223
214
|
state,
|
|
224
215
|
running,
|
|
225
216
|
load,
|
|
226
|
-
refresh,
|
|
227
217
|
goToPage,
|
|
228
218
|
start,
|
|
229
|
-
readStatus,
|
|
230
219
|
download,
|
|
231
220
|
}
|
|
232
221
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
onMounted,
|
|
4
|
+
shallowRef,
|
|
5
|
+
type ComputedRef,
|
|
6
|
+
type Ref,
|
|
7
|
+
} from 'vue'
|
|
8
|
+
|
|
9
|
+
/** Where a read runs: `server: false` leaves it to the browser. */
|
|
10
|
+
export interface ApiReadOptions {
|
|
11
|
+
server?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Data a layout strip shows, kept null until the strip is mounted. A strip
|
|
16
|
+
* reads Stripe-backed data with `server: false`, so a slow Stripe never holds
|
|
17
|
+
* the server render of the whole page; the server then renders the strip
|
|
18
|
+
* without it, and the browser's first render must match that HTML, even when
|
|
19
|
+
* the page read the same request on the server and handed its data over.
|
|
20
|
+
*/
|
|
21
|
+
export function useMountedData<T>(data: Ref<T | null>): ComputedRef<T | null> {
|
|
22
|
+
const isMounted = shallowRef(false)
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
isMounted.value = true
|
|
25
|
+
})
|
|
26
|
+
return computed(() => (isMounted.value ? data.value : null))
|
|
27
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { computed, type ComputedRef } from 'vue'
|
|
2
|
+
|
|
1
3
|
/** One workspace of the switcher, as `GET /api/saas/workspaces/mine` answers it. */
|
|
2
4
|
export interface MyWorkspace {
|
|
3
5
|
_id: string
|
|
@@ -15,42 +17,38 @@ export interface MyWorkspace {
|
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
const WORKSPACES_ENDPOINT = '/api/saas/workspaces/mine'
|
|
18
|
-
const STATE_KEY = 'saas-my-workspaces'
|
|
19
20
|
|
|
20
21
|
interface MyWorkspacesHandle {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
/** Empty until the list is in, and for a visitor without a session. */
|
|
23
|
+
workspaces: ComputedRef<MyWorkspace[]>
|
|
24
|
+
isLoaded: ComputedRef<boolean>
|
|
25
|
+
/** The last read failed; the entries already on screen stay. */
|
|
26
|
+
hasFailed: ComputedRef<boolean>
|
|
23
27
|
refresh: () => Promise<void>
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
31
|
* Shared between the sidebar switcher and the screens that change what it
|
|
28
|
-
* displays (a
|
|
32
|
+
* displays (a deletion; a rename reads it again with the rest of the page),
|
|
33
|
+
* so a change never waits for a page reload.
|
|
34
|
+
* Nothing is read without a session: the public layouts mount the switcher's
|
|
35
|
+
* readers too.
|
|
29
36
|
*/
|
|
30
37
|
export function useMyWorkspaces(): MyWorkspacesHandle {
|
|
31
|
-
const {
|
|
32
|
-
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} catch (error) {
|
|
47
|
-
// Only the initial load may empty the list — a failed refresh keeps
|
|
48
|
-
// the entries already on screen rather than making the switcher
|
|
49
|
-
// disappear.
|
|
50
|
-
if (!isLoaded.value) workspaces.value = []
|
|
51
|
-
throw error
|
|
52
|
-
}
|
|
38
|
+
const { loggedIn } = useDmsUserSession()
|
|
39
|
+
const { data, status, refresh } = useApiData<MyWorkspace[]>(() =>
|
|
40
|
+
loggedIn.value ? WORKSPACES_ENDPOINT : null,
|
|
41
|
+
)
|
|
42
|
+
const workspaces = computed(() => data.value ?? [])
|
|
43
|
+
return {
|
|
44
|
+
workspaces,
|
|
45
|
+
isLoaded: computed(
|
|
46
|
+
() =>
|
|
47
|
+
!loggedIn.value ||
|
|
48
|
+
status.value === 'success' ||
|
|
49
|
+
workspaces.value.length > 0,
|
|
50
|
+
),
|
|
51
|
+
hasFailed: computed(() => status.value === 'error'),
|
|
52
|
+
refresh: () => refresh(),
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
return { workspaces, isLoaded, refresh }
|
|
56
54
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ApiReadOptions } from './useMountedData'
|
|
2
|
+
|
|
1
3
|
const NEXT_INVOICE_ENDPOINT = '/api/saas/tenant/upcoming-invoice'
|
|
2
|
-
const NEXT_INVOICE_STATE_KEY = 'saas-next-invoice'
|
|
3
4
|
|
|
4
5
|
/** The figures of Stripe's next-invoice preview that cards quote. */
|
|
5
6
|
export interface NextInvoiceSummary {
|
|
@@ -11,10 +12,10 @@ export interface NextInvoiceSummary {
|
|
|
11
12
|
/**
|
|
12
13
|
* Stripe's preview of the next invoice, shared by the cards quoting its total
|
|
13
14
|
* (plan card, trial strip); the "Next invoice" block reads the full rows.
|
|
15
|
+
* The trial strip reads it with `server: false` (see `useMountedData`).
|
|
14
16
|
*/
|
|
15
|
-
export function useNextInvoice(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
17
|
+
export function useNextInvoice(
|
|
18
|
+
options: ApiReadOptions = {},
|
|
19
|
+
): ApiDataResult<NextInvoiceSummary> {
|
|
20
|
+
return useApiData<NextInvoiceSummary>(NEXT_INVOICE_ENDPOINT, options)
|
|
20
21
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter, Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** A backend URL to read, or nothing to read while it is null or undefined. */
|
|
4
|
+
export type OnDemandUrl = () => string | null | undefined
|
|
5
|
+
|
|
6
|
+
/** Query parameters of an on-demand read, read again for each request. */
|
|
7
|
+
export type OnDemandQuery = MaybeRefOrGetter<Record<string, unknown> | undefined>
|
|
8
|
+
|
|
9
|
+
export interface OnDemandReadOptions {
|
|
10
|
+
query?: OnDemandQuery
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OnDemandRead<T> {
|
|
14
|
+
/** The last answer to the current URL, null until one came. */
|
|
15
|
+
data: Readonly<Ref<T | null>>
|
|
16
|
+
pending: Readonly<Ref<boolean>>
|
|
17
|
+
/** Reads the URL now; rejects with the failure. */
|
|
18
|
+
read: () => Promise<T>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What makes a read wait for `read()`: never on a server, never on its own. */
|
|
22
|
+
const ON_DEMAND = {
|
|
23
|
+
immediate: false,
|
|
24
|
+
server: false,
|
|
25
|
+
watch: false,
|
|
26
|
+
refreshOnPageRefresh: false,
|
|
27
|
+
} as const
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A read a component makes when it needs it (a dialog or a drawer opening, a
|
|
31
|
+
* lookup, a preview), through `useApiData` as every read of the module: in
|
|
32
|
+
* the browser only, outside the page's refreshes, and afresh on each `read()`.
|
|
33
|
+
* The URL and the query may change between reads: each `read()` asks for the
|
|
34
|
+
* current ones.
|
|
35
|
+
*/
|
|
36
|
+
export function useOnDemandRead<T>(
|
|
37
|
+
url: OnDemandUrl,
|
|
38
|
+
options: OnDemandReadOptions = {},
|
|
39
|
+
): OnDemandRead<T> {
|
|
40
|
+
const request = useApiData<T>(url, { query: options.query, ...ON_DEMAND })
|
|
41
|
+
|
|
42
|
+
async function read(): Promise<T> {
|
|
43
|
+
await request.execute()
|
|
44
|
+
if (request.status.value === 'error') throw request.error.value
|
|
45
|
+
return request.data.value as T
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return { data: request.data, pending: request.pending, read }
|
|
49
|
+
}
|
|
@@ -30,7 +30,8 @@ export function usePendingCheckout() {
|
|
|
30
30
|
)
|
|
31
31
|
const route = useDmsRoute()
|
|
32
32
|
const router = useDmsRouter()
|
|
33
|
-
const { loadPendingCheckout, cancelCheckout, changePlan } =
|
|
33
|
+
const { loadPendingCheckout, cancelCheckout, changePlan } =
|
|
34
|
+
useTenantPlanChanges()
|
|
34
35
|
|
|
35
36
|
/** Raises the prompt when `error` is a pending-checkout refusal. */
|
|
36
37
|
async function offerFor(error: unknown, planId: string): Promise<boolean> {
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { type PlanCatalog, PLANS_ENDPOINT } from '../build/plan-catalog'
|
|
2
2
|
|
|
3
|
-
const PLAN_CATALOG_STATE_KEY = 'saas-plan-catalog'
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* The plans, features and new-plan permissions of the catalogue, read once
|
|
7
5
|
* for every block of a page: the plan cards, the editor's access matrix and
|
|
8
|
-
* preview, the retire dialog. `
|
|
9
|
-
* `refresh` reads the catalogue as it stands now.
|
|
6
|
+
* preview, the retire dialog. `refresh` reads the catalogue as it stands now.
|
|
10
7
|
*/
|
|
11
|
-
export function usePlanCatalog():
|
|
12
|
-
|
|
13
|
-
return useSharedRequest(PLAN_CATALOG_STATE_KEY, () =>
|
|
14
|
-
$authFetch<PlanCatalog>(`${PLANS_ENDPOINT}/catalog`),
|
|
15
|
-
)
|
|
8
|
+
export function usePlanCatalog(): ApiDataResult<PlanCatalog> {
|
|
9
|
+
return useApiData<PlanCatalog>(`${PLANS_ENDPOINT}/catalog`)
|
|
16
10
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PublicPricing } from '../build/public/pricing'
|
|
2
|
+
|
|
3
|
+
const PRICING_ENDPOINT = '/api/saas/pricing'
|
|
4
|
+
const PRICING_KEY = 'saas:public-pricing'
|
|
5
|
+
const CONTENT_LANGUAGE_HEADER = 'x-content-language'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The plans on sale and the billing rules the pricing page shows, read with
|
|
9
|
+
* the page: a server render hands them over in the visitor's language. The
|
|
10
|
+
* key names that language, so a switch reads them again in the new one (the
|
|
11
|
+
* API localizes feature names and units). The language goes with each
|
|
12
|
+
* request: `$authFetch` keeps the one it was created in.
|
|
13
|
+
*/
|
|
14
|
+
export function usePublicPricing() {
|
|
15
|
+
const { locale } = useI18n()
|
|
16
|
+
return useApiData<PublicPricing>(
|
|
17
|
+
() => `${PRICING_KEY}:${locale.value}`,
|
|
18
|
+
({ $authFetch, signal }) =>
|
|
19
|
+
$authFetch<PublicPricing>(PRICING_ENDPOINT, {
|
|
20
|
+
signal,
|
|
21
|
+
headers: { [CONTENT_LANGUAGE_HEADER]: locale.value },
|
|
22
|
+
}),
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -463,6 +463,8 @@ export function useSaasRegistration(options: UseSaasRegistrationOptions = {}) {
|
|
|
463
463
|
async function mountPaymentElement(): Promise<void> {
|
|
464
464
|
const publishableKey = saasConfig?.stripePublishableKey
|
|
465
465
|
if (!publishableKey) return
|
|
466
|
+
// Not a `useApiData` read: each call creates a SetupIntent, whose client
|
|
467
|
+
// secret is the card form's alone, never cached nor shared.
|
|
466
468
|
const setup = await $authFetch<SetupIntentResponse>(SETUP_INTENT_ENDPOINT)
|
|
467
469
|
if (!setup.clientSecret) return
|
|
468
470
|
stripeHandle.value = useStripePaymentElement({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const SEAT_QUOTA_ENDPOINT = '/api/saas/tenant/seats'
|
|
2
|
-
const SEAT_QUOTA_STATE_KEY = 'saas-seat-quota'
|
|
3
2
|
|
|
4
3
|
export interface PlatformSupportMember {
|
|
5
4
|
userId: string
|
|
@@ -28,9 +27,6 @@ export interface SeatQuotaResponse {
|
|
|
28
27
|
platformSupport: PlatformSupportMember[]
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
export function useSeatQuota():
|
|
32
|
-
|
|
33
|
-
return useSharedRequest(SEAT_QUOTA_STATE_KEY, () =>
|
|
34
|
-
$authFetch<SeatQuotaResponse>(SEAT_QUOTA_ENDPOINT),
|
|
35
|
-
)
|
|
30
|
+
export function useSeatQuota(): ApiDataResult<SeatQuotaResponse> {
|
|
31
|
+
return useApiData<SeatQuotaResponse>(SEAT_QUOTA_ENDPOINT)
|
|
36
32
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PlanInterval } from './usePlanIntervalLabel'
|
|
2
2
|
|
|
3
3
|
const TENANT_PLAN_ENDPOINT = '/api/saas/tenant/plan'
|
|
4
|
-
const TENANT_PLAN_STATE_KEY = 'saas-tenant-plan'
|
|
5
4
|
const TENANT_CHECKOUT_ENDPOINT = `${TENANT_PLAN_ENDPOINT}/checkout`
|
|
6
5
|
const TENANT_PREVIEW_ENDPOINT = `${TENANT_PLAN_ENDPOINT}/preview`
|
|
7
6
|
const TENANT_CANCELLATION_ENDPOINT = `${TENANT_PLAN_ENDPOINT}/cancellation`
|
|
@@ -188,11 +187,31 @@ function currentPageUrl(): string {
|
|
|
188
187
|
|
|
189
188
|
/** The payload resolves inheritance for every public plan and carries the
|
|
190
189
|
* features catalogue, so the plan card and the free-access banner share it. */
|
|
191
|
-
|
|
190
|
+
/** What a change's preview is asked for: the plan, and the country to tax. */
|
|
191
|
+
type PreviewQuery = {
|
|
192
|
+
planId: string
|
|
193
|
+
country?: string
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function useTenantPlan(): ApiDataResult<TenantPlanResponse> {
|
|
197
|
+
return useApiData<TenantPlanResponse>(TENANT_PLAN_ENDPOINT)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* What changes the workspace's plan, and the reads a dialog makes on a click
|
|
202
|
+
* (a change's preview, the checkout left pending). The plan itself is
|
|
203
|
+
* `useTenantPlan`'s: refresh it once a change went through.
|
|
204
|
+
*/
|
|
205
|
+
export function useTenantPlanChanges() {
|
|
192
206
|
const { $authFetch } = useAuthFetch()
|
|
193
207
|
const { authenticateUpgrade } = useUpgradeAuthentication()
|
|
194
|
-
const
|
|
195
|
-
|
|
208
|
+
const previewQuery = shallowRef<PreviewQuery | null>(null)
|
|
209
|
+
const previewRead = useOnDemandRead<PlanChangePreview>(
|
|
210
|
+
() => (previewQuery.value ? TENANT_PREVIEW_ENDPOINT : null),
|
|
211
|
+
{ query: () => previewQuery.value ?? undefined },
|
|
212
|
+
)
|
|
213
|
+
const checkoutRead = useOnDemandRead<PendingCheckoutResult>(
|
|
214
|
+
() => TENANT_CHECKOUT_ENDPOINT,
|
|
196
215
|
)
|
|
197
216
|
|
|
198
217
|
/**
|
|
@@ -223,9 +242,8 @@ export function useTenantPlan() {
|
|
|
223
242
|
planId: string,
|
|
224
243
|
country?: string | null,
|
|
225
244
|
): Promise<PlanChangePreview> {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
})
|
|
245
|
+
previewQuery.value = country ? { planId, country } : { planId }
|
|
246
|
+
return previewRead.read()
|
|
229
247
|
}
|
|
230
248
|
|
|
231
249
|
function cancelPendingChange(): Promise<ChangePlanResult> {
|
|
@@ -247,7 +265,7 @@ export function useTenantPlan() {
|
|
|
247
265
|
}
|
|
248
266
|
|
|
249
267
|
function loadPendingCheckout(): Promise<PendingCheckoutResult> {
|
|
250
|
-
return
|
|
268
|
+
return checkoutRead.read()
|
|
251
269
|
}
|
|
252
270
|
|
|
253
271
|
/** Without an operation id, gives up on whatever checkout is pending. */
|
|
@@ -259,7 +277,6 @@ export function useTenantPlan() {
|
|
|
259
277
|
}
|
|
260
278
|
|
|
261
279
|
return {
|
|
262
|
-
...shared,
|
|
263
280
|
changePlan,
|
|
264
281
|
previewChange,
|
|
265
282
|
cancelPendingChange,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const OVERVIEW_ENDPOINT = '/api/saas/workspaces/current/overview'
|
|
2
|
-
const OVERVIEW_STATE_KEY = 'saas-workspace-overview'
|
|
3
2
|
|
|
4
3
|
/** Seats as the members page counts them; `maxMembers` null when unlimited. */
|
|
5
4
|
export interface WorkspaceSeatsOverview {
|
|
@@ -50,9 +49,6 @@ export interface WorkspaceOverview {
|
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
/** What the General page's danger zone states about deleting the workspace. */
|
|
53
|
-
export function useWorkspaceOverview():
|
|
54
|
-
|
|
55
|
-
return useSharedRequest(OVERVIEW_STATE_KEY, () =>
|
|
56
|
-
$authFetch<WorkspaceOverview>(OVERVIEW_ENDPOINT),
|
|
57
|
-
)
|
|
52
|
+
export function useWorkspaceOverview(): ApiDataResult<WorkspaceOverview> {
|
|
53
|
+
return useApiData<WorkspaceOverview>(OVERVIEW_ENDPOINT)
|
|
58
54
|
}
|
|
@@ -233,7 +233,9 @@ async function submit(): Promise<void> {
|
|
|
233
233
|
})
|
|
234
234
|
const destination = landingPath()
|
|
235
235
|
rememberChosenPlan(null)
|
|
236
|
-
|
|
236
|
+
// The token is spent: the destination takes this page's place in the
|
|
237
|
+
// history, so Back does not return to a form that can only fail.
|
|
238
|
+
if (typeof window !== 'undefined') window.location.replace(destination)
|
|
237
239
|
} catch (error) {
|
|
238
240
|
errorMessage.value = resolveApiError(
|
|
239
241
|
error,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineDmsServer } from '#dms/server'
|
|
2
|
+
import { LEGAL_DOCUMENTS } from './app/build/public/routes'
|
|
3
|
+
|
|
4
|
+
// The legal pages hold no visitor data and load their text in the browser:
|
|
5
|
+
// a shared cache in front of the frontend server may keep them a few minutes
|
|
6
|
+
// for visitors without any cookie. Every other request stays private.
|
|
7
|
+
const LEGAL_PAGE_CACHE = {
|
|
8
|
+
public: true,
|
|
9
|
+
maxAge: 300,
|
|
10
|
+
staleWhileRevalidate: 3600,
|
|
11
|
+
} as const
|
|
12
|
+
|
|
13
|
+
export default defineDmsServer((server) => {
|
|
14
|
+
server.registerRouteRules(
|
|
15
|
+
Object.fromEntries(
|
|
16
|
+
LEGAL_DOCUMENTS.map((document) => [
|
|
17
|
+
document.path,
|
|
18
|
+
{ cache: LEGAL_PAGE_CACHE },
|
|
19
|
+
]),
|
|
20
|
+
),
|
|
21
|
+
)
|
|
22
|
+
})
|