@panomc/theme-core 1.0.0-dev.39
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/bin/bundle-internal-libs.js +104 -0
- package/bin/check.js +253 -0
- package/bin/generate-licenses.js +125 -0
- package/bin/generate-runtime-shims.js +180 -0
- package/bin/license/file-fingerprint.js +74 -0
- package/bin/license/finalize-fingerprint.js +72 -0
- package/bin/license/generate-license-constants.js +335 -0
- package/bin/new.js +281 -0
- package/bin/package-zip.js +57 -0
- package/bin/sync.js +326 -0
- package/bin/templates/app.html +59 -0
- package/bin/theme-core.js +103 -0
- package/package.json +77 -0
- package/src/index.js +15 -0
- package/src/kit/hooks-client.js +128 -0
- package/src/kit/hooks-server.js +319 -0
- package/src/kit/license-runtime.js +373 -0
- package/src/kit/resolve.js +71 -0
- package/src/kit/specifiers.js +62 -0
- package/src/kit/svelte-config.js +74 -0
- package/src/kit/vite-config.js +249 -0
- package/src/lib/NotificationManager.js +1 -0
- package/src/lib/PluginAPI.js +368 -0
- package/src/lib/PluginManager.js +1 -0
- package/src/lib/Store.js +43 -0
- package/src/lib/api.util.js +5 -0
- package/src/lib/auth.util.js +77 -0
- package/src/lib/components/App.svelte +10 -0
- package/src/lib/components/Breadcrumb.svelte +88 -0
- package/src/lib/components/CardHeader.svelte +42 -0
- package/src/lib/components/Date.svelte +34 -0
- package/src/lib/components/DefaultToast.svelte +11 -0
- package/src/lib/components/ErrorAlert.svelte +16 -0
- package/src/lib/components/Footer.svelte +223 -0
- package/src/lib/components/Header.svelte +122 -0
- package/src/lib/components/Hook.svelte +71 -0
- package/src/lib/components/LinkCodeInput.svelte +129 -0
- package/src/lib/components/LoginFormBody.svelte +90 -0
- package/src/lib/components/Main.svelte +76 -0
- package/src/lib/components/Navbar.svelte +462 -0
- package/src/lib/components/NoContent.svelte +14 -0
- package/src/lib/components/NotificationContainer.svelte +304 -0
- package/src/lib/components/OnlineAdmins.svelte +64 -0
- package/src/lib/components/PageActions.svelte +39 -0
- package/src/lib/components/PageTitle.svelte +36 -0
- package/src/lib/components/Pagination.svelte +65 -0
- package/src/lib/components/PlayerHead.svelte +58 -0
- package/src/lib/components/PlayerPermissionBadge.svelte +19 -0
- package/src/lib/components/PlayerStatusBadge.svelte +63 -0
- package/src/lib/components/Post.svelte +240 -0
- package/src/lib/components/Posts.svelte +19 -0
- package/src/lib/components/RegisterForm.svelte +125 -0
- package/src/lib/components/Sidebar.svelte +12 -0
- package/src/lib/components/SuccessAlert.svelte +14 -0
- package/src/lib/components/TicketRow.svelte +61 -0
- package/src/lib/components/TicketStatus.svelte +24 -0
- package/src/lib/components/Tickets.svelte +43 -0
- package/src/lib/components/Toast.svelte +13 -0
- package/src/lib/components/ToastContainer.svelte +83 -0
- package/src/lib/components/ViewComponent.svelte +8 -0
- package/src/lib/components/modals/CloseTicketConfirmModal.svelte +121 -0
- package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +93 -0
- package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +61 -0
- package/src/lib/components/sidebars/HomeSidebar.svelte +333 -0
- package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +124 -0
- package/src/lib/components/sidebars/ProfileSidebar.svelte +149 -0
- package/src/lib/components/sidebars/SupportSidebar.svelte +54 -0
- package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +84 -0
- package/src/lib/csrf.js +5 -0
- package/src/lib/init.libs.js +2 -0
- package/src/lib/language.util.js +154 -0
- package/src/lib/layouts/AppLayout.svelte +59 -0
- package/src/lib/layouts/AuthLayout.svelte +29 -0
- package/src/lib/layouts/MainLayout.svelte +60 -0
- package/src/lib/layouts/ProfileLayout.svelte +29 -0
- package/src/lib/layouts/ThemeSettingsLayout.svelte +37 -0
- package/src/lib/layouts/TicketsLayout.svelte +31 -0
- package/src/lib/loginInput.util.js +4 -0
- package/src/lib/orderNavLinks.util.js +58 -0
- package/src/lib/pages/ActivateEmailPage.svelte +48 -0
- package/src/lib/pages/ConfirmNewEmailPage.svelte +48 -0
- package/src/lib/pages/ErrorPage.svelte +41 -0
- package/src/lib/pages/HomePage.svelte +35 -0
- package/src/lib/pages/LoginPage.svelte +448 -0
- package/src/lib/pages/NotificationsPage.svelte +70 -0
- package/src/lib/pages/PlayerDetailPage.svelte +29 -0
- package/src/lib/pages/PostDetailPage.svelte +36 -0
- package/src/lib/pages/PreviewPostPage.svelte +38 -0
- package/src/lib/pages/RegisterPage.svelte +144 -0
- package/src/lib/pages/RenewPasswordPage.svelte +49 -0
- package/src/lib/pages/ResetPasswordPage.svelte +55 -0
- package/src/lib/pages/RulesPage.svelte +52 -0
- package/src/lib/pages/SupportPage.svelte +36 -0
- package/src/lib/pages/ThemeSettingsPage.svelte +551 -0
- package/src/lib/pages/profile/ProfilePage.svelte +32 -0
- package/src/lib/pages/profile/SettingsPage.svelte +163 -0
- package/src/lib/pages/profile/TicketsPage.svelte +54 -0
- package/src/lib/pages/ticket/CreateTicketPage.svelte +48 -0
- package/src/lib/pages/ticket/TicketDetailPage.svelte +59 -0
- package/src/lib/services/auth.js +85 -0
- package/src/lib/services/posts.js +152 -0
- package/src/lib/services/profile.js +37 -0
- package/src/lib/services/theme-setting.js +22 -0
- package/src/lib/services/tickets.js +95 -0
- package/src/lib/siteRealtime.js +244 -0
- package/src/lib/string.util.js +27 -0
- package/src/lib/tooltip.util.js +5 -0
- package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +321 -0
- package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +10 -0
- package/src/lib/ui-logics/layout-logics/MainLayoutLogics.js +19 -0
- package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +10 -0
- package/src/lib/ui-logics/layout-logics/ThemeSettingsLayoutLogics.js +215 -0
- package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +10 -0
- package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +45 -0
- package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +42 -0
- package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +83 -0
- package/src/lib/ui-logics/page-logics/HomePageLogics.js +65 -0
- package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +264 -0
- package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +40 -0
- package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +58 -0
- package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +53 -0
- package/src/lib/ui-logics/page-logics/ProfilePageLogics.js +44 -0
- package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +44 -0
- package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +53 -0
- package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +230 -0
- package/src/lib/ui-logics/page-logics/SupportPageLogics.js +60 -0
- package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +160 -0
- package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +132 -0
- package/src/lib/variables.js +1 -0
- package/src/lib/views/ActivateEmailView.svelte +71 -0
- package/src/lib/views/AppLayoutView.svelte +31 -0
- package/src/lib/views/AuthLayoutView.svelte +23 -0
- package/src/lib/views/ConfirmNewEmailView.svelte +71 -0
- package/src/lib/views/CreateTicketView.svelte +73 -0
- package/src/lib/views/ErrorView.svelte +38 -0
- package/src/lib/views/HomeView.svelte +72 -0
- package/src/lib/views/LoginView.svelte +372 -0
- package/src/lib/views/MainLayoutView.svelte +86 -0
- package/src/lib/views/NotificationsView.svelte +129 -0
- package/src/lib/views/PlayerDetailView.svelte +31 -0
- package/src/lib/views/PostDetailView.svelte +199 -0
- package/src/lib/views/PreviewPostView.svelte +151 -0
- package/src/lib/views/ProfileLayoutView.svelte +16 -0
- package/src/lib/views/ProfileView.svelte +68 -0
- package/src/lib/views/RegisterView.svelte +113 -0
- package/src/lib/views/RenewPasswordView.svelte +98 -0
- package/src/lib/views/ResetPasswordView.svelte +88 -0
- package/src/lib/views/RulesView.svelte +26 -0
- package/src/lib/views/SettingsView.svelte +471 -0
- package/src/lib/views/SupportView.svelte +79 -0
- package/src/lib/views/ThemeSettingsLayoutView.svelte +19 -0
- package/src/lib/views/ThemeSettingsView.svelte +1508 -0
- package/src/lib/views/TicketDetailView.svelte +185 -0
- package/src/lib/views/TicketsLayoutView.svelte +21 -0
- package/src/lib/views/TicketsView.svelte +87 -0
- package/src/plugin-engine/engine.js +484 -0
- package/src/registry/index.js +86 -0
- package/src/routes/RootLayout.svelte +21 -0
- package/src/routes/plugin-ui/Layout.svelte +291 -0
- package/src/routes/plugin-ui/Page.svelte +117 -0
- package/src/routes/plugin-ui/layout.js +8 -0
- package/src/routes/plugin-ui/page.js +8 -0
- package/src/routes/plugins-client-file.js +76 -0
- package/src/routes/root-layout-load.js +15 -0
- package/src/routes/theme-api-languages.js +52 -0
- package/src/routes/theme-api-licenses.js +28 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for the theme's server hooks. A theme's src/hooks.server.js becomes:
|
|
3
|
+
*
|
|
4
|
+
* import { createThemeHooks } from "$pano/kit/hooks-server.js";
|
|
5
|
+
* import { internalLibsHash } from "$lib/internalLibs.js";
|
|
6
|
+
* import { runtimeShimsHash } from "$lib/runtimeShims.js";
|
|
7
|
+
* import * as licenseConstants from "$lib/server/license-constants.generated.js";
|
|
8
|
+
* export const { handle, handleError, handleFetch } = createThemeHooks({
|
|
9
|
+
* internalLibsHash,
|
|
10
|
+
* runtimeShimsHash,
|
|
11
|
+
* licenseConstants,
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* The generated per-theme artifacts (internalLibsHash, runtimeShimsHash, license
|
|
15
|
+
* constants) are parameters because they are produced inside the theme repo at
|
|
16
|
+
* build time; everything else lives here so a hooks fix ships to every theme as
|
|
17
|
+
* a core version bump instead of a hand-applied patch.
|
|
18
|
+
*/
|
|
19
|
+
import {
|
|
20
|
+
API_URL,
|
|
21
|
+
COOKIE_PREFIX,
|
|
22
|
+
CSRF_TOKEN_COOKIE_NAME,
|
|
23
|
+
JWT_COOKIE_NAME,
|
|
24
|
+
updateApiUrl,
|
|
25
|
+
updatePanoWebsiteUrl,
|
|
26
|
+
} from "../lib/variables.js";
|
|
27
|
+
import { dev } from "$app/environment";
|
|
28
|
+
import { getCredentialsServerSide } from "../lib/services/auth.js";
|
|
29
|
+
import { createLicenseRuntime } from "./license-runtime.js";
|
|
30
|
+
import { RUNTIME_SPECIFIERS } from "./specifiers.js";
|
|
31
|
+
|
|
32
|
+
function stripModulePreload(linkHeader) {
|
|
33
|
+
const parts = linkHeader
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((p) => p.trim())
|
|
36
|
+
.filter(Boolean);
|
|
37
|
+
|
|
38
|
+
const kept = parts.filter((p) => !/;\s*rel="?modulepreload"?/i.test(p));
|
|
39
|
+
|
|
40
|
+
return kept.length ? kept.join(", ") : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getCookieWithHttpFallback(cookies, baseName) {
|
|
44
|
+
return cookies.get(baseName) ?? cookies.get(`${baseName}_http`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** In production, skip logging common client/bot noise (wrong method, stray POST to non-action routes). */
|
|
48
|
+
function shouldSuppressServerErrorLog(error) {
|
|
49
|
+
if (process.env.NODE_ENV !== "production") return false;
|
|
50
|
+
if (error?.status === 405) return true;
|
|
51
|
+
const msg = String(error?.message ?? "");
|
|
52
|
+
if (msg.includes("No form actions exist")) return true;
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function escapeHtml(s) {
|
|
57
|
+
return String(s).replace(
|
|
58
|
+
/[&<>"']/g,
|
|
59
|
+
(c) =>
|
|
60
|
+
({
|
|
61
|
+
"&": "&",
|
|
62
|
+
"<": "<",
|
|
63
|
+
">": ">",
|
|
64
|
+
'"': """,
|
|
65
|
+
"'": "'",
|
|
66
|
+
})[c],
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function renderLicenseBlocked(reason, message) {
|
|
71
|
+
// Minimal HTML page; deliberately self-contained so the broken theme can't accidentally
|
|
72
|
+
// serve its own (now-unlicensed) UI. The Pano host's renewal sweep will fall back to the
|
|
73
|
+
// bundled vanilla theme on next sweep, but until then we surface the cause.
|
|
74
|
+
const body =
|
|
75
|
+
'<!doctype html><html lang="en"><head>' +
|
|
76
|
+
'<meta charset="utf-8"><title>License required</title>' +
|
|
77
|
+
'<meta name="robots" content="noindex">' +
|
|
78
|
+
"<style>html,body{height:100%;margin:0;font-family:system-ui,sans-serif;color:#222;background:#f7f7f9}" +
|
|
79
|
+
"main{display:flex;align-items:center;justify-content:center;height:100%;padding:2rem;text-align:center}" +
|
|
80
|
+
"section{max-width:540px}h1{margin:.2em 0 .6em}code{background:#eee;padding:.1em .3em;border-radius:.2em}" +
|
|
81
|
+
".reason{color:#a00;font-weight:600}</style></head><body><main><section>" +
|
|
82
|
+
"<h1>This premium theme is not licensed on this server.</h1>" +
|
|
83
|
+
"<p>The Pano host did not provide a valid license token.</p>" +
|
|
84
|
+
`<p>Reason: <span class="reason">${escapeHtml(reason)}</span>${message ? ` — ${escapeHtml(message)}` : ""}</p>` +
|
|
85
|
+
"<p>Open the Pano panel and reconnect your panomc.com account, then re-activate this theme.</p>" +
|
|
86
|
+
"</section></main></body></html>";
|
|
87
|
+
return new Response(body, {
|
|
88
|
+
status: 503,
|
|
89
|
+
headers: {
|
|
90
|
+
"content-type": "text/html; charset=utf-8",
|
|
91
|
+
"cache-control": "no-store",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const IMPORT_MAP_PLACEHOLDER = "%pano_lib_import%";
|
|
97
|
+
const IMPORT_MAP_PLACEHOLDER_LEN = IMPORT_MAP_PLACEHOLDER.length;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {object} opts
|
|
101
|
+
* @param {string} opts.internalLibsHash content hash from the generated $lib/internalLibs.js
|
|
102
|
+
* @param {string} opts.runtimeShimsHash content hash from the generated $lib/runtimeShims.js
|
|
103
|
+
* @param {object} [opts.licenseConstants] the generated license constants module (premium builds);
|
|
104
|
+
* pass the whole module namespace — free builds no-op automatically. Panel profile: omit.
|
|
105
|
+
* @param {(html: string) => string} [opts.transformHtml] optional extra page-chunk transform
|
|
106
|
+
* @param {string} [opts.base] URL prefix for /lib and /runtime shim URLs ("" for themes,
|
|
107
|
+
* "/panel" for panel-ui — must match kit.paths.base)
|
|
108
|
+
* @param {(ctx: {event: any, locals: object, jwt: string|undefined, csrfToken: string|undefined,
|
|
109
|
+
* pathname: string}) => Promise<void>} [opts.resolveLocals] profile-specific locals resolution.
|
|
110
|
+
* Default (theme profile): locals.user via getCredentialsServerSide guarded against /api and
|
|
111
|
+
* /auth paths. Panel passes its basicData-based resolver instead.
|
|
112
|
+
* @param {(locals: object) => void} [opts.applyExtraEnv] hook for profile-specific env vars
|
|
113
|
+
* (panel: PANO_WEBSITE_API_URL → updatePanoWebsiteApiUrl)
|
|
114
|
+
* @param {boolean} [opts.suppressNoisyErrors] prod-suppress 405/no-form-action logs (theme default)
|
|
115
|
+
*/
|
|
116
|
+
export function createThemeHooks({
|
|
117
|
+
internalLibsHash,
|
|
118
|
+
runtimeShimsHash,
|
|
119
|
+
licenseConstants = null,
|
|
120
|
+
transformHtml = null,
|
|
121
|
+
base = "",
|
|
122
|
+
resolveLocals = null,
|
|
123
|
+
applyExtraEnv = null,
|
|
124
|
+
suppressNoisyErrors = true,
|
|
125
|
+
}) {
|
|
126
|
+
const license = createLicenseRuntime(licenseConstants);
|
|
127
|
+
|
|
128
|
+
// Plugins' bare specifiers resolve to the tiny STABLE shim modules generated by
|
|
129
|
+
// bin/generate-runtime-shims.js. Each shim re-exports the HOST bundle's own live
|
|
130
|
+
// module instance from the registry populated by kit/hooks-client.js, so host pages
|
|
131
|
+
// and plugins share one Svelte runtime and no second runtime copy is downloaded at
|
|
132
|
+
// hydration. The shim URLs never change across deploys (stale cached HTML keeps
|
|
133
|
+
// working); their CONTENT only changes when the svelte/sdk dependency is upgraded,
|
|
134
|
+
// which the ?v=<runtimeShimsHash> query cache-busts — safe here, unlike the old
|
|
135
|
+
// /lib?v= scheme, because a shim served for a stale ?v is still just a re-export of
|
|
136
|
+
// whatever runtime the host page actually loaded, never a mismatched second bundle.
|
|
137
|
+
// libBase (content-hashed, bin/bundle-internal-libs.js) still serves bootstrap.
|
|
138
|
+
const libBase = `${base}/lib/${internalLibsHash}`;
|
|
139
|
+
const runtimeShim = (file) => `${base}/runtime/${file}?v=${runtimeShimsHash}`;
|
|
140
|
+
const importMapEntries = Object.entries(RUNTIME_SPECIFIERS)
|
|
141
|
+
.map(([specifier, file]) => ` "${specifier}": "${runtimeShim(file)}"`)
|
|
142
|
+
.join(",\n");
|
|
143
|
+
const importMap = `
|
|
144
|
+
<script type="importmap" crossorigin="anonymous">
|
|
145
|
+
{
|
|
146
|
+
"imports": {
|
|
147
|
+
${importMapEntries}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
</script>
|
|
151
|
+
<script defer src="${libBase}/bootstrap/bootstrap.bundle.min.js"></script>`;
|
|
152
|
+
|
|
153
|
+
// One-shot license verification at boot. For premium builds the Pano host sets
|
|
154
|
+
// PANO_LICENSE_JWT before spawning bun; the runtime helper verifies the RS256 signature
|
|
155
|
+
// + claim checks against the panomc.com public key embedded at build time. Free builds
|
|
156
|
+
// no-op everything.
|
|
157
|
+
//
|
|
158
|
+
// `dev` is SvelteKit's COMPILE-TIME flag: true only under `vite dev`, false in
|
|
159
|
+
// every production build (baked into the bundle — cannot be spoofed with
|
|
160
|
+
// NODE_ENV at runtime). Premium authors can develop locally without a license;
|
|
161
|
+
// shipped zips keep enforcing.
|
|
162
|
+
const licenseEnforced = license.isPremiumBuild() && !dev;
|
|
163
|
+
if (license.isPremiumBuild() && dev) {
|
|
164
|
+
console.log(
|
|
165
|
+
"[pano-license] dev server — premium license gate skipped (enforced in production builds)",
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let bootLicenseError = null;
|
|
170
|
+
if (licenseEnforced) {
|
|
171
|
+
try {
|
|
172
|
+
license.verifyLicenseFromEnv();
|
|
173
|
+
console.log("[pano-license] startup verification passed");
|
|
174
|
+
} catch (e) {
|
|
175
|
+
bootLicenseError =
|
|
176
|
+
e instanceof license.LicenseError
|
|
177
|
+
? e
|
|
178
|
+
: new license.LicenseError("unknown", String(e?.message ?? e));
|
|
179
|
+
console.error(
|
|
180
|
+
"[pano-license] startup verification FAILED:",
|
|
181
|
+
bootLicenseError.message,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** @type {import('@sveltejs/kit').Handle} */
|
|
187
|
+
async function handle({
|
|
188
|
+
event,
|
|
189
|
+
event: {
|
|
190
|
+
cookies,
|
|
191
|
+
url: { pathname },
|
|
192
|
+
},
|
|
193
|
+
resolve,
|
|
194
|
+
}) {
|
|
195
|
+
// License gate: every request to a premium theme has to pass the cached check. Free
|
|
196
|
+
// builds and `vite dev` short-circuit (licenseEnforced is compile-time false in dev).
|
|
197
|
+
if (licenseEnforced) {
|
|
198
|
+
if (bootLicenseError) {
|
|
199
|
+
return renderLicenseBlocked(
|
|
200
|
+
bootLicenseError.reason ?? "unknown",
|
|
201
|
+
bootLicenseError.message,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
license.assertStillLicensed();
|
|
206
|
+
} catch (e) {
|
|
207
|
+
const reason =
|
|
208
|
+
e instanceof license.LicenseError ? e.reason : "unknown";
|
|
209
|
+
return renderLicenseBlocked(reason, e?.message);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const locals = {};
|
|
214
|
+
|
|
215
|
+
// noinspection JSUnresolvedReference
|
|
216
|
+
const apiUrlEnv = process.env.API_URL;
|
|
217
|
+
|
|
218
|
+
// noinspection JSUnresolvedReference
|
|
219
|
+
const panoWebsiteUrlEnv = process.env.PANO_WEBSITE_URL;
|
|
220
|
+
|
|
221
|
+
if (apiUrlEnv) {
|
|
222
|
+
updateApiUrl(apiUrlEnv);
|
|
223
|
+
locals.apiUrlEnv = apiUrlEnv;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (panoWebsiteUrlEnv) {
|
|
227
|
+
updatePanoWebsiteUrl(panoWebsiteUrlEnv);
|
|
228
|
+
locals.panoWebsiteUrlEnv = panoWebsiteUrlEnv;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (applyExtraEnv) {
|
|
232
|
+
applyExtraEnv(locals);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const jwt = getCookieWithHttpFallback(
|
|
236
|
+
cookies,
|
|
237
|
+
COOKIE_PREFIX + JWT_COOKIE_NAME,
|
|
238
|
+
);
|
|
239
|
+
const csrfToken = getCookieWithHttpFallback(
|
|
240
|
+
cookies,
|
|
241
|
+
COOKIE_PREFIX + CSRF_TOKEN_COOKIE_NAME,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
if (resolveLocals) {
|
|
245
|
+
// Profile-specific (panel: /api/panel/basicData → locals.basicData/jwt).
|
|
246
|
+
await resolveLocals({ event, locals, jwt, csrfToken, pathname });
|
|
247
|
+
} else {
|
|
248
|
+
locals.user =
|
|
249
|
+
jwt &&
|
|
250
|
+
csrfToken &&
|
|
251
|
+
!pathname.startsWith("/api/") &&
|
|
252
|
+
!pathname.startsWith("/auth/") &&
|
|
253
|
+
(await getCredentialsServerSide(jwt));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
locals.csrfToken = csrfToken;
|
|
257
|
+
|
|
258
|
+
event.locals = locals;
|
|
259
|
+
|
|
260
|
+
const response = await resolve(event, {
|
|
261
|
+
transformPageChunk: ({ html }) => {
|
|
262
|
+
const index = html.indexOf(IMPORT_MAP_PLACEHOLDER);
|
|
263
|
+
let out = html;
|
|
264
|
+
if (index !== -1) {
|
|
265
|
+
out =
|
|
266
|
+
html.substring(0, index) +
|
|
267
|
+
importMap +
|
|
268
|
+
html.substring(index + IMPORT_MAP_PLACEHOLDER_LEN);
|
|
269
|
+
}
|
|
270
|
+
return transformHtml ? transformHtml(out) : out;
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const ct = response.headers.get("content-type") || "";
|
|
275
|
+
if (ct.includes("text/html")) {
|
|
276
|
+
const link = response.headers.get("link");
|
|
277
|
+
if (link) {
|
|
278
|
+
const filtered = stripModulePreload(link);
|
|
279
|
+
if (filtered) response.headers.set("link", filtered);
|
|
280
|
+
else response.headers.delete("link");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return response;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** @type {import('@sveltejs/kit').HandleServerError} */
|
|
288
|
+
function handleError({ error, event }) {
|
|
289
|
+
if (!suppressNoisyErrors || !shouldSuppressServerErrorLog(error)) {
|
|
290
|
+
console.log("!!! [GLOBAL ERROR EVENT]:", event.url.href);
|
|
291
|
+
console.error("!!! [GLOBAL ERROR CONTENT]:", error);
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
message: "Internal Error",
|
|
295
|
+
code: error?.code,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** @type {import("@sveltejs/kit").HandleFetch} */
|
|
300
|
+
async function handleFetch({ event, request, fetch }) {
|
|
301
|
+
// Rewrite relative /api/ requests to the backend URL during SSR.
|
|
302
|
+
// Load functions use relative paths for consistent SSR↔CSR fetch dedup.
|
|
303
|
+
if (request.url.startsWith(event.url.origin + "/api/")) {
|
|
304
|
+
const apiPath =
|
|
305
|
+
new URL(request.url).pathname + new URL(request.url).search;
|
|
306
|
+
const backendUrl = API_URL.replace(/\/api\/?$/, "") + apiPath;
|
|
307
|
+
request = new Request(backendUrl, request);
|
|
308
|
+
request.headers.set("cookie", event.request.headers.get("cookie") || "");
|
|
309
|
+
request.headers.set("Origin", API_URL);
|
|
310
|
+
} else if (request.url.startsWith(API_URL)) {
|
|
311
|
+
request.headers.set("cookie", event.request.headers.get("cookie") || "");
|
|
312
|
+
request.headers.set("Origin", API_URL);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return fetch(request);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return { handle, handleError, handleFetch };
|
|
319
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime license check for premium Pano themes.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the plugin-side {@link com.panomc.plugins.license.PluginLicenseClient} in shape:
|
|
5
|
+
* - load the panomc.com public key embedded at build time
|
|
6
|
+
* - read the RS256 JWT from the PANO_LICENSE_JWT env var the Pano host sets when it
|
|
7
|
+
* spawns the theme bun process
|
|
8
|
+
* - verify the signature locally and assert the claims (audience = theme id, version,
|
|
9
|
+
* issuer, expiry)
|
|
10
|
+
*
|
|
11
|
+
* The host has ALREADY verified those claims by the time it hands us the JWT (see
|
|
12
|
+
* com.panomc.platform.license.LicenseManager.fetchAndCacheThemeLicense), but a forked /
|
|
13
|
+
* patched host could feed back a forged token. Re-verifying with our own embedded
|
|
14
|
+
* public key is the theme's actual security boundary; a cracker has to either tamper with
|
|
15
|
+
* THIS theme version's bundle (which only breaks one version, the next release resets
|
|
16
|
+
* everything because the public key, theme version and constants are embedded fresh) OR
|
|
17
|
+
* forge a JWT (impossible without panomc.com's RSA private key).
|
|
18
|
+
*
|
|
19
|
+
* Free builds (PANO_LICENSE_REQUIRED=false) make every export here a no-op so the same
|
|
20
|
+
* code path stays valid for development and free distribution.
|
|
21
|
+
*/
|
|
22
|
+
import { createHash, createPublicKey, createVerify } from "node:crypto";
|
|
23
|
+
import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
|
|
26
|
+
/** Stable strings mirrored from com.panomc.platform.license.LicenseDeniedReason. */
|
|
27
|
+
export const LICENSE_REASONS = Object.freeze({
|
|
28
|
+
NOT_CONNECTED: "not-connected",
|
|
29
|
+
KEY_NOT_AVAILABLE: "key-not-available",
|
|
30
|
+
SIGNATURE_INVALID: "signature-invalid",
|
|
31
|
+
EXPIRED: "expired",
|
|
32
|
+
AUDIENCE_MISMATCH: "audience-mismatch",
|
|
33
|
+
VERSION_MISMATCH: "version-mismatch",
|
|
34
|
+
MALFORMED_JWT: "malformed-jwt",
|
|
35
|
+
FILE_TAMPERED: "file-tampered",
|
|
36
|
+
UNKNOWN: "unknown",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export class LicenseError extends Error {
|
|
40
|
+
constructor(reason, message) {
|
|
41
|
+
super(`license-check-failed: ${reason}${message ? ` (${message})` : ""}`);
|
|
42
|
+
this.reason = reason;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createLicenseRuntime(licenseConstants) {
|
|
47
|
+
const {
|
|
48
|
+
PANO_LICENSE_PUBLIC_KEY_BASE64 = "",
|
|
49
|
+
PANO_LICENSE_THEME_ID = "",
|
|
50
|
+
PANO_LICENSE_THEME_VERSION = "",
|
|
51
|
+
PANO_LICENSE_REQUIRED = false,
|
|
52
|
+
PANO_LICENSE_ISSUER_HINT = "",
|
|
53
|
+
} = licenseConstants || {};
|
|
54
|
+
|
|
55
|
+
let cachedPublicKey = null;
|
|
56
|
+
function loadPublicKey() {
|
|
57
|
+
if (cachedPublicKey !== null) return cachedPublicKey;
|
|
58
|
+
if (!PANO_LICENSE_PUBLIC_KEY_BASE64) return null;
|
|
59
|
+
// Reassemble into PEM so node's crypto can ingest it. 64-char lines per X.509.
|
|
60
|
+
const pem =
|
|
61
|
+
"-----BEGIN PUBLIC KEY-----\n" +
|
|
62
|
+
(PANO_LICENSE_PUBLIC_KEY_BASE64.match(/.{1,64}/g) || []).join("\n") +
|
|
63
|
+
"\n-----END PUBLIC KEY-----\n";
|
|
64
|
+
cachedPublicKey = createPublicKey(pem);
|
|
65
|
+
return cachedPublicKey;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function base64UrlDecode(str) {
|
|
69
|
+
const pad = "=".repeat((4 - (str.length % 4)) % 4);
|
|
70
|
+
const b64 = (str + pad).replace(/-/g, "+").replace(/_/g, "/");
|
|
71
|
+
return Buffer.from(b64, "base64");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function decodeJwt(jwt) {
|
|
75
|
+
const parts = jwt.split(".");
|
|
76
|
+
if (parts.length !== 3) {
|
|
77
|
+
throw new LicenseError(LICENSE_REASONS.MALFORMED_JWT, "JWT does not have 3 segments");
|
|
78
|
+
}
|
|
79
|
+
let header;
|
|
80
|
+
let payload;
|
|
81
|
+
try {
|
|
82
|
+
header = JSON.parse(base64UrlDecode(parts[0]).toString("utf-8"));
|
|
83
|
+
payload = JSON.parse(base64UrlDecode(parts[1]).toString("utf-8"));
|
|
84
|
+
} catch (e) {
|
|
85
|
+
throw new LicenseError(LICENSE_REASONS.MALFORMED_JWT, e.message);
|
|
86
|
+
}
|
|
87
|
+
const signature = base64UrlDecode(parts[2]);
|
|
88
|
+
const signedData = Buffer.from(`${parts[0]}.${parts[1]}`, "utf-8");
|
|
89
|
+
return { header, payload, signature, signedData };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Cached snapshot of the last successful verification; refreshed lazily on expiry. */
|
|
93
|
+
let snapshot = null;
|
|
94
|
+
|
|
95
|
+
/** True when this build was configured as premium AND a public key was embedded. */
|
|
96
|
+
function isPremiumBuild() {
|
|
97
|
+
return PANO_LICENSE_REQUIRED && !!PANO_LICENSE_PUBLIC_KEY_BASE64;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Theme identity baked in at build time. */
|
|
101
|
+
function getEmbeddedThemeIdentity() {
|
|
102
|
+
return {
|
|
103
|
+
id: PANO_LICENSE_THEME_ID,
|
|
104
|
+
version: PANO_LICENSE_THEME_VERSION,
|
|
105
|
+
premium: PANO_LICENSE_REQUIRED,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Verifies the JWT in PANO_LICENSE_JWT (RS256 + claim checks) and caches the snapshot.
|
|
111
|
+
* Throws [LicenseError] on any failure. No-op for free builds.
|
|
112
|
+
*/
|
|
113
|
+
function verifyLicenseFromEnv() {
|
|
114
|
+
if (!isPremiumBuild()) {
|
|
115
|
+
snapshot = null;
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const publicKey = loadPublicKey();
|
|
120
|
+
if (!publicKey) {
|
|
121
|
+
throw new LicenseError(
|
|
122
|
+
LICENSE_REASONS.KEY_NOT_AVAILABLE,
|
|
123
|
+
"embedded panomc.com public key is missing or malformed"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// JWT priority: <themeRoot>/.pano-license.jwt (refreshed by the Pano host every renewal
|
|
128
|
+
// sweep) > PANO_LICENSE_JWT env (initial value at process start). The env var alone
|
|
129
|
+
// would freeze at the launch-time JWT and expire after one TTL window even though the
|
|
130
|
+
// host already has a fresh token in cache — see UIManager.writeThemeLicenseFile.
|
|
131
|
+
const themeRootForJwt = locateThemeRoot();
|
|
132
|
+
const jwt = readCurrentJwt(themeRootForJwt);
|
|
133
|
+
if (!jwt) {
|
|
134
|
+
throw new LicenseError(
|
|
135
|
+
LICENSE_REASONS.NOT_CONNECTED,
|
|
136
|
+
"Pano host did not pass PANO_LICENSE_JWT (premium themes require a connected panomc.com account)"
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const { header, payload, signature, signedData } = decodeJwt(jwt);
|
|
141
|
+
if (header.alg !== "RS256") {
|
|
142
|
+
throw new LicenseError(
|
|
143
|
+
LICENSE_REASONS.SIGNATURE_INVALID,
|
|
144
|
+
`unexpected JWT algorithm: ${header.alg}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let signatureOk = false;
|
|
149
|
+
try {
|
|
150
|
+
signatureOk = createVerify("RSA-SHA256").update(signedData).verify(publicKey, signature);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
throw new LicenseError(LICENSE_REASONS.SIGNATURE_INVALID, e.message);
|
|
153
|
+
}
|
|
154
|
+
if (!signatureOk) {
|
|
155
|
+
throw new LicenseError(
|
|
156
|
+
LICENSE_REASONS.SIGNATURE_INVALID,
|
|
157
|
+
"JWT signature failed verification (host may be tampered)"
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const expectedIssuer =
|
|
162
|
+
(process.env.PANO_LICENSE_ISSUER || PANO_LICENSE_ISSUER_HINT || "panomc.com").trim();
|
|
163
|
+
if (expectedIssuer && payload.iss !== expectedIssuer) {
|
|
164
|
+
throw new LicenseError(
|
|
165
|
+
LICENSE_REASONS.AUDIENCE_MISMATCH,
|
|
166
|
+
`iss=${payload.iss}, expected ${expectedIssuer}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const audience = Array.isArray(payload.aud) ? payload.aud[0] : payload.aud;
|
|
171
|
+
if (
|
|
172
|
+
!audience ||
|
|
173
|
+
String(audience).toLowerCase() !== String(PANO_LICENSE_THEME_ID).toLowerCase()
|
|
174
|
+
) {
|
|
175
|
+
throw new LicenseError(
|
|
176
|
+
LICENSE_REASONS.AUDIENCE_MISMATCH,
|
|
177
|
+
`aud=${audience}, expected ${PANO_LICENSE_THEME_ID}`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (payload.ver !== PANO_LICENSE_THEME_VERSION) {
|
|
182
|
+
throw new LicenseError(
|
|
183
|
+
LICENSE_REASONS.VERSION_MISMATCH,
|
|
184
|
+
`ver=${payload.ver}, expected ${PANO_LICENSE_THEME_VERSION}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
189
|
+
if (typeof payload.exp !== "number" || payload.exp <= nowSec) {
|
|
190
|
+
throw new LicenseError(LICENSE_REASONS.EXPIRED, `exp=${payload.exp} now=${nowSec}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Self-verify file integrity. The Pano host already validates this when it starts the
|
|
194
|
+
// bun process (see UIManager.startUI ↔ HashUtil.computeStableFileFingerprint), but a
|
|
195
|
+
// forked/patched host could skip its own check. Reading the on-disk manifest here +
|
|
196
|
+
// re-walking our own theme directory makes the theme refuse to serve when any of its
|
|
197
|
+
// shipped files have been edited after install.
|
|
198
|
+
//
|
|
199
|
+
// The check is wrapped in a try-catch so a malformed/missing manifest is reported as
|
|
200
|
+
// FILE_TAMPERED instead of bubbling a generic FS error (those are noisy and unhelpful).
|
|
201
|
+
try {
|
|
202
|
+
verifyFileFingerprint();
|
|
203
|
+
} catch (e) {
|
|
204
|
+
if (e instanceof LicenseError) throw e;
|
|
205
|
+
throw new LicenseError(LICENSE_REASONS.FILE_TAMPERED, e?.message || String(e));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
snapshot = {
|
|
209
|
+
payload,
|
|
210
|
+
expiresAtMs: payload.exp * 1000,
|
|
211
|
+
audience,
|
|
212
|
+
version: payload.ver,
|
|
213
|
+
};
|
|
214
|
+
return snapshot;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const DEFAULT_FINGERPRINT_EXCLUDE = new Set(["manifest.json", ".pano-license.jwt"]);
|
|
218
|
+
const LICENSE_JWT_FILENAME = ".pano-license.jwt";
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Reads the freshest JWT for this theme. Priority:
|
|
222
|
+
* 1. <themeRoot>/.pano-license.jwt — host writes this on every renewal sweep so the bun
|
|
223
|
+
* process can pick up new tokens without restarting.
|
|
224
|
+
* 2. process.env.PANO_LICENSE_JWT — the launch-time value, used as a fallback when the
|
|
225
|
+
* disk file is missing (e.g. first start of a theme installed by an older host).
|
|
226
|
+
*/
|
|
227
|
+
function readCurrentJwt(themeRoot) {
|
|
228
|
+
if (themeRoot) {
|
|
229
|
+
try {
|
|
230
|
+
const p = path.join(themeRoot, LICENSE_JWT_FILENAME);
|
|
231
|
+
if (existsSync(p)) {
|
|
232
|
+
const fromDisk = readFileSync(p, "utf8").trim();
|
|
233
|
+
if (fromDisk) return fromDisk;
|
|
234
|
+
}
|
|
235
|
+
} catch {
|
|
236
|
+
// fall through to env
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return (process.env.PANO_LICENSE_JWT || "").trim();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function sha256Hex(buffer) {
|
|
243
|
+
return createHash("sha256").update(buffer).digest("hex");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function listFilesRecursive(dir) {
|
|
247
|
+
const out = [];
|
|
248
|
+
function walk(d) {
|
|
249
|
+
let entries;
|
|
250
|
+
try {
|
|
251
|
+
entries = readdirSync(d, { withFileTypes: true });
|
|
252
|
+
} catch {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
for (const entry of entries) {
|
|
256
|
+
const full = path.join(d, entry.name);
|
|
257
|
+
if (entry.isDirectory()) walk(full);
|
|
258
|
+
else if (entry.isFile()) out.push(full);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
walk(dir);
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Reimplementation of file-fingerprint.js#computeStableFileFingerprint. Kept inline here
|
|
267
|
+
* so the runtime guard works without depending on any extra source files that an attacker
|
|
268
|
+
* could trivially remove from the build output.
|
|
269
|
+
*/
|
|
270
|
+
function computeFileFingerprintOf(dir) {
|
|
271
|
+
const items = listFilesRecursive(dir)
|
|
272
|
+
.map((full) => ({
|
|
273
|
+
rel: path.relative(dir, full).split(path.sep).join("/"),
|
|
274
|
+
full,
|
|
275
|
+
}))
|
|
276
|
+
.filter((it) => !DEFAULT_FINGERPRINT_EXCLUDE.has(it.rel))
|
|
277
|
+
.sort((a, b) => (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0))
|
|
278
|
+
.map((it) => `${it.rel}:${sha256Hex(readFileSync(it.full))}`);
|
|
279
|
+
return sha256Hex(items.join("\n"));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Locate the theme root by walking up from the running script until we find a
|
|
284
|
+
* `manifest.json` with our theme id. We can't trust process.cwd() blindly because the
|
|
285
|
+
* Pano host spawns bun from inside the theme folder but operators could run it via
|
|
286
|
+
* arbitrary working directories during local debugging.
|
|
287
|
+
*/
|
|
288
|
+
function locateThemeRoot() {
|
|
289
|
+
const candidates = [process.cwd()];
|
|
290
|
+
// `import.meta.url` resolves to .../build/server/chunks/<hash>.js after vite has bundled
|
|
291
|
+
// this file. The theme root is "up" from there.
|
|
292
|
+
try {
|
|
293
|
+
const here = new URL(import.meta.url).pathname;
|
|
294
|
+
let dir = path.dirname(here);
|
|
295
|
+
for (let i = 0; i < 8; i++) {
|
|
296
|
+
candidates.push(dir);
|
|
297
|
+
dir = path.dirname(dir);
|
|
298
|
+
if (dir === "/" || dir === ".") break;
|
|
299
|
+
}
|
|
300
|
+
} catch {
|
|
301
|
+
// import.meta.url unavailable in some runtimes (older bun, jest, etc.) — fall back to
|
|
302
|
+
// cwd-only.
|
|
303
|
+
}
|
|
304
|
+
for (const c of candidates) {
|
|
305
|
+
const mf = path.join(c, "manifest.json");
|
|
306
|
+
if (!existsSync(mf)) continue;
|
|
307
|
+
try {
|
|
308
|
+
const parsed = JSON.parse(readFileSync(mf, "utf-8"));
|
|
309
|
+
if (parsed && parsed.id === PANO_LICENSE_THEME_ID) return c;
|
|
310
|
+
} catch {
|
|
311
|
+
// try the next candidate
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function verifyFileFingerprint() {
|
|
318
|
+
const themeRoot = locateThemeRoot();
|
|
319
|
+
if (!themeRoot) {
|
|
320
|
+
throw new LicenseError(
|
|
321
|
+
LICENSE_REASONS.FILE_TAMPERED,
|
|
322
|
+
`could not locate theme root containing manifest.json for "${PANO_LICENSE_THEME_ID}"`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
const manifest = JSON.parse(readFileSync(path.join(themeRoot, "manifest.json"), "utf-8"));
|
|
326
|
+
const expected = manifest.fileFingerprint;
|
|
327
|
+
if (typeof expected !== "string" || expected.length !== 64) {
|
|
328
|
+
throw new LicenseError(
|
|
329
|
+
LICENSE_REASONS.FILE_TAMPERED,
|
|
330
|
+
"manifest.json is missing or has malformed fileFingerprint (run a fresh build of the theme)"
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
const actual = computeFileFingerprintOf(themeRoot);
|
|
334
|
+
if (actual !== expected) {
|
|
335
|
+
throw new LicenseError(
|
|
336
|
+
LICENSE_REASONS.FILE_TAMPERED,
|
|
337
|
+
`theme files have been modified after install: expected ${expected.slice(0, 12)}…, got ${actual.slice(0, 12)}…`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Re-verify proactively when the cached snapshot has less than this much time left. */
|
|
343
|
+
const PRE_EXPIRY_REFRESH_MARGIN_MS = 5 * 60 * 1000;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Cheap runtime check intended for sprinkling across request handlers. Re-verifies a
|
|
347
|
+
* few minutes BEFORE the cached snapshot expires so we pick up the JWT that the host
|
|
348
|
+
* just wrote to <themeRoot>/.pano-license.jwt (the host's half-life renewal lands
|
|
349
|
+
* roughly at expiresAt - 30 minutes for a 1h TTL, so 5 min before expiry the disk
|
|
350
|
+
* file is always already refreshed).
|
|
351
|
+
*/
|
|
352
|
+
function assertStillLicensed() {
|
|
353
|
+
if (!isPremiumBuild()) return;
|
|
354
|
+
if (!snapshot || snapshot.expiresAtMs <= Date.now() + PRE_EXPIRY_REFRESH_MARGIN_MS) {
|
|
355
|
+
verifyLicenseFromEnv();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Returns the current verified license snapshot or null. */
|
|
360
|
+
function getLicenseSnapshot() {
|
|
361
|
+
return snapshot;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
LICENSE_REASONS,
|
|
366
|
+
LicenseError,
|
|
367
|
+
isPremiumBuild,
|
|
368
|
+
getEmbeddedThemeIdentity,
|
|
369
|
+
verifyLicenseFromEnv,
|
|
370
|
+
assertStillLicensed,
|
|
371
|
+
getLicenseSnapshot,
|
|
372
|
+
};
|
|
373
|
+
}
|