@frigear-nu/subscriptions 0.0.7 → 0.0.9
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/module.d.mts +65 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +61 -29
- package/dist/runtime/app/components/SubscriptionPlans.d.vue.ts +31 -27
- package/dist/runtime/app/components/SubscriptionPlans.vue +203 -105
- package/dist/runtime/app/components/SubscriptionPlans.vue.d.ts +31 -27
- package/dist/runtime/app/components/SubscriptionStatus.d.vue.ts +1 -1
- package/dist/runtime/app/components/SubscriptionStatus.vue +45 -24
- package/dist/runtime/app/components/SubscriptionStatus.vue.d.ts +1 -1
- package/dist/runtime/app/components/Users/Admin/Membership.d.vue.ts +14 -0
- package/dist/runtime/app/components/Users/Admin/Membership.vue +192 -0
- package/dist/runtime/app/components/Users/Admin/Membership.vue.d.ts +14 -0
- package/dist/runtime/app/composables/usePlans.d.ts +11 -0
- package/dist/runtime/app/composables/usePlans.js +9 -1
- package/dist/runtime/app/composables/useSubscription.d.ts +1 -0
- package/dist/runtime/app/composables/useSubscription.js +17 -3
- package/dist/runtime/app/pages/cancel.d.vue.ts +1 -1
- package/dist/runtime/app/pages/cancel.vue.d.ts +1 -1
- package/dist/runtime/app/pages/membership.d.vue.ts +1 -1
- package/dist/runtime/app/pages/membership.vue +18 -1
- package/dist/runtime/app/pages/membership.vue.d.ts +1 -1
- package/dist/runtime/app/pages/success.d.vue.ts +1 -1
- package/dist/runtime/app/pages/success.vue +9 -3
- package/dist/runtime/app/pages/success.vue.d.ts +1 -1
- package/dist/runtime/app/plugins/warm-plans.client.d.ts +6 -0
- package/dist/runtime/app/plugins/warm-plans.client.js +12 -0
- package/dist/runtime/app/tabs/Membership.d.vue.ts +14 -0
- package/dist/runtime/app/tabs/Membership.vue +53 -0
- package/dist/runtime/app/tabs/Membership.vue.d.ts +14 -0
- package/dist/runtime/app/widgets/AdminCurrentSubscription.d.vue.ts +11 -0
- package/dist/runtime/app/widgets/AdminCurrentSubscription.vue +23 -0
- package/dist/runtime/app/widgets/AdminCurrentSubscription.vue.d.ts +11 -0
- package/dist/runtime/i18n/lang/da.json +61 -3
- package/dist/runtime/i18n/lang/en.json +61 -3
- package/dist/runtime/server/db/schema.sqlite.d.ts +19 -0
- package/dist/runtime/server/db/schema.sqlite.js +2 -0
- package/dist/runtime/server/mcp/tools/my-subscriptions.d.ts +2 -0
- package/dist/runtime/server/mcp/tools/my-subscriptions.js +9 -0
- package/dist/runtime/server/routes/admin/payment-link.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/payment-link.post.js +46 -0
- package/dist/runtime/server/routes/admin/subscription.delete.d.ts +2 -0
- package/dist/runtime/server/routes/admin/subscription.delete.js +14 -0
- package/dist/runtime/server/routes/admin/subscription.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/subscription.get.js +17 -0
- package/dist/runtime/server/routes/admin/subscription.post.d.ts +2 -0
- package/dist/runtime/server/routes/admin/subscription.post.js +44 -0
- package/dist/runtime/server/routes/admin/subscriptions.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/subscriptions.get.js +4 -0
- package/dist/runtime/server/routes/subscriptions/checkout.post.js +16 -30
- package/dist/runtime/server/routes/subscriptions/me.get.js +2 -20
- package/dist/runtime/server/routes/subscriptions/portal.post.js +2 -2
- package/dist/runtime/server/stripe/invoice-events.d.ts +2 -0
- package/dist/runtime/server/stripe/invoice-events.js +42 -0
- package/dist/runtime/server/utils/admin-membership.d.ts +5 -0
- package/dist/runtime/server/utils/admin-membership.js +7 -0
- package/dist/runtime/server/utils/checkout.d.ts +15 -0
- package/dist/runtime/server/utils/checkout.js +22 -0
- package/dist/runtime/server/utils/plans.js +20 -1
- package/dist/runtime/server/utils/subscriptions.d.ts +3 -0
- package/dist/runtime/server/utils/subscriptions.js +22 -3
- package/dist/runtime/utils/index.d.ts +1 -1
- package/dist/runtime/utils/index.js +1 -1
- package/dist/runtime/utils/plans.d.ts +15 -6
- package/dist/runtime/utils/plans.js +16 -11
- package/dist/types.d.mts +1 -1
- package/package.json +17 -5
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import type { PlanPriceRef, ResolvedPlan } from '../../types.js';
|
|
1
|
+
import type { PlanDisabledRange, PlanPriceRef, ResolvedPlan } from '../../types.js';
|
|
2
2
|
export declare const DEFAULT_ENTITLED_STATUSES: string[];
|
|
3
3
|
/** Statuses that count as "holds a live subscription" when deciding between a new checkout and a plan change. */
|
|
4
|
+
/**
|
|
5
|
+
* Whether a stored row currently entitles its user: an entitled status, not ended, and (for manual grants,
|
|
6
|
+
* which have no Stripe lifecycle to end them) not past its optional end date.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isEntitledRow(row: {
|
|
9
|
+
status: string;
|
|
10
|
+
endedAt: Date | null;
|
|
11
|
+
source?: string | null;
|
|
12
|
+
currentPeriodEnd: Date | null;
|
|
13
|
+
}, statuses?: string[], now?: number): boolean;
|
|
4
14
|
export declare const LIVE_STATUSES: string[];
|
|
5
15
|
type PlanConfigLike = Record<string, {
|
|
6
16
|
prices: PlanPriceRef[];
|
|
@@ -19,14 +29,13 @@ export type ChangeKind = 'upgrade' | 'downgrade';
|
|
|
19
29
|
* plan that isn't configured counts as the lowest rank.
|
|
20
30
|
*/
|
|
21
31
|
export declare function decideChangeKind(currentRank: number | null | undefined, targetRank: number): ChangeKind;
|
|
22
|
-
/**
|
|
23
|
-
* Validates a redirect URL supplied by a client: it must be a relative path (`/x`) or an absolute URL on
|
|
24
|
-
* `origin`. Returns an absolute URL on that origin, or `null` when it is unsafe.
|
|
25
|
-
*/
|
|
26
|
-
export declare function resolveSameOriginUrl(input: string, origin: string): string | null;
|
|
27
32
|
/** Finds a price (and its plan) in already resolved plans by price id. */
|
|
28
33
|
export declare function findPrice(plans: ResolvedPlan[], priceId: string): {
|
|
29
34
|
plan: ResolvedPlan;
|
|
30
35
|
price: import(".").PlanPrice;
|
|
31
36
|
} | null;
|
|
37
|
+
/** Parses a range date; `{fullYear}` becomes the current year. Invalid dates yield `null`. */
|
|
38
|
+
export declare function parseRangeDate(text: string, now?: Date): Date | null;
|
|
39
|
+
/** Whether `now` falls (inclusively) within any of the ranges. Unparseable ranges are ignored. */
|
|
40
|
+
export declare function isWithinDisabledRanges(ranges: PlanDisabledRange[] | undefined, now?: Date): boolean;
|
|
32
41
|
export {};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export const DEFAULT_ENTITLED_STATUSES = ["active", "trialing"];
|
|
2
|
+
export function isEntitledRow(row, statuses = DEFAULT_ENTITLED_STATUSES, now = Date.now()) {
|
|
3
|
+
if (!statuses.includes(row.status) || row.endedAt) return false;
|
|
4
|
+
if (row.source === "manual" && row.currentPeriodEnd && row.currentPeriodEnd.getTime() <= now) return false;
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
2
7
|
export const LIVE_STATUSES = ["active", "trialing", "past_due"];
|
|
3
8
|
export function resolvePlanKey(plans, price) {
|
|
4
9
|
for (const [key, plan] of Object.entries(plans)) {
|
|
@@ -13,17 +18,6 @@ export function decideChangeKind(currentRank, targetRank) {
|
|
|
13
18
|
if (currentRank === null || currentRank === void 0) return "upgrade";
|
|
14
19
|
return targetRank > currentRank ? "upgrade" : "downgrade";
|
|
15
20
|
}
|
|
16
|
-
export function resolveSameOriginUrl(input, origin) {
|
|
17
|
-
if (input.startsWith("/")) {
|
|
18
|
-
if (input.startsWith("//") || input.startsWith("/\\")) return null;
|
|
19
|
-
return `${origin}${input}`;
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
return new URL(input).origin === new URL(origin).origin ? input : null;
|
|
23
|
-
} catch {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
21
|
export function findPrice(plans, priceId) {
|
|
28
22
|
for (const plan of plans) {
|
|
29
23
|
const price = plan.prices.find((item) => item.id === priceId);
|
|
@@ -31,3 +25,14 @@ export function findPrice(plans, priceId) {
|
|
|
31
25
|
}
|
|
32
26
|
return null;
|
|
33
27
|
}
|
|
28
|
+
export function parseRangeDate(text, now = /* @__PURE__ */ new Date()) {
|
|
29
|
+
const date = new Date(text.replaceAll("{fullYear}", String(now.getFullYear())));
|
|
30
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
31
|
+
}
|
|
32
|
+
export function isWithinDisabledRanges(ranges, now = /* @__PURE__ */ new Date()) {
|
|
33
|
+
return (ranges ?? []).some((range) => {
|
|
34
|
+
const from = parseRangeDate(range.from, now);
|
|
35
|
+
const to = parseRangeDate(range.to, now);
|
|
36
|
+
return !!from && !!to && now >= from && now <= to;
|
|
37
|
+
});
|
|
38
|
+
}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from './module.mjs'
|
|
2
2
|
|
|
3
|
-
export { type CheckoutBeforeContext, type CheckoutBody, type CheckoutResponse, type MeResponse, type ModuleOptions, type PlanConfig, type PlanPrice, type PlanPriceRef, type PlansFilterContext, type PlansResponse, type PortalBody, type PublicModuleOptions, type PublicPlan, type ResolvedPlan, type SubscriptionDto, type SubscriptionsRuntimeConfig } from './module.mjs'
|
|
3
|
+
export { type AdminMembershipResponse, type AdminPaymentLinkResponse, type CheckoutBeforeContext, type CheckoutBody, type CheckoutResponse, type InvoicePaymentEvent, type MeResponse, type ModuleOptions, type PlanAvailability, type PlanConfig, type PlanDisabledRange, type PlanPrice, type PlanPriceRef, type PlansFilterContext, type PlansResponse, type PortalBody, type PublicModuleOptions, type PublicPlan, type ResolvedPlan, type SubscriptionDto, type SubscriptionsRuntimeConfig } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/subscriptions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Recurring subscriptions (plans, checkout, upgrade/downgrade, billing portal and entitlements) for the frigear ecosystem, built on @frigear-nu/stripe.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/subscriptions",
|
|
6
6
|
"repository": {
|
|
@@ -30,10 +30,12 @@
|
|
|
30
30
|
"playground"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@frigear-nu/
|
|
34
|
-
"@frigear-nu/
|
|
35
|
-
"@frigear-nu/
|
|
36
|
-
"@frigear-nu/
|
|
33
|
+
"@frigear-nu/auth": "0.0.4",
|
|
34
|
+
"@frigear-nu/mcp": "0.0.4",
|
|
35
|
+
"@frigear-nu/module-kit": "1.0.0",
|
|
36
|
+
"@frigear-nu/stripe": "0.0.9",
|
|
37
|
+
"@frigear-nu/ui": "0.0.8",
|
|
38
|
+
"@frigear-nu/users": "1.0.10",
|
|
37
39
|
"@libsql/client": "^0.18.0",
|
|
38
40
|
"@nuxt/kit": "^4.6.0",
|
|
39
41
|
"@vueuse/core": "^15.0.0",
|
|
@@ -45,15 +47,25 @@
|
|
|
45
47
|
"zod": "^4.6.5"
|
|
46
48
|
},
|
|
47
49
|
"peerDependencies": {
|
|
50
|
+
"@frigear-nu/menu": "0.0.10",
|
|
51
|
+
"@frigear-nu/widget": "0.0.3",
|
|
48
52
|
"@nuxt/ui": "^4.10.0",
|
|
49
53
|
"@nuxthub/core": "^0.10.8"
|
|
50
54
|
},
|
|
51
55
|
"peerDependenciesMeta": {
|
|
56
|
+
"@frigear-nu/menu": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@frigear-nu/widget": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
52
62
|
"@nuxt/ui": {
|
|
53
63
|
"optional": true
|
|
54
64
|
}
|
|
55
65
|
},
|
|
56
66
|
"devDependencies": {
|
|
67
|
+
"@frigear-nu/menu": "0.0.10",
|
|
68
|
+
"@frigear-nu/widget": "0.0.3",
|
|
57
69
|
"@nuxt/devtools": "^3.4.2",
|
|
58
70
|
"@nuxt/eslint-config": "^1.17.0",
|
|
59
71
|
"@nuxt/module-builder": "^1.0.3",
|