@zaaxch/grasp-vue 0.0.0-stage → 0.2.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/README.md +11 -2
- package/dist/client.d.ts +95 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +222 -0
- package/dist/client.js.map +1 -0
- package/dist/components.d.ts +64 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +369 -0
- package/dist/components.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/router.d.ts +19 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +132 -0
- package/dist/router.js.map +1 -0
- package/dist/stores.d.ts +605 -0
- package/dist/stores.d.ts.map +1 -0
- package/dist/stores.js +355 -0
- package/dist/stores.js.map +1 -0
- package/dist/theme.d.ts +16 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +26 -0
- package/dist/theme.js.map +1 -0
- package/package.json +71 -3
package/dist/router.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { getPlanRank } from '@zaaxch/grasp-core';
|
|
2
|
+
import { createRouter, createWebHistory, } from 'vue-router';
|
|
3
|
+
import { GraspAccountSettings, GraspAuthFlow, GraspBillingPanel, GraspShellLayout, } from './components.js';
|
|
4
|
+
import { useAuthStore } from './stores.js';
|
|
5
|
+
export function defineFeatureRoutes(routes) {
|
|
6
|
+
return Object.freeze([...routes]);
|
|
7
|
+
}
|
|
8
|
+
function resolveSafeRedirect(candidate, fallback) {
|
|
9
|
+
if (typeof candidate === 'string' && candidate.startsWith('/') && !candidate.startsWith('//')) {
|
|
10
|
+
return candidate;
|
|
11
|
+
}
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds the standardized Grasp Vue Router with built-in `/`, `/login`, `/settings`, `/billing`
|
|
16
|
+
* routes plus support for public, standalone, and auth-disabled application modes.
|
|
17
|
+
*/
|
|
18
|
+
export function createGraspRouter(options) {
|
|
19
|
+
const authenticatedHome = options.authenticatedHome ?? '/settings';
|
|
20
|
+
const layoutComponent = options.layoutComponent ?? GraspShellLayout;
|
|
21
|
+
const loginComponent = options.loginComponent ?? GraspAuthFlow;
|
|
22
|
+
const authEnabled = options.config.auth.enabled !== false;
|
|
23
|
+
const standaloneRoutes = options.featureRoutes
|
|
24
|
+
.filter((route) => route.meta?.['layout'] === 'standalone')
|
|
25
|
+
.map((route) => ({
|
|
26
|
+
...route,
|
|
27
|
+
meta: {
|
|
28
|
+
...(route.meta ?? {}),
|
|
29
|
+
auth: !authEnabled ? 'public' : (route.meta?.['auth'] ?? 'public'),
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
const shellFeatureRoutes = options.featureRoutes
|
|
33
|
+
.filter((route) => route.meta?.['layout'] !== 'standalone')
|
|
34
|
+
.map((route) => ({
|
|
35
|
+
...route,
|
|
36
|
+
meta: {
|
|
37
|
+
...(route.meta ?? {}),
|
|
38
|
+
auth: !authEnabled ? 'public' : (route.meta?.['auth'] ?? 'required'),
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
const shellChildren = [];
|
|
42
|
+
if (authEnabled) {
|
|
43
|
+
shellChildren.push({
|
|
44
|
+
path: '/settings',
|
|
45
|
+
name: 'grasp-settings',
|
|
46
|
+
component: GraspAccountSettings,
|
|
47
|
+
meta: { auth: 'required' },
|
|
48
|
+
}, {
|
|
49
|
+
path: '/billing',
|
|
50
|
+
name: 'grasp-billing',
|
|
51
|
+
component: GraspBillingPanel,
|
|
52
|
+
meta: { auth: 'required' },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (options.config.billing.enabled) {
|
|
56
|
+
shellChildren.push({
|
|
57
|
+
path: '/billing',
|
|
58
|
+
name: 'grasp-billing',
|
|
59
|
+
component: GraspBillingPanel,
|
|
60
|
+
meta: { auth: 'public' },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
shellChildren.push(...shellFeatureRoutes);
|
|
64
|
+
const routes = [
|
|
65
|
+
{
|
|
66
|
+
path: '/',
|
|
67
|
+
name: 'grasp-landing',
|
|
68
|
+
component: options.landingComponent,
|
|
69
|
+
},
|
|
70
|
+
...(authEnabled
|
|
71
|
+
? [
|
|
72
|
+
{
|
|
73
|
+
path: '/login',
|
|
74
|
+
name: 'grasp-login',
|
|
75
|
+
component: loginComponent,
|
|
76
|
+
meta: { guestOnly: true },
|
|
77
|
+
},
|
|
78
|
+
]
|
|
79
|
+
: []),
|
|
80
|
+
...standaloneRoutes,
|
|
81
|
+
...(shellChildren.length > 0
|
|
82
|
+
? [
|
|
83
|
+
{
|
|
84
|
+
path: '/_app',
|
|
85
|
+
component: layoutComponent,
|
|
86
|
+
children: shellChildren,
|
|
87
|
+
},
|
|
88
|
+
]
|
|
89
|
+
: []),
|
|
90
|
+
];
|
|
91
|
+
const router = createRouter({
|
|
92
|
+
history: options.history ?? createWebHistory(),
|
|
93
|
+
routes,
|
|
94
|
+
});
|
|
95
|
+
router.beforeEach(async (to) => {
|
|
96
|
+
if (!authEnabled) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const auth = useAuthStore();
|
|
100
|
+
if (!auth.ready) {
|
|
101
|
+
await auth.bootstrap();
|
|
102
|
+
}
|
|
103
|
+
const leafMeta = to.matched[to.matched.length - 1]?.meta;
|
|
104
|
+
const requiresAuth = leafMeta?.['auth'] === 'required';
|
|
105
|
+
const guestOnly = leafMeta?.['guestOnly'] === true;
|
|
106
|
+
if (requiresAuth && !auth.isAuthenticated) {
|
|
107
|
+
return {
|
|
108
|
+
path: '/login',
|
|
109
|
+
query: { redirect: to.fullPath },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (guestOnly && auth.isAuthenticated) {
|
|
113
|
+
return resolveSafeRedirect(to.query['redirect'], authenticatedHome);
|
|
114
|
+
}
|
|
115
|
+
const requiredPlanRecord = to.matched.find((record) => typeof record.meta['minPlan'] === 'string');
|
|
116
|
+
if (requiredPlanRecord) {
|
|
117
|
+
const minPlan = requiredPlanRecord.meta['minPlan'];
|
|
118
|
+
const currentPlan = auth.entitlement?.planId ?? 'free';
|
|
119
|
+
const currentRank = getPlanRank(options.config.billing, currentPlan);
|
|
120
|
+
const requiredRank = getPlanRank(options.config.billing, minPlan);
|
|
121
|
+
if (requiredRank >= 0 && currentRank < requiredRank) {
|
|
122
|
+
return {
|
|
123
|
+
path: '/billing',
|
|
124
|
+
query: { upgrade: minPlan },
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
});
|
|
130
|
+
return router;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4B,MAAM,oBAAoB,CAAA;AAE1E,OAAO,EACL,YAAY,EACZ,gBAAgB,GAIjB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAY1C,MAAM,UAAU,mBAAmB,CAAC,MAAiC;IACnE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAA;AACnC,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAkB,EAAE,QAAgB;IAC/D,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9F,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC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