Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

feat(cloud): add support links and plan purchase entry points

Timothy Yin7bc858a6f5c6
diff --git a/apps/cloud/app/assets/cloud.css b/apps/cloud/app/assets/cloud.css
index 06939765..e1bbc826 100644
--- a/apps/cloud/app/assets/cloud.css
+++ b/apps/cloud/app/assets/cloud.css
@@ -1271,11 +1271,6 @@
transform: translateX(-100%);
opacity: 0;
}
-@media (max-width: 899px) {
- .cf-preview-badge {
- display: none;
- }
-}
/* Management surfaces use the same table, metadata forms and viewer primitives as the console. */
.cf-site-page-header {
@@ -2989,3 +2984,26 @@ a.cf-domain-address:hover {
margin: 0 auto 12px;
gap: 2px;
}
+
+.cf-support-link {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+}
+.cf-support-link svg {
+ flex-shrink: 0;
+}
+.cf-pricing-footer {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-wrap: wrap;
+ gap: 12px 24px;
+ margin-top: 24px;
+ color: var(--muted-foreground);
+ font-size: 12px;
+}
+.cf-pricing-card:target {
+ outline: 2px solid var(--ring);
+ outline-offset: 3px;
+}
diff --git a/apps/cloud/app/components/CloudPortalShell.vue b/apps/cloud/app/components/CloudPortalShell.vue
index 54e1ea0f..3a4c6fb6 100644
--- a/apps/cloud/app/components/CloudPortalShell.vue
+++ b/apps/cloud/app/components/CloudPortalShell.vue
@@ -53,12 +53,7 @@ useCloudSiteSubscription()
/>
<span class="cf-header-location">{{ section }}</span>
</template>
- <template #actions
- ><CfBadge class="cf-preview-badge">{{
- $t('cloud.messages.cloudPreview')
- }}</CfBadge
- ><CloudThemeToggle
- /></template>
+ <template #actions><CloudThemeToggle /></template>
<template #navigation><CloudSidebarNavigation /></template>
<template #footer><CloudUserMenu /></template>
<slot />
diff --git a/apps/cloud/app/components/CloudPricing.vue b/apps/cloud/app/components/CloudPricing.vue
index 20e1ecfd..7d03d744 100644
--- a/apps/cloud/app/components/CloudPricing.vue
+++ b/apps/cloud/app/components/CloudPricing.vue
@@ -1,4 +1,5 @@
<script setup lang="ts">
+import { planPurchasePath } from '../utils/plan-purchase'
import {
BILLING_LIMITS,
allowance,
@@ -14,9 +15,15 @@ const props = withDefaults(
}>(),
{ portal: false, embedded: false },
)
+const route = useRoute()
+const requestedPurchase = computed(() =>
+ planPurchasePath(route.query.plan, route.query.interval),
+)
const { t, locale } = useI18n(),
links = useCloudLinks(),
- interval = ref<1 | 3>(1)
+ interval = ref<1 | 3>(
+ requestedPurchase.value && route.query.interval === '3' ? 3 : 1,
+ )
const billingPeriod = computed({
get: () => String(interval.value),
set: (value: string) => {
@@ -60,12 +67,7 @@ const currentPlan = computed(() => billing?.data.value?.plan.id)
const amount = (plan: any) =>
interval.value === 1 ? plan.monthlyPrice : plan.quarterlyPrice
const action = (plan: any) =>
- !props.portal && plan.id === data.value?.newPlanId
- ? links.signup
- : links.redeem +
- (props.portal && billing?.selected.value
- ? '?workspaceId=' + billing.selected.value
- : '')
+ amount(plan) === 0 ? links.signup : links.purchase(plan.id, interval.value)
const payment = computed(() => payments?.data.value),
paying = ref(''),
paymentError = ref('')
@@ -161,9 +163,9 @@ async function checkout(plan: any) {
/>
<p class="cf-field-hint">
{{
- payment?.enabled
+ portal && payment?.environment === 'test'
? $t('cloud.payments.testHelp')
- : $t('cloud.billing.paymentsPlanned')
+ : $t('cloud.billing.purchaseHelp')
}}
</p>
<p
@@ -206,6 +208,8 @@ async function checkout(plan: any) {
<article
v-for="plan in data.plans"
:key="plan.id"
+ :id="'plan-' + plan.id"
+ tabindex="-1"
class="cf-pricing-card"
:class="{
'is-featured': plan.featured && !embedded,
@@ -246,11 +250,9 @@ async function checkout(plan: any) {
' / ' +
$t('cloud.billing.month')
: $t(
- portal
- ? amount(plan) === 0
- ? 'cloud.billing.noCharge'
- : 'cloud.billing.monthlyBilling'
- : 'cloud.billing.noCheckout',
+ amount(plan) === 0
+ ? 'cloud.billing.noCharge'
+ : 'cloud.billing.monthlyBilling',
)
}}
</p>
@@ -303,15 +305,25 @@ async function checkout(plan: any) {
>{{ $t('cloud.payments.subscribe') }}</CfButton
>
<CfButton
- v-else-if="
- portal &&
- (billing?.data.value?.workspace.role !== 'admin' ||
- !!payment?.pending)
+ v-else-if="portal"
+ disabled
+ variant="secondary"
+ :title="
+ billing?.data.value?.workspace.role !== 'admin'
+ ? $t('cloud.billing.adminOnly')
+ : $t('cloud.billing.purchaseUnavailableHelp')
"
+ >{{
+ billing?.data.value?.workspace.role !== 'admin'
+ ? $t('cloud.billing.adminOnly')
+ : $t('cloud.billing.purchaseUnavailable')
+ }}</CfButton
+ >
+ <CfButton
+ v-else-if="amount(plan) === null"
disabled
- :title="$t('cloud.billing.adminOnly')"
variant="secondary"
- >{{ $t('cloud.billing.redeem') }}</CfButton
+ >{{ $t('cloud.billing.notPriced') }}</CfButton
>
<CfButton
v-else
@@ -319,13 +331,11 @@ async function checkout(plan: any) {
:variant="plan.featured ? 'default' : 'secondary'"
><NuxtLink
:to="action(plan)"
- :external="!portal"
+ external
>{{
- $t(
- !portal && plan.id === data.newPlanId
- ? 'cloud.billing.createAccount'
- : 'cloud.billing.redeem',
- )
+ amount(plan) === 0
+ ? $t('cloud.billing.createAccount')
+ : $t('cloud.billing.buyPlan', { plan: plan.name })
}}</NuxtLink
></CfButton
>
@@ -382,6 +392,13 @@ async function checkout(plan: any) {
:caption="$t('cloud.billing.compare')"
/></section
></template>
+ <div class="cf-pricing-footer">
+ <CloudSupportLink /><NuxtLink
+ :to="links.redeem"
+ :external="!portal"
+ >{{ $t('cloud.billing.redeem') }}</NuxtLink
+ >
+ </div>
<CloudLegalLinks />
</div>
</template>
diff --git a/apps/cloud/app/components/CloudSupportLink.vue b/apps/cloud/app/components/CloudSupportLink.vue
new file mode 100644
index 00000000..4d07e0af
--- /dev/null
+++ b/apps/cloud/app/components/CloudSupportLink.vue
@@ -0,0 +1,16 @@
+<script setup lang="ts">
+import { Mail } from 'lucide-vue-next'
+</script>
+<template>
+ <a
+ href="mailto:[email protected]"
+ class="cf-support-link"
+ :aria-label="
+ $t('cloud.support.email', { email: '[email protected]' })
+ "
+ ><Mail
+ :size="14"
+ aria-hidden="true"
+ /><span>[email protected]</span></a
+ >
+</template>
diff --git a/apps/cloud/app/components/CloudUserMenu.vue b/apps/cloud/app/components/CloudUserMenu.vue
index b3f95ce1..ec23a578 100644
--- a/apps/cloud/app/components/CloudUserMenu.vue
+++ b/apps/cloud/app/components/CloudUserMenu.vue
@@ -84,6 +84,7 @@ const initials = computed(() =>
><Ticket :size="16" />{{ $t('cloud.billing.redeem') }}</NuxtLink
></DropdownMenuItem
>
+ <DropdownMenuItem as-child><CloudSupportLink /></DropdownMenuItem>
<DropdownMenuSeparator class="cf-menu-separator" />
<DropdownMenuItem
:disabled="busy"
diff --git a/apps/cloud/app/composables/useCloudAuthDestination.ts b/apps/cloud/app/composables/useCloudAuthDestination.ts
new file mode 100644
index 00000000..274b6826
--- /dev/null
+++ b/apps/cloud/app/composables/useCloudAuthDestination.ts
@@ -0,0 +1,12 @@
+import { purchaseReturnPath } from '../utils/plan-purchase'
+export function useCloudAuthDestination() {
+ const route = useRoute()
+ const destination = computed(
+ () => purchaseReturnPath(route.query.next) ?? '/workspace',
+ )
+ function authLink(path: '/signin' | '/signup') {
+ const next = purchaseReturnPath(route.query.next)
+ return { path, query: next ? { next } : {} }
+ }
+ return { destination, authLink }
+}
diff --git a/apps/cloud/app/composables/useCloudLinks.ts b/apps/cloud/app/composables/useCloudLinks.ts
index 79fb23a7..f2b4d064 100644
--- a/apps/cloud/app/composables/useCloudLinks.ts
+++ b/apps/cloud/app/composables/useCloudLinks.ts
@@ -1,3 +1,4 @@
+import { planPurchasePath } from '../utils/plan-purchase'
/** Production actions cross to the portal; preview/local auth stays on its own isolated origin. */
export function useCloudLinks() {
const hostname = useCloudRequestURL().hostname
@@ -10,5 +11,7 @@ export function useCloudLinks() {
signup: portal + '/signup',
redeem: portal + '/account/redeem',
portalPricing: portal + '/account/plan#plans',
+ purchase: (plan: string, interval: 1 | 3) =>
+ portal + (planPurchasePath(plan, interval) ?? '/account/plan#plans'),
}
}
diff --git a/apps/cloud/app/middleware/platform.global.ts b/apps/cloud/app/middleware/platform.global.ts
index 94ae47b5..062b6d3f 100644
--- a/apps/cloud/app/middleware/platform.global.ts
+++ b/apps/cloud/app/middleware/platform.global.ts
@@ -1,3 +1,4 @@
+import { purchaseReturnPath } from '../utils/plan-purchase'
import type {
EntrySiteCatalog,
EntrySiteSummary,
@@ -18,7 +19,9 @@ export default defineNuxtRouteMiddleware(async (to) => {
'/api/auth/session',
).catch(() => null)
if (session?.authenticated)
- return navigateTo('/workspace', { redirectCode: 302 })
+ return navigateTo(purchaseReturnPath(to.query.next) ?? '/workspace', {
+ redirectCode: 302,
+ })
}
if (
(path === '/pricing' &&
@@ -45,7 +48,11 @@ export default defineNuxtRouteMiddleware(async (to) => {
session.user?.id ?? null
if (!session.authenticated || !session.user) {
context.value = null
- return navigateTo('/signin', { redirectCode: 302 })
+ const next = purchaseReturnPath(to.fullPath)
+ return navigateTo(
+ { path: '/signin', query: next ? { next } : {} },
+ { redirectCode: 302 },
+ )
}
if (path === '/sites' || path === '/workspace') {
const result = await fetcher<{ sites: EntrySiteSummary[] }>('/api/sites')
diff --git a/apps/cloud/app/pages/index.vue b/apps/cloud/app/pages/index.vue
index 02ccf35f..f6027195 100644
--- a/apps/cloud/app/pages/index.vue
+++ b/apps/cloud/app/pages/index.vue
@@ -58,7 +58,7 @@ useSeoMeta({
></CfButton>
</div>
<p class="cf-small-note">
- {{ $t('cloud.messages.selfHostedIsAvailableNowCloudIsInPreview') }}
+ {{ $t('cloud.messages.chooseHostedOrSelfHosted') }}
</p></motion.div
>
<motion.div v-bind="entrance"
@@ -167,6 +167,7 @@ useSeoMeta({
href="https://github.com/HoshinoSuzumi/chronoframe/blob/main/LICENSING.md"
>{{ $t('cloud.messages.sourceAndLicensing') }}<ArrowUpRight :size="13"
/></a>
+ <CloudSupportLink />
<CloudLegalLinks />
</footer>
</div>
diff --git a/apps/cloud/app/pages/signin.vue b/apps/cloud/app/pages/signin.vue
index af0b0569..d6fa72b9 100644
--- a/apps/cloud/app/pages/signin.vue
+++ b/apps/cloud/app/pages/signin.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
const { t } = useI18n()
+const { destination, authLink } = useCloudAuthDestination()
import { accountError } from '../utils/account-error'
const { data: status } = await useFetch('/api/auth/status')
@@ -76,7 +77,7 @@ async function submit() {
return
}
}
- await navigateTo('/workspace', { external: true })
+ await navigateTo(destination.value, { external: true })
} catch (cause) {
error.value = accountError(cause, t)
} finally {
@@ -93,7 +94,7 @@ async function passkeySignIn() {
try {
const result = await useCloudAccount().signIn.passkey()
if (result.error) throw result.error
- await navigateTo('/workspace', { external: true })
+ await navigateTo(destination.value, { external: true })
} catch (cause) {
error.value = accountError(cause, t)
} finally {
@@ -271,7 +272,7 @@ async function resend() {
<p class="cf-auth-hint">
{{ $t('cloud.messages.newHere')
}}<NuxtLink
- to="/signup"
+ :to="authLink('/signup')"
class="cf-text-link"
>{{ $t('cloud.messages.createAnAccount') }}</NuxtLink
>
diff --git a/apps/cloud/app/pages/signup.vue b/apps/cloud/app/pages/signup.vue
index 73992287..711a3b93 100644
--- a/apps/cloud/app/pages/signup.vue
+++ b/apps/cloud/app/pages/signup.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
const { t } = useI18n()
+const { destination, authLink } = useCloudAuthDestination()
import { accountError } from '../utils/account-error'
useSeoMeta({
@@ -34,7 +35,7 @@ async function submit() {
method: 'POST',
body: { email: email.value, otp: code.value },
})
- await navigateTo('/workspace', { external: true })
+ await navigateTo(destination.value, { external: true })
}
} catch (cause) {
error.value = accountError(cause, t)
@@ -153,7 +154,7 @@ async function resend() {
<p class="cf-auth-hint">
{{ $t('cloud.messages.alreadyHaveAnAccount')
}}<NuxtLink
- to="/signin"
+ :to="authLink('/signin')"
class="cf-text-link"
>{{ $t('cloud.messages.logIn') }}</NuxtLink
>
diff --git a/apps/cloud/app/utils/plan-purchase.ts b/apps/cloud/app/utils/plan-purchase.ts
new file mode 100644
index 00000000..02848156
--- /dev/null
+++ b/apps/cloud/app/utils/plan-purchase.ts
@@ -0,0 +1,38 @@
+export function planPurchasePath(
+ plan: unknown,
+ interval: unknown,
+): string | null {
+ if (
+ typeof plan !== 'string' ||
+ !/^[a-zA-Z0-9_.-]{1,128}$/.test(plan) ||
+ ![1, 3, '1', '3'].includes(interval as string | number)
+ )
+ return null
+ return `/account/plan?plan=${encodeURIComponent(plan)}&interval=${interval}#plan-${encodeURIComponent(plan)}`
+}
+export function purchaseReturnPath(input: unknown): string | null {
+ if (typeof input !== 'string' || !input.startsWith('/account/plan?'))
+ return null
+ try {
+ const url = new URL(input, 'https://portal.invalid')
+ if (
+ url.origin !== 'https://portal.invalid' ||
+ url.pathname !== '/account/plan'
+ )
+ return null
+ if (
+ [...url.searchParams.keys()].some(
+ (key) => !['plan', 'interval'].includes(key),
+ ) ||
+ url.searchParams.getAll('plan').length !== 1 ||
+ url.searchParams.getAll('interval').length !== 1
+ )
+ return null
+ return planPurchasePath(
+ url.searchParams.get('plan'),
+ url.searchParams.get('interval'),
+ )
+ } catch {
+ return null
+ }
+}
diff --git a/apps/cloud/i18n/locales/en.json b/apps/cloud/i18n/locales/en.json
index 01d8c511..7f2647cb 100644
--- a/apps/cloud/i18n/locales/en.json
+++ b/apps/cloud/i18n/locales/en.json
@@ -64,7 +64,6 @@
"navigation": "Navigation",
"yourWorkspaceAndSiteNavigation": "Your workspace and site navigation.",
"closeNavigation": "Close navigation",
- "cloudPreview": "Cloud preview",
"workspace": "Workspace",
"security": "Security",
"password": "Password",
@@ -186,7 +185,6 @@
"aHomeForTheMomentsYouWantToShare": "A home for the moments you want to share. Bring your photographs together in a gallery that feels entirely yours.",
"createYourAccount": "Create your account",
"exploreSelfHosted": "Explore Self-hosted",
- "selfHostedIsAvailableNowCloudIsInPreview": "Self-hosted is available now. Cloud is in preview.",
"examplePhotographyGallery": "Example photography gallery",
"fieldNotes": "FIELD NOTES",
"aChronoframeGallery": "A CHRONOFRAME GALLERY",
@@ -300,7 +298,7 @@
"thisAlbumUrlIsAlreadyUsedOrReservedBy": "This album URL is already used or reserved by an older link. Choose another slug.",
"mediaServicesNeedDeploymentConfigurationCheckTheSelectedEnvironment": "Media services need deployment configuration. Check the selected environment settings.",
"thisItemChangedRefreshAndTryAgain": "This item changed. Refresh and try again.",
- "thePreviewResourceLimitHasBeenReached": "The preview resource limit has been reached.",
+ "thePreviewResourceLimitHasBeenReached": "The resource limit for your plan has been reached.",
"administratorAccessIsRequired": "Administrator access is required.",
"theOperationFailedCheckTheEnteredValuesAndYour": "The operation failed. Check the entered values and your connection, then retry.",
"storageConnectedAndVerified": "Storage connected and verified.",
@@ -417,7 +415,8 @@
"photograph": "Photograph",
"photographs": "Photographs",
"processing": "Processing",
- "yourPublicAddressAndSharedLinksWillReturn40": "Your public address and shared links will return 404. Your photographs, albums and storage will remain in your workspace. You can publish again later."
+ "yourPublicAddressAndSharedLinksWillReturn40": "Your public address and shared links will return 404. Your photographs, albums and storage will remain in your workspace. You can publish again later.",
+ "chooseHostedOrSelfHosted": "Choose ChronoFrame Cloud for a hosted gallery, or self-host with your own infrastructure."
},
"ui": {
"editNamed": "Edit {title}",
@@ -607,12 +606,10 @@
"quarterly": "Quarterly",
"month": "month",
"quarter": "quarter",
- "paymentsPlanned": "Online payments are not enabled yet. Prices are a preview; eligible activation codes can be redeemed now.",
"defaultTier": "New account default",
"simplePlan": "Your photographs, with room to make it yours.",
"free": "Free",
"notPriced": "Price not configured",
- "noCheckout": "No charge will be made on this page.",
"createAccount": "Create your account",
"redeem": "Redeem code",
"conditions": "Conditional allowances",
@@ -684,7 +681,11 @@
"includedPlan": "Included plan",
"recommended": "Recommended",
"noCharge": "No payment required",
- "monthlyBilling": "Monthly billing"
+ "monthlyBilling": "Monthly billing",
+ "purchaseHelp": "Choose monthly or quarterly billing. Review the payment details before confirming your subscription.",
+ "buyPlan": "Subscribe to {plan}",
+ "purchaseUnavailable": "Currently unavailable",
+ "purchaseUnavailableHelp": "This plan is not currently available for purchase. Please contact support or try again later."
},
"payments": {
"billing": "Subscription billing",
@@ -774,6 +775,9 @@
"revised": "Last revised:",
"loadFailed": "Unable to load this document. Please retry.",
"readBefore": "Please review our terms and privacy policy before continuing."
+ },
+ "support": {
+ "email": "Contact support: {email}"
}
}
}
diff --git a/apps/cloud/i18n/locales/zh-Hans.json b/apps/cloud/i18n/locales/zh-Hans.json
index 86f991d3..c4f51cbe 100644
--- a/apps/cloud/i18n/locales/zh-Hans.json
+++ b/apps/cloud/i18n/locales/zh-Hans.json
@@ -64,7 +64,6 @@
"navigation": "导航",
"yourWorkspaceAndSiteNavigation": "工作区与站点导航。",
"closeNavigation": "关闭导航",
- "cloudPreview": "Cloud 预览版",
"workspace": "工作区",
"security": "安全",
"password": "密码",
@@ -186,7 +185,6 @@
"aHomeForTheMomentsYouWantToShare": "为想要分享的时刻安一个家,将照片汇聚成一座属于自己的图库。",
"createYourAccount": "创建账户",
"exploreSelfHosted": "了解自托管版",
- "selfHostedIsAvailableNowCloudIsInPreview": "自托管版现已可用,Cloud 目前处于预览阶段。",
"examplePhotographyGallery": "摄影图库示例",
"fieldNotes": "影像手记",
"aChronoframeGallery": "CHRONOFRAME 图库",
@@ -300,7 +298,7 @@
"thisAlbumUrlIsAlreadyUsedOrReservedBy": "此相簿地址已被使用或被旧链接保留,请选择其他地址标识。",
"mediaServicesNeedDeploymentConfigurationCheckTheSelectedEnvironment": "媒体服务需要完成部署配置,请检查所选环境的设置。",
"thisItemChangedRefreshAndTryAgain": "此项目已发生更改,请刷新后重试。",
- "thePreviewResourceLimitHasBeenReached": "已达到预览阶段的资源上限。",
+ "thePreviewResourceLimitHasBeenReached": "已达到当前套餐的资源上限。",
"administratorAccessIsRequired": "此操作需要管理员权限。",
"theOperationFailedCheckTheEnteredValuesAndYour": "操作失败,请检查输入内容和网络连接后重试。",
"storageConnectedAndVerified": "存储已连接并通过验证。",
@@ -417,7 +415,8 @@
"photograph": "照片",
"photographs": "照片",
"processing": "处理中",
- "yourPublicAddressAndSharedLinksWillReturn40": "公开地址和分享链接将返回 404。照片、相簿和存储会保留在工作区中,你可以稍后重新发布。"
+ "yourPublicAddressAndSharedLinksWillReturn40": "公开地址和分享链接将返回 404。照片、相簿和存储会保留在工作区中,你可以稍后重新发布。",
+ "chooseHostedOrSelfHosted": "选择 ChronoFrame Cloud 托管图库,或在自己的基础设施上自部署。"
},
"ui": {
"editNamed": "编辑 {title}",
@@ -607,12 +606,10 @@
"quarterly": "按季",
"month": "月",
"quarter": "季",
- "paymentsPlanned": "尚未启用在线支付,价格仅供预览;持有有效激活码的用户现在即可兑换。",
"defaultTier": "新账号默认层级",
"simplePlan": "让照片成为主角,为你的故事留出空间。",
"free": "免费",
"notPriced": "价格尚未配置",
- "noCheckout": "此页面不会发起扣款。",
"createAccount": "创建账号",
"redeem": "兑换激活码",
"conditions": "条件权益",
@@ -684,7 +681,11 @@
"includedPlan": "默认套餐",
"recommended": "推荐",
"noCharge": "无需付款",
- "monthlyBilling": "按月计费"
+ "monthlyBilling": "按月计费",
+ "purchaseHelp": "支持按月或按季订阅,请在确认订阅前核对付款详情。",
+ "buyPlan": "购买 {plan}",
+ "purchaseUnavailable": "暂不可购买",
+ "purchaseUnavailableHelp": "该套餐目前暂不可购买,请联系客服或稍后重试。"
},
"payments": {
"billing": "订阅账单",
@@ -774,6 +775,9 @@
"revised": "最近修订:",
"loadFailed": "暂时无法加载文档,请重试。",
"readBefore": "继续前,请阅读用户协议与隐私政策。"
+ },
+ "support": {
+ "email": "联系客服:{email}"
}
}
}
diff --git a/tests/plan-purchase.test.ts b/tests/plan-purchase.test.ts
new file mode 100644
index 00000000..722f0870
--- /dev/null
+++ b/tests/plan-purchase.test.ts
@@ -0,0 +1,58 @@
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import {
+ planPurchasePath,
+ purchaseReturnPath,
+} from '../apps/cloud/app/utils/plan-purchase.ts'
+
+test('Purchase links preserve plan and billing interval without starting a checkout', () => {
+ assert.equal(
+ planPurchasePath('creator', 1),
+ '/account/plan?plan=creator&interval=1#plan-creator',
+ )
+ assert.equal(
+ planPurchasePath('studio', '3'),
+ '/account/plan?plan=studio&interval=3#plan-studio',
+ )
+ assert.equal(
+ purchaseReturnPath('/account/plan?plan=studio&interval=3'),
+ planPurchasePath('studio', 3),
+ )
+ assert.equal(
+ purchaseReturnPath('/account/plan?interval=3&plan=studio#other'),
+ planPurchasePath('studio', 3),
+ )
+})
+
+test('Authentication returns accept only canonical plan-selection destinations', () => {
+ for (const value of [
+ undefined,
+ null,
+ [],
+ ['x'],
+ 'https://evil.test/account/plan?plan=studio&interval=3',
+ '//evil.test/account/plan?plan=studio&interval=3',
+ '/workspace',
+ '/account/plan/../?plan=studio&interval=3',
+ '/account/plan?plan=studio&interval=3&next=https://evil.test',
+ '/account/plan?plan=studio&plan=creator&interval=3',
+ '/account/plan?plan=studio&interval=3&interval=1',
+ '/account/plan?plan=%2F%2Fevil.test&interval=3',
+ '/account/plan?plan=studio&interval=12',
+ ]) {
+ assert.equal(purchaseReturnPath(value), null, String(value))
+ }
+ for (const period of [
+ undefined,
+ null,
+ [],
+ ['3'],
+ { toString: () => '3' },
+ 0,
+ 12,
+ 'quarterly',
+ ])
+ assert.equal(planPurchasePath('studio', period), null)
+ for (const plan of ['', 'a/b', 'a b', 'x'.repeat(129), ['studio'], null])
+ assert.equal(planPurchasePath(plan, 1), null)
+})