@panomc/sdk 1.0.0-dev.4 → 1.0.0-dev.40
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 +3 -3
- package/core/favicon/apple-touch-icon.png +0 -0
- package/core/favicon/favicon-96x96.png +0 -0
- package/core/favicon/favicon.ico +0 -0
- package/core/favicon/favicon.svg +1 -0
- package/core/favicon/site.webmanifest +21 -0
- package/core/favicon/web-app-manifest-192x192.png +0 -0
- package/core/favicon/web-app-manifest-512x512.png +0 -0
- package/core/favicon_old/android-icon-144x144.png +0 -0
- package/core/favicon_old/android-icon-192x192.png +0 -0
- package/core/favicon_old/android-icon-36x36.png +0 -0
- package/core/favicon_old/android-icon-48x48.png +0 -0
- package/core/favicon_old/android-icon-72x72.png +0 -0
- package/core/favicon_old/android-icon-96x96.png +0 -0
- package/core/favicon_old/apple-icon-114x114.png +0 -0
- package/core/favicon_old/apple-icon-120x120.png +0 -0
- package/core/favicon_old/apple-icon-144x144.png +0 -0
- package/core/favicon_old/apple-icon-152x152.png +0 -0
- package/core/favicon_old/apple-icon-180x180.png +0 -0
- package/core/favicon_old/apple-icon-57x57.png +0 -0
- package/core/favicon_old/apple-icon-60x60.png +0 -0
- package/core/favicon_old/apple-icon-72x72.png +0 -0
- package/core/favicon_old/apple-icon-76x76.png +0 -0
- package/core/favicon_old/apple-icon-precomposed.png +0 -0
- package/core/favicon_old/apple-icon.png +0 -0
- package/core/favicon_old/browserconfig.xml +11 -0
- package/core/favicon_old/favicon-16x16.png +0 -0
- package/core/favicon_old/favicon-32x32.png +0 -0
- package/core/favicon_old/favicon-96x96.png +0 -0
- package/core/favicon_old/favicon.ico +0 -0
- package/core/favicon_old/manifest.json +41 -0
- package/core/favicon_old/ms-icon-144x144.png +0 -0
- package/core/favicon_old/ms-icon-150x150.png +0 -0
- package/core/favicon_old/ms-icon-310x310.png +0 -0
- package/core/favicon_old/ms-icon-70x70.png +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.svg +483 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff2 +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.svg +486 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff2 +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.svg +484 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff2 +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.eot +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.svg +486 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.ttf +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff +0 -0
- package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff2 +0 -0
- package/core/js/NotificationManager.js +19 -0
- package/core/js/PluginAPI.js +29 -0
- package/core/js/PluginManager.js +789 -0
- package/core/js/RouteMatcher.js +134 -0
- package/core/js/api.util.js +248 -0
- package/core/js/tooltip.util.js +59 -0
- package/core/js/variables.js +60 -0
- package/core/js/version.util.js +100 -0
- package/core/scss/custom-bootstrap.scss +187 -0
- package/core/scss/fonts.scss +85 -0
- package/core/scss/main.scss +385 -0
- package/core/scss/themes.scss +97 -0
- package/package.json +34 -10
- package/src/api/plugin-context.js +3 -3
- package/src/api/plugin.js +20 -3
- package/src/components/{index.js → panel.js} +12 -8
- package/src/components/theme.js +13 -0
- package/src/index.js +3 -3
- package/src/internal/index.js +1 -1
- package/src/internal/pano-context.js +14 -4
- package/src/svelte.js +7 -0
- package/src/toasts/index.js +2 -2
- package/src/types.js +40 -0
- package/src/utils/api.js +2 -2
- package/src/utils/auth.js +8 -0
- package/src/utils/component.js +11 -9
- package/src/utils/language.js +3 -1
- package/src/utils/text.js +8 -0
- package/src/utils/tooltip.js +1 -1
- package/src/variables.js +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple route matcher that supports literals, dynamic segments [param],
|
|
3
|
+
* catch-all segments [...param], and basic regex patterns.
|
|
4
|
+
*/
|
|
5
|
+
export class RouteMatcher {
|
|
6
|
+
/**
|
|
7
|
+
* Matches a path against a pattern.
|
|
8
|
+
* @param {string} pattern - The route pattern (e.g., '/announcements/[id]')
|
|
9
|
+
* @param {string} path - The actual path (e.g., '/announcements/123')
|
|
10
|
+
* @returns {object|null} - Params object if matched, null otherwise
|
|
11
|
+
*/
|
|
12
|
+
static match(pattern, path) {
|
|
13
|
+
// Normalize path: remove query params and trailing slash
|
|
14
|
+
const [pathOnly] = path.split('?');
|
|
15
|
+
const normalizedPath = pathOnly === '/' ? '/' : pathOnly.replace(/\/$/, '');
|
|
16
|
+
const normalizedPattern = pattern === '/' ? '/' : pattern.replace(/\/$/, '');
|
|
17
|
+
|
|
18
|
+
// 1. Literal match
|
|
19
|
+
if (normalizedPattern === normalizedPath) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 2. Regex match
|
|
24
|
+
// Regex must be explicitly opted in with a `re:` prefix — we must NOT infer "this is a
|
|
25
|
+
// regex" from a leading/trailing slash, since a normal plugin path with a trailing slash
|
|
26
|
+
// (e.g. `/news/`) would otherwise be reinterpreted as an UNANCHORED regex and silently
|
|
27
|
+
// hijack unrelated routes. The body is anchored as `^(?:...)$` so it can't partial-match.
|
|
28
|
+
if (pattern.startsWith('re:')) {
|
|
29
|
+
try {
|
|
30
|
+
const regex = new RegExp(`^(?:${pattern.slice(3)})$`);
|
|
31
|
+
const match = normalizedPath.match(regex);
|
|
32
|
+
if (match) {
|
|
33
|
+
return match.groups || {};
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error('Invalid regex pattern:', pattern, e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 3. Segment-based match (SvelteKit style)
|
|
41
|
+
const patternSegments = normalizedPattern.split('/').filter(Boolean);
|
|
42
|
+
const pathSegments = normalizedPath.split('/').filter(Boolean);
|
|
43
|
+
|
|
44
|
+
const params = {};
|
|
45
|
+
|
|
46
|
+
// Check for catch-all [...param]
|
|
47
|
+
const catchAllIndex = patternSegments.findIndex((s) => s.startsWith('[...') && s.endsWith(']'));
|
|
48
|
+
|
|
49
|
+
if (catchAllIndex !== -1) {
|
|
50
|
+
// SvelteKit only allows a rest param as the FINAL segment. A catch-all that isn't last
|
|
51
|
+
// would greedily absorb every trailing segment and ignore the pattern's suffix, so a
|
|
52
|
+
// pattern like `/[...rest]/edit` would wrongly match `/a/b/c`. Reject it outright.
|
|
53
|
+
if (catchAllIndex !== patternSegments.length - 1) return null;
|
|
54
|
+
|
|
55
|
+
// Logic for catch-all
|
|
56
|
+
if (pathSegments.length < catchAllIndex) return null;
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < catchAllIndex; i++) {
|
|
59
|
+
if (!this.segmentsMatch(patternSegments[i], pathSegments[i], params)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const paramName = patternSegments[catchAllIndex].slice(4, -1);
|
|
65
|
+
params[paramName] = pathSegments.slice(catchAllIndex).join('/');
|
|
66
|
+
return params;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Normal segment match
|
|
70
|
+
if (patternSegments.length !== pathSegments.length) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (let i = 0; i < patternSegments.length; i++) {
|
|
75
|
+
if (!this.segmentsMatch(patternSegments[i], pathSegments[i], params)) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return params;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static segmentsMatch(patternSegment, pathSegment, params) {
|
|
84
|
+
if (patternSegment.startsWith('[') && patternSegment.endsWith(']')) {
|
|
85
|
+
const paramName = patternSegment.slice(1, -1);
|
|
86
|
+
params[paramName] = pathSegment;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (patternSegment.startsWith(':')) {
|
|
90
|
+
const paramName = patternSegment.slice(1);
|
|
91
|
+
params[paramName] = pathSegment;
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return patternSegment === pathSegment;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Canonical form of a route key/path used for the exact-match fast path: query stripped and a
|
|
100
|
+
* single trailing slash removed (but `/` preserved). Used at BOTH registration and lookup so
|
|
101
|
+
* `/foo` and `/foo/` collapse to one entry and the exact-match map lookup always hits instead
|
|
102
|
+
* of falling through to the slower (and buggier) regex/segment branch.
|
|
103
|
+
* @param {string} path
|
|
104
|
+
* @returns {string}
|
|
105
|
+
*/
|
|
106
|
+
export function canonicalizeRouteKey(path) {
|
|
107
|
+
const [pathOnly] = String(path).split('?');
|
|
108
|
+
return pathOnly === '/' ? '/' : pathOnly.replace(/\/$/, '');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Finds a registered page matching the given path.
|
|
113
|
+
* @param {Object} registeredPages - Map of patterns to page objects
|
|
114
|
+
* @param {string} path - The path to match
|
|
115
|
+
* @returns {Object|null} - The matching page object with params, or null
|
|
116
|
+
*/
|
|
117
|
+
export function findMatch(registeredPages, path) {
|
|
118
|
+
// First, try exact match for performance
|
|
119
|
+
const normalizedPath = canonicalizeRouteKey(path);
|
|
120
|
+
|
|
121
|
+
if (registeredPages[normalizedPath]) {
|
|
122
|
+
return { ...registeredPages[normalizedPath], params: {} };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Then, try more complex matches
|
|
126
|
+
for (const pattern in registeredPages) {
|
|
127
|
+
const params = RouteMatcher.match(pattern, path);
|
|
128
|
+
if (params) {
|
|
129
|
+
return { ...registeredPages[pattern], params };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { API_URL, CSRF_HEADER } from "$lib/variables.js";
|
|
2
|
+
import { get } from "svelte/store";
|
|
3
|
+
import { page } from "$app/stores";
|
|
4
|
+
import { browser } from "$app/environment";
|
|
5
|
+
import { initialized } from "$lib/Store.js";
|
|
6
|
+
import { show } from "$lib/components/ToastContainer.svelte";
|
|
7
|
+
|
|
8
|
+
// Constants for network error handling
|
|
9
|
+
export const NETWORK_ERROR = 'NETWORK_ERROR';
|
|
10
|
+
export const networkErrorBody = { result: 'error', error: NETWORK_ERROR };
|
|
11
|
+
|
|
12
|
+
// Function to build query parameters from an object
|
|
13
|
+
export function buildQueryParams(params) {
|
|
14
|
+
const queryString = Object.keys(params)
|
|
15
|
+
.filter((key) => params[key])
|
|
16
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
|
17
|
+
.join('&');
|
|
18
|
+
return queryString === '' ? '' : '?' + queryString;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ApiUtil = {
|
|
22
|
+
interceptors: {},
|
|
23
|
+
|
|
24
|
+
// GET request
|
|
25
|
+
async get({ path, request, csrfToken, token, blob, handler }) {
|
|
26
|
+
return this.customRequest({
|
|
27
|
+
path,
|
|
28
|
+
request,
|
|
29
|
+
csrfToken,
|
|
30
|
+
token,
|
|
31
|
+
blob,
|
|
32
|
+
handler,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// POST request
|
|
37
|
+
async post({ path, request, body, headers, csrfToken, token, blob, handler, onUploadProgress }) {
|
|
38
|
+
return this.customRequest({
|
|
39
|
+
path,
|
|
40
|
+
data: { method: 'POST', credentials: 'include', body, headers },
|
|
41
|
+
request,
|
|
42
|
+
csrfToken,
|
|
43
|
+
token,
|
|
44
|
+
blob,
|
|
45
|
+
handler,
|
|
46
|
+
onUploadProgress,
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// PUT request
|
|
51
|
+
async put({ path, request, body, headers, csrfToken, token, blob, handler, onUploadProgress }) {
|
|
52
|
+
return this.customRequest({
|
|
53
|
+
path,
|
|
54
|
+
data: { method: 'PUT', credentials: 'include', body, headers },
|
|
55
|
+
request,
|
|
56
|
+
csrfToken,
|
|
57
|
+
token,
|
|
58
|
+
blob,
|
|
59
|
+
handler,
|
|
60
|
+
onUploadProgress,
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// DELETE request
|
|
65
|
+
async delete({ path, request, headers, csrfToken, token, blob, handler }) {
|
|
66
|
+
return this.customRequest({
|
|
67
|
+
path,
|
|
68
|
+
data: { method: 'DELETE', headers },
|
|
69
|
+
request,
|
|
70
|
+
csrfToken,
|
|
71
|
+
token,
|
|
72
|
+
blob,
|
|
73
|
+
handler,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
// Custom request handler
|
|
78
|
+
async customRequest({ path, data = {}, request, csrfToken, token, blob, handler, onUploadProgress }) {
|
|
79
|
+
// Retrieve CSRF token if not provided
|
|
80
|
+
if (!csrfToken) {
|
|
81
|
+
let session;
|
|
82
|
+
if (request && typeof request.parent === "function") {
|
|
83
|
+
const parentData = await request.parent();
|
|
84
|
+
session = parentData.session;
|
|
85
|
+
} else if (browser && get(page).data) {
|
|
86
|
+
session = get(page).data.session;
|
|
87
|
+
}
|
|
88
|
+
csrfToken = session && session.csrfToken;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Set CSRF header if token is available
|
|
92
|
+
const CSRFHeader = csrfToken ? { [CSRF_HEADER]: csrfToken } : {};
|
|
93
|
+
|
|
94
|
+
// Convert body to JSON string if not FormData
|
|
95
|
+
if (!(data.body instanceof FormData)) {
|
|
96
|
+
data.body = JSON.stringify(data.body);
|
|
97
|
+
data.headers = { 'Content-Type': 'application/json', ...data.headers };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Set request options
|
|
101
|
+
const options = {
|
|
102
|
+
...data,
|
|
103
|
+
headers: { ...data.headers, ...CSRFHeader },
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Add Authorization header if token is provided
|
|
107
|
+
if (token) {
|
|
108
|
+
options.headers['Authorization'] = `Bearer ${token}`;
|
|
109
|
+
} else if ('credentials' in Request.prototype) {
|
|
110
|
+
options['credentials'] = 'include';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// When the app runs behind the Pano backend's reverse proxy, SvelteKit load
|
|
114
|
+
// functions must use relative paths so SSR and CSR fetch URLs match.
|
|
115
|
+
// SvelteKit deduplicates event.fetch calls by URL — if SSR uses an absolute URL
|
|
116
|
+
// (e.g. http://0.0.0.0:8088/api/...) but CSR uses relative (/api/...), the client
|
|
117
|
+
// will re-fetch instead of using the serialized SSR response.
|
|
118
|
+
//
|
|
119
|
+
// For the Pano website (api.panomc.com on Cloudflare Pages), both SSR and CSR
|
|
120
|
+
// already use the same absolute URL, so dedup works naturally — no change needed.
|
|
121
|
+
const hasEventFetch = request && request.fetch;
|
|
122
|
+
const isReverseProxied = !API_URL.includes(".panomc.com");
|
|
123
|
+
|
|
124
|
+
if (hasEventFetch && isReverseProxied) {
|
|
125
|
+
// Reverse proxy scenario: use relative path for consistent SSR↔CSR dedup.
|
|
126
|
+
// handleFetch in hooks.server.js will rewrite this to the backend URL during SSR.
|
|
127
|
+
if (!path.startsWith("/api/")) {
|
|
128
|
+
path = `/api/${path.replace("/api/", "")}`;
|
|
129
|
+
}
|
|
130
|
+
} else if ((request && !get(initialized)) || !browser || API_URL.includes(".panomc.com")) {
|
|
131
|
+
let apiUrl = API_URL;
|
|
132
|
+
|
|
133
|
+
if (
|
|
134
|
+
!API_URL.includes(".panomc.com") &&
|
|
135
|
+
import.meta.env.PROD &&
|
|
136
|
+
browser &&
|
|
137
|
+
get(initialized)
|
|
138
|
+
) {
|
|
139
|
+
apiUrl = "/api"
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (browser && (API_URL.includes("0.0.0.0") || API_URL.includes("127.0.0.1") || API_URL.includes("localhost"))) {
|
|
143
|
+
apiUrl = "/api"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
path = `${apiUrl}/${path.replace('/api/', '')}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const bodyHandler = (response) => (blob ? response.blob() : response.text());
|
|
150
|
+
const jsonParseHandler = (json) => {
|
|
151
|
+
try {
|
|
152
|
+
return JSON.parse(json);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
return json;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const requestCall = (rejectHandler) => {
|
|
159
|
+
const reject = async (err) => {
|
|
160
|
+
console.log(err);
|
|
161
|
+
if (rejectHandler) {
|
|
162
|
+
throw new Error(err);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (!this.interceptors.errorHandler || !handler) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.interceptors.errorHandler(requestCall);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (onUploadProgress && browser && data.body instanceof FormData) {
|
|
173
|
+
return new Promise((resolve, rejectFn) => {
|
|
174
|
+
const xhr = new XMLHttpRequest();
|
|
175
|
+
xhr.open(data.method, path);
|
|
176
|
+
|
|
177
|
+
if (options.credentials === 'include') {
|
|
178
|
+
xhr.withCredentials = true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const headersToSet = { ...options.headers };
|
|
182
|
+
delete headersToSet['Content-Type'];
|
|
183
|
+
|
|
184
|
+
Object.keys(headersToSet).forEach((key) => {
|
|
185
|
+
xhr.setRequestHeader(key, headersToSet[key]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
xhr.upload.onprogress = (event) => {
|
|
189
|
+
if (event.lengthComputable) {
|
|
190
|
+
onUploadProgress(event.loaded / event.total);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
xhr.onload = async () => {
|
|
195
|
+
try {
|
|
196
|
+
let parsedJson;
|
|
197
|
+
try {
|
|
198
|
+
parsedJson = JSON.parse(xhr.responseText);
|
|
199
|
+
} catch (err) {
|
|
200
|
+
parsedJson = xhr.responseText;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (parsedJson?.error === 'DISABLED_FOR_DEMO') {
|
|
204
|
+
if (browser) {
|
|
205
|
+
await show("components.toasts.demo-mode-restricted");
|
|
206
|
+
}
|
|
207
|
+
resolve();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const finalData = handler ? await handler(parsedJson, rejectFn) : parsedJson;
|
|
212
|
+
resolve(finalData);
|
|
213
|
+
} catch (err) {
|
|
214
|
+
rejectFn(err);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
xhr.onerror = () => rejectFn('NETWORK_ERROR');
|
|
219
|
+
|
|
220
|
+
xhr.send(data.body);
|
|
221
|
+
}).catch(reject);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Perform fetch request
|
|
225
|
+
const fetchMethod =
|
|
226
|
+
request && request.fetch ? request.fetch(path, options) : fetch(path, options);
|
|
227
|
+
|
|
228
|
+
// Handle response
|
|
229
|
+
return fetchMethod
|
|
230
|
+
.then(bodyHandler)
|
|
231
|
+
.then(jsonParseHandler)
|
|
232
|
+
.then(async (parsedJson) => {
|
|
233
|
+
if (parsedJson?.error === 'DISABLED_FOR_DEMO') {
|
|
234
|
+
if (browser) {
|
|
235
|
+
await show("components.toasts.demo-mode-restricted");
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
return handler ? await handler(parsedJson, reject) : parsedJson;
|
|
240
|
+
})
|
|
241
|
+
.catch(reject);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
return requestCall();
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export default ApiUtil;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import tippy from 'tippy.js';
|
|
2
|
+
import 'tippy.js/dist/tippy.css';
|
|
3
|
+
import { page } from '$app/stores';
|
|
4
|
+
|
|
5
|
+
function setTooltip(element, [value, options]) {
|
|
6
|
+
const instance = typeof element._tippy === 'undefined' ? tippy(element) : element._tippy;
|
|
7
|
+
|
|
8
|
+
instance.setContent(value);
|
|
9
|
+
instance.setProps(options);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function tooltip(element, properties) {
|
|
13
|
+
let unsubscribePage;
|
|
14
|
+
let instance;
|
|
15
|
+
|
|
16
|
+
const init = (props) => {
|
|
17
|
+
if (!props) return;
|
|
18
|
+
|
|
19
|
+
let [value, options] = props;
|
|
20
|
+
if (!value) {
|
|
21
|
+
if (instance) instance.destroy();
|
|
22
|
+
instance = null;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!instance) {
|
|
27
|
+
instance = tippy(element);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const mergedOptions = {
|
|
31
|
+
content: value,
|
|
32
|
+
placement: 'bottom',
|
|
33
|
+
interactive: true,
|
|
34
|
+
animation: 'fade',
|
|
35
|
+
...options
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
instance.setProps(mergedOptions);
|
|
39
|
+
|
|
40
|
+
if (!unsubscribePage) {
|
|
41
|
+
unsubscribePage = page.subscribe(() => {
|
|
42
|
+
if (instance) instance.hide();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
init(properties);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
update(updatedProperties) {
|
|
51
|
+
init(updatedProperties);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
destroy() {
|
|
55
|
+
if (instance) instance.destroy();
|
|
56
|
+
if (unsubscribePage) unsubscribePage();
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export let API_URL = import.meta.env.VITE_API_URL;
|
|
2
|
+
export const UI_URL = import.meta.env.VITE_UI_URL;
|
|
3
|
+
export const PANEL_URL = import.meta.env.VITE_PANEL_URL;
|
|
4
|
+
export const SETUP_URL = import.meta.env.VITE_SETUP_URL;
|
|
5
|
+
export let PANO_WEBSITE_URL = import.meta.env.VITE_PANO_WEBSITE_URL;
|
|
6
|
+
export let PANO_WEBSITE_API_URL = import.meta.env.VITE_PANO_WEBSITE_API_URL;
|
|
7
|
+
export const PRERELEASE = import.meta.env.VITE_PRERELEASE;
|
|
8
|
+
|
|
9
|
+
export const COOKIE_PREFIX = import.meta.env.VITE_COOKIE_PREFIX;
|
|
10
|
+
|
|
11
|
+
export const CSRF_TOKEN_COOKIE_NAME = 'csrf_token';
|
|
12
|
+
export const JWT_COOKIE_NAME = 'auth_token';
|
|
13
|
+
|
|
14
|
+
export const CSRF_HEADER = 'X-CSRF-Token';
|
|
15
|
+
|
|
16
|
+
export function checkDomainRedirection() {
|
|
17
|
+
if (typeof window === 'undefined' || !API_URL || API_URL.startsWith('/')) return;
|
|
18
|
+
|
|
19
|
+
// In production API_URL is the Pano host's internal backend address (loopback or
|
|
20
|
+
// server.host:internal-port) — never a browser-reachable origin, so redirecting on it
|
|
21
|
+
// would bounce reverse-proxied visitors to the internal port. Canonical-host redirects
|
|
22
|
+
// are owned by the backend (WebsiteUrlRedirectHandler); this helper only smooths the
|
|
23
|
+
// dev workflow: hitting a vite dev port directly bounces you into the Pano dev server.
|
|
24
|
+
if (!import.meta.env.DEV) return;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const apiUrl = new URL(API_URL);
|
|
28
|
+
const currentUrl = new URL(window.location.href);
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
currentUrl.hostname !== apiUrl.hostname ||
|
|
32
|
+
currentUrl.port !== apiUrl.port ||
|
|
33
|
+
currentUrl.protocol !== apiUrl.protocol
|
|
34
|
+
) {
|
|
35
|
+
const basePath = UI_URL || PANEL_URL || SETUP_URL || '/';
|
|
36
|
+
let pathname = currentUrl.pathname;
|
|
37
|
+
|
|
38
|
+
if (basePath !== '/' && !pathname.startsWith(basePath)) {
|
|
39
|
+
pathname = basePath + (pathname === '/' ? '' : pathname);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const targetUrl = new URL(pathname + currentUrl.search + currentUrl.hash, apiUrl.origin);
|
|
43
|
+
window.location.href = targetUrl.toString();
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error('Failed to check domain redirection:', e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function updateApiUrl(apiUrl) {
|
|
51
|
+
API_URL = apiUrl;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function updatePanoWebsiteUrl(panoWebsiteUrl) {
|
|
55
|
+
PANO_WEBSITE_URL = panoWebsiteUrl;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function updatePanoWebsiteApiUrl(panoWebsiteApiUrl) {
|
|
59
|
+
PANO_WEBSITE_API_URL = panoWebsiteApiUrl;
|
|
60
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Matches Kotlin `VersionUtil.isSemVer` (optional leading v tag). */
|
|
2
|
+
function isSemVer(version) {
|
|
3
|
+
return /^v?\d+\.\d+\.\d+(-[\w.]+)?$/.test(version);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Kotlin `parseVersion(removePrefix(version, "v"))` with hyphen split limited to core + prerelease remainder. */
|
|
7
|
+
function parseVersion(version) {
|
|
8
|
+
const cleanVersion = version.replace(/^v/, '');
|
|
9
|
+
const hyphen = cleanVersion.indexOf('-');
|
|
10
|
+
const corePart = hyphen === -1 ? cleanVersion : cleanVersion.slice(0, hyphen);
|
|
11
|
+
const preRaw = hyphen === -1 ? '' : cleanVersion.slice(hyphen + 1);
|
|
12
|
+
const coreParts = corePart.split('.').map((p) => Number(p));
|
|
13
|
+
const preParts = preRaw
|
|
14
|
+
? preRaw.split('.').map((part) => {
|
|
15
|
+
const parsed = /^-?\d+$/.test(part) ? Number(part) : NaN;
|
|
16
|
+
return Number.isNaN(parsed) ? part : parsed;
|
|
17
|
+
})
|
|
18
|
+
: [];
|
|
19
|
+
return { coreParts, preParts };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Kotlin `compareVersions`; does not coerce non-tags (opaque tags compare only via `===`). */
|
|
23
|
+
export function compareVersions(a, b) {
|
|
24
|
+
const isASemVer = isSemVer(a);
|
|
25
|
+
const isBSemVer = isSemVer(b);
|
|
26
|
+
|
|
27
|
+
if (!isASemVer && !isBSemVer) return 0;
|
|
28
|
+
if (!isASemVer) return -1;
|
|
29
|
+
if (!isBSemVer) return 1;
|
|
30
|
+
|
|
31
|
+
const va = parseVersion(a);
|
|
32
|
+
const vb = parseVersion(b);
|
|
33
|
+
|
|
34
|
+
const len = Math.max(va.coreParts.length, vb.coreParts.length);
|
|
35
|
+
for (let i = 0; i < len; i++) {
|
|
36
|
+
const ai = va.coreParts[i] || 0;
|
|
37
|
+
const bi = vb.coreParts[i] || 0;
|
|
38
|
+
if (ai !== bi) return ai - bi;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const prePriority = ['alpha', 'beta'];
|
|
42
|
+
|
|
43
|
+
const isAPre = va.preParts.length > 0;
|
|
44
|
+
const isBPre = vb.preParts.length > 0;
|
|
45
|
+
|
|
46
|
+
if (!isAPre && isBPre) return 1;
|
|
47
|
+
if (isAPre && !isBPre) return -1;
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < Math.max(va.preParts.length, vb.preParts.length); i++) {
|
|
50
|
+
const ap = va.preParts[i];
|
|
51
|
+
const bp = vb.preParts[i];
|
|
52
|
+
if (ap === bp) continue;
|
|
53
|
+
|
|
54
|
+
if (typeof ap === 'string' && typeof bp === 'string') {
|
|
55
|
+
const ai = prePriority.indexOf(ap);
|
|
56
|
+
const bi = prePriority.indexOf(bp);
|
|
57
|
+
return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi);
|
|
58
|
+
}
|
|
59
|
+
if (typeof ap === 'number' && typeof bp === 'number') return ap - bp;
|
|
60
|
+
return typeof ap === 'string' ? -1 : 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Kotlin `isVersionHigher` — installed `local-build` is treated below any normal semver release. */
|
|
67
|
+
export function isStoreVersionHigher(latestPublishedTag, installedTag) {
|
|
68
|
+
const normalizedInstalled =
|
|
69
|
+
installedTag === 'local-build' ? 'v1.0.0-alpha.0' : installedTag;
|
|
70
|
+
return compareVersions(latestPublishedTag, normalizedInstalled) > 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Same release according to Kotlin store rules (exact tag strings or semver-equal, including optional `v`).
|
|
75
|
+
*/
|
|
76
|
+
export function areStoreVersionTagsEqual(a, b) {
|
|
77
|
+
if (a === b) return true;
|
|
78
|
+
if (a == null || b == null) return false;
|
|
79
|
+
if (!isSemVer(a) || !isSemVer(b)) return false;
|
|
80
|
+
return compareVersions(a, b) === 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isPanoVersionCompatible(current, required) {
|
|
84
|
+
if (current === 'local-build') return true;
|
|
85
|
+
if (!isSemVer(current) || !isSemVer(required)) return false;
|
|
86
|
+
|
|
87
|
+
const currentParsed = parseVersion(current);
|
|
88
|
+
const requiredParsed = parseVersion(required);
|
|
89
|
+
|
|
90
|
+
const coreEqual =
|
|
91
|
+
JSON.stringify(currentParsed.coreParts) === JSON.stringify(requiredParsed.coreParts);
|
|
92
|
+
|
|
93
|
+
const requiredIsPre = requiredParsed.preParts.length > 0;
|
|
94
|
+
|
|
95
|
+
if (coreEqual && !requiredIsPre) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return compareVersions(current, required) >= 0;
|
|
100
|
+
}
|