@panomc/sdk 1.0.0-dev.9 → 2.0.0-dev.61
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/api/routes.core.json +3702 -0
- package/bin/api/__tests__/api-compat.test.mjs +97 -0
- package/bin/api/__tests__/check-paths.test.mjs +113 -0
- package/bin/api/__tests__/cli.test.mjs +44 -0
- package/bin/api/__tests__/extract-routes.test.mjs +132 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/api/paths.old-new.json +82 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
- package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
- package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
- package/bin/api/__tests__/fixtures/plugin-new/api/paths.old-new.json +66 -0
- package/bin/api/__tests__/fixtures/plugin-new/build.gradle.kts +42 -0
- package/bin/api/__tests__/fixtures/plugin-new/gradle.properties +4 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/panel/Things.js +4 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/theme/Logo.svelte +9 -0
- package/bin/api/__tests__/fixtures/plugin-new/src/theme/api.js +29 -0
- package/bin/api/__tests__/fixtures/plugin-old/build.gradle.kts +22 -0
- package/bin/api/__tests__/fixtures/plugin-old/gradle.properties +4 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/panel/Things.js +4 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/theme/Logo.svelte +9 -0
- package/bin/api/__tests__/fixtures/plugin-old/src/theme/api.js +29 -0
- package/bin/api/__tests__/fixtures/refusals/gradle.properties +1 -0
- package/bin/api/__tests__/fixtures/refusals/src/main/kotlin/x/Bad.kt +39 -0
- package/bin/api/__tests__/fixtures/unresolved/src/main/kotlin/x/Orphan.kt +19 -0
- package/bin/api/__tests__/helpers.mjs +48 -0
- package/bin/api/__tests__/migrate-v1.test.mjs +377 -0
- package/bin/api/__tests__/openapi-snapshot.test.mjs +120 -0
- package/bin/api/api-compat.mjs +204 -0
- package/bin/api/check-paths.mjs +135 -0
- package/bin/api/cli.mjs +83 -0
- package/bin/api/extract-routes.mjs +129 -0
- package/bin/api/js-scan.mjs +337 -0
- package/bin/api/kotlin.mjs +366 -0
- package/bin/api/migrate-v1.mjs +330 -0
- package/bin/api/openapi-snapshot.mjs +112 -0
- package/bin/api/project.mjs +172 -0
- package/bin/api/rename-table.mjs +66 -0
- package/bin/api/util.mjs +194 -0
- package/bin/pano-api.js +5 -0
- package/build/plugin-api-rollup.js +46 -0
- package/core/css/pano-tokens.css +225 -0
- 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/ControllerRegistry.js +421 -0
- package/core/js/NotificationManager.js +62 -0
- package/core/js/PluginAPI.js +39 -0
- package/core/js/PluginManager.js +851 -0
- package/core/js/RouteMatcher.js +142 -0
- package/core/js/__tests__/ControllerRegistry.test.js +378 -0
- package/core/js/__tests__/NotificationManager.test.js +57 -0
- package/core/js/__tests__/PluginAPI.test.js +25 -0
- package/core/js/__tests__/RouteMatcher.test.js +33 -0
- package/core/js/__tests__/accessClient.test.js +582 -0
- package/core/js/__tests__/api.util.v1.test.js +336 -0
- package/core/js/__tests__/devBounce.test.js +28 -0
- package/core/js/__tests__/html.util.test.js +18 -0
- package/core/js/__tests__/pluginFolder.util.test.js +106 -0
- package/core/js/__tests__/pluginPackage.test.js +134 -0
- package/core/js/__tests__/pluginUiZip.test.js +47 -0
- package/core/js/__tests__/sdkLevel.test.js +34 -0
- package/core/js/api.util.js +433 -0
- package/core/js/html.util.js +26 -0
- package/core/js/pluginFolder.util.js +95 -0
- package/core/js/tooltip.util.js +59 -0
- package/core/js/variables.js +95 -0
- package/core/js/version.util.js +100 -0
- package/core/scss/_pano-tokens.scss +51 -0
- package/core/scss/custom-bootstrap.scss +196 -0
- package/core/scss/fonts.scss +85 -0
- package/core/scss/main.scss +389 -0
- package/core/scss/themes.scss +120 -0
- package/package.json +50 -10
- package/src/__tests__/controllers.test.js +220 -0
- package/src/__tests__/views.spike.test.js +472 -0
- package/src/components/{index.js → panel.js} +9 -7
- package/src/components/theme.js +18 -0
- package/src/controllers.js +127 -0
- package/src/index.js +1 -1
- package/src/svelte.js +3 -2
- package/src/types.js +5 -3
- package/src/utils/api.js +42 -1
- package/src/utils/auth.js +8 -0
- package/src/utils/component.js +4 -2
- package/src/utils/route.js +16 -0
- package/src/utils/text.js +8 -0
- package/src/views.js +29 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, mock, spyOn, test } from 'bun:test';
|
|
2
|
+
import { get } from 'svelte/store';
|
|
3
|
+
|
|
4
|
+
// TC-70: a plugin module without `panoSdk === 2` was built for @panomc/sdk 1.x and is skipped.
|
|
5
|
+
|
|
6
|
+
mock.module('$lib/api.util.js', () => ({ default: {} }));
|
|
7
|
+
mock.module('$lib/PluginAPI.js', () => ({ init: () => {}, panoApiClient: {}, panoApiServer: {} }));
|
|
8
|
+
mock.module('$app/environment', () => ({ browser: false, dev: false }));
|
|
9
|
+
mock.module('$app/paths', () => ({ base: '' }));
|
|
10
|
+
mock.module('@sveltejs/kit', () => ({ error: (status) => new Error(`HTTP ${status}`) }));
|
|
11
|
+
|
|
12
|
+
const manager = await import('../PluginManager.js');
|
|
13
|
+
|
|
14
|
+
describe('dropOldSdkPlugins', () => {
|
|
15
|
+
test('a 1.x module is skipped with the rebuild message; a 2.x module stays', () => {
|
|
16
|
+
const spy = spyOn(console, 'error').mockImplementation(() => {});
|
|
17
|
+
manager.plugins.set({
|
|
18
|
+
old: { module: { default: class {} } },
|
|
19
|
+
wrong: { module: { default: class {}, panoSdk: 1 } },
|
|
20
|
+
fresh: { module: { default: class {}, panoSdk: 2 } },
|
|
21
|
+
unloaded: {},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const skipped = manager.dropOldSdkPlugins();
|
|
25
|
+
const messages = spy.mock.calls.map((call) => String(call[0]));
|
|
26
|
+
spy.mockRestore();
|
|
27
|
+
|
|
28
|
+
expect(skipped).toEqual(['old', 'wrong']);
|
|
29
|
+
expect(Object.keys(get(manager.plugins))).toEqual(['fresh', 'unloaded']);
|
|
30
|
+
expect(messages).toContain(
|
|
31
|
+
'[Plugin Manager] old was built for @panomc/sdk 1.x and does not load on this Pano; rebuild it with @panomc/plugin-kit',
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,433 @@
|
|
|
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 = { error: { code: NETWORK_ERROR } };
|
|
11
|
+
export const DISABLED_FOR_DEMO = 'DISABLED_FOR_DEMO';
|
|
12
|
+
|
|
13
|
+
/** Prefix of the whole API when the backend base (`API_URL`) ends in `/api` (doc 04 section 9). */
|
|
14
|
+
const API_VERSION_PREFIX = '/api/v1';
|
|
15
|
+
|
|
16
|
+
/** Prefix of the plugin namespace (decision 81): plugin endpoints are unversioned, `/api/plugins/<id>/...`. */
|
|
17
|
+
const API_PLUGIN_PREFIX = '/api';
|
|
18
|
+
|
|
19
|
+
const NETWORK_RETRY_DELAY_MS = 400;
|
|
20
|
+
|
|
21
|
+
function isIdempotent(method) {
|
|
22
|
+
return !method || ['GET', 'HEAD', 'OPTIONS'].includes(method.toUpperCase());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The browser's cached answer of `GET /auth/csrf` (doc 05 section 4): the promise of the token, `null`
|
|
27
|
+
* when the visitor has no cookie session. Kept in the browser only; on the server one module serves every
|
|
28
|
+
* visitor, so nothing is cached there.
|
|
29
|
+
* @type {Promise<string | null> | undefined}
|
|
30
|
+
*/
|
|
31
|
+
let fetchedCsrfToken;
|
|
32
|
+
|
|
33
|
+
/** Forget the token fetched from `GET /auth/csrf` (a test, or a client that knows the session changed). */
|
|
34
|
+
export function resetFetchedCsrfToken() {
|
|
35
|
+
fetchedCsrfToken = undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Ask Pano for the session's CSRF token. Used before a mutation when the page session has none (a front-end
|
|
40
|
+
* on another origin, or a page whose data carries no session): a cookie session answers `{ csrfToken }`, a
|
|
41
|
+
* Bearer or anonymous request gets `null` (`401` is "no live cookie session", not an error).
|
|
42
|
+
*
|
|
43
|
+
* @param {{ fetch?: typeof fetch } | undefined} request SvelteKit's `load` / event, whose `fetch` is used on the server
|
|
44
|
+
* @returns {Promise<string | null>}
|
|
45
|
+
*/
|
|
46
|
+
async function loadCsrfToken(request) {
|
|
47
|
+
const url = resolveApiUrl('/auth/csrf', {
|
|
48
|
+
apiUrl: API_URL,
|
|
49
|
+
hasEventFetch: !!(request && request.fetch),
|
|
50
|
+
browser,
|
|
51
|
+
prod: !!import.meta.env.PROD,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const response = await (request && request.fetch ? request.fetch : fetch)(url, {
|
|
56
|
+
credentials: 'include',
|
|
57
|
+
cache: 'no-store',
|
|
58
|
+
headers: { Accept: 'application/json' },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (!response.ok) return null;
|
|
62
|
+
|
|
63
|
+
const body = await response.json();
|
|
64
|
+
|
|
65
|
+
return typeof body?.csrfToken === 'string' && body.csrfToken ? body.csrfToken : null;
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The CSRF token for a mutation that has none: fetched once in the browser, per call on the server. */
|
|
72
|
+
function resolveCsrfToken(request) {
|
|
73
|
+
if (!browser) return loadCsrfToken(request);
|
|
74
|
+
|
|
75
|
+
fetchedCsrfToken ??= loadCsrfToken(request);
|
|
76
|
+
|
|
77
|
+
return fetchedCsrfToken;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A refused request means the session behind a cached token may be gone: ask again next time. */
|
|
81
|
+
function noteStatus(response) {
|
|
82
|
+
if (response && (response.status === 401 || response.status === 403)) fetchedCsrfToken = undefined;
|
|
83
|
+
|
|
84
|
+
return response;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Function to build query parameters from an object
|
|
88
|
+
export function buildQueryParams(params) {
|
|
89
|
+
const queryString = Object.keys(params)
|
|
90
|
+
.filter((key) => params[key])
|
|
91
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
|
92
|
+
.join('&');
|
|
93
|
+
return queryString === '' ? '' : '?' + queryString;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const isWebsiteApi = (apiUrl) => typeof apiUrl === 'string' && apiUrl.includes('.panomc.com');
|
|
97
|
+
|
|
98
|
+
const isLoopbackApi = (apiUrl) =>
|
|
99
|
+
typeof apiUrl === 'string' &&
|
|
100
|
+
(apiUrl.includes('0.0.0.0') || apiUrl.includes('127.0.0.1') || apiUrl.includes('localhost'));
|
|
101
|
+
|
|
102
|
+
/** A path that still carries the `/api` prefix (`/api`, `/api/...`, `/api?x`), but not `/apiary`. */
|
|
103
|
+
const startsWithApi = (path) => /^\/api(?:[/?#]|$)/.test(path);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A plugin's own endpoint path: `/plugins/<id>/...` or `/api/plugins/<id>/...`, anything but core's `/plugins/<id>/_/...`.
|
|
107
|
+
* These live outside `/api/v1` (decision 81), so `ApiUtil` sends them to `/api/plugins/<id>/...` whichever form came in.
|
|
108
|
+
* @param {string} path
|
|
109
|
+
*/
|
|
110
|
+
export const isPluginOwnPath = (path) =>
|
|
111
|
+
typeof path === 'string' && /^\/(?:api\/)?plugins\/[^/?#]+\/(?!_(?:[/?#]|$))[^?#]/.test(path);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Callers pass paths relative to `/api/v1` ("/posts"). A missing leading slash is added.
|
|
115
|
+
* In dev a path that starts with `/api` throws (the website API has no `/v1`, so it is exempt).
|
|
116
|
+
*
|
|
117
|
+
* @param {string} path
|
|
118
|
+
* @param {{ website?: boolean, prod?: boolean }} [opts]
|
|
119
|
+
* @returns {string} the path with a leading slash
|
|
120
|
+
*/
|
|
121
|
+
export function normalizeApiPath(path, { website = false, prod = false } = {}) {
|
|
122
|
+
if (typeof path !== 'string') throw new TypeError('[pano] api path must be a string');
|
|
123
|
+
|
|
124
|
+
const normalized = path.startsWith('/') ? path : `/${path}`;
|
|
125
|
+
|
|
126
|
+
if (!website && !prod && startsWithApi(normalized)) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`[pano] path must not start with /api: write '${normalized.replace(/^\/api/, '') || '/'}'`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return normalized;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The URL of one call: exactly the four cases of doc 04 section 9, no pass-through.
|
|
137
|
+
*
|
|
138
|
+
* 1. `apiUrl` contains `.panomc.com` (the website; its API has no `/v1`): `apiUrl + path`.
|
|
139
|
+
* 2. `hasEventFetch` (SSR `load` behind the proxy): relative `/api/v1` + path, so SSR and CSR dedupe.
|
|
140
|
+
* 3. browser, and production or a loopback `apiUrl`: `/api/v1` + path.
|
|
141
|
+
* 4. everything else (SSR without an event, not initialised): `apiUrl + '/v1' + path`.
|
|
142
|
+
*
|
|
143
|
+
* With `unversioned` (a plugin's own endpoints, `/plugins/<id>/...`, decision 81) the same four cases apply but the
|
|
144
|
+
* version segment is left out: `/api` + path, or `apiUrl + path`.
|
|
145
|
+
*
|
|
146
|
+
* @param {string} path relative to `/api/v1` (relative to `/api` with `unversioned`)
|
|
147
|
+
* @param {{ apiUrl?: string, hasEventFetch?: boolean, browser?: boolean, prod?: boolean, unversioned?: boolean }} ctx
|
|
148
|
+
* @returns {string}
|
|
149
|
+
*/
|
|
150
|
+
export function resolveApiUrl(
|
|
151
|
+
path,
|
|
152
|
+
{ apiUrl = '', hasEventFetch = false, browser = false, prod = false, unversioned = false } = {},
|
|
153
|
+
) {
|
|
154
|
+
const website = isWebsiteApi(apiUrl);
|
|
155
|
+
const relative = normalizeApiPath(path, { website, prod });
|
|
156
|
+
const root = unversioned ? API_PLUGIN_PREFIX : API_VERSION_PREFIX;
|
|
157
|
+
|
|
158
|
+
if (website) return `${apiUrl.replace(/\/+$/, '')}${relative}`;
|
|
159
|
+
if (hasEventFetch) return `${root}${relative}`;
|
|
160
|
+
if (browser && (prod || isLoopbackApi(apiUrl))) return `${root}${relative}`;
|
|
161
|
+
|
|
162
|
+
return `${(apiUrl || '/api').replace(/\/+$/, '')}${unversioned ? '' : '/v1'}${relative}`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const ApiUtil = {
|
|
166
|
+
interceptors: {},
|
|
167
|
+
|
|
168
|
+
// GET request
|
|
169
|
+
async get({ path, request, csrfToken, token, blob, handler, unversioned }) {
|
|
170
|
+
return this.customRequest({
|
|
171
|
+
path,
|
|
172
|
+
unversioned,
|
|
173
|
+
request,
|
|
174
|
+
csrfToken,
|
|
175
|
+
token,
|
|
176
|
+
blob,
|
|
177
|
+
handler,
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
// POST request
|
|
182
|
+
async post({ path, request, body, headers, csrfToken, token, blob, handler, onUploadProgress, unversioned }) {
|
|
183
|
+
return this.customRequest({
|
|
184
|
+
path,
|
|
185
|
+
unversioned,
|
|
186
|
+
data: { method: 'POST', credentials: 'include', body, headers },
|
|
187
|
+
request,
|
|
188
|
+
csrfToken,
|
|
189
|
+
token,
|
|
190
|
+
blob,
|
|
191
|
+
handler,
|
|
192
|
+
onUploadProgress,
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
// PUT request
|
|
197
|
+
async put({ path, request, body, headers, csrfToken, token, blob, handler, onUploadProgress, unversioned }) {
|
|
198
|
+
return this.customRequest({
|
|
199
|
+
path,
|
|
200
|
+
unversioned,
|
|
201
|
+
data: { method: 'PUT', credentials: 'include', body, headers },
|
|
202
|
+
request,
|
|
203
|
+
csrfToken,
|
|
204
|
+
token,
|
|
205
|
+
blob,
|
|
206
|
+
handler,
|
|
207
|
+
onUploadProgress,
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
// DELETE request
|
|
212
|
+
async delete({ path, request, headers, csrfToken, token, blob, handler, unversioned }) {
|
|
213
|
+
return this.customRequest({
|
|
214
|
+
path,
|
|
215
|
+
unversioned,
|
|
216
|
+
data: { method: 'DELETE', headers },
|
|
217
|
+
request,
|
|
218
|
+
csrfToken,
|
|
219
|
+
token,
|
|
220
|
+
blob,
|
|
221
|
+
handler,
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
// Custom request handler
|
|
226
|
+
async customRequest({ path, data = {}, request, csrfToken, token, blob, handler, onUploadProgress, unversioned }) {
|
|
227
|
+
// Retrieve CSRF token if not provided
|
|
228
|
+
if (!csrfToken) {
|
|
229
|
+
let session;
|
|
230
|
+
if (request && typeof request.parent === "function") {
|
|
231
|
+
const parentData = await request.parent();
|
|
232
|
+
session = parentData.session;
|
|
233
|
+
} else if (browser && get(page).data) {
|
|
234
|
+
session = get(page).data.session;
|
|
235
|
+
}
|
|
236
|
+
csrfToken = session && session.csrfToken;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// A mutation on a cookie session needs the header (doc 05 section 4). When the page session has no token,
|
|
240
|
+
// ask `GET /auth/csrf` once. A Bearer call (`token`) never needs it.
|
|
241
|
+
if (!csrfToken && !token && !isIdempotent(data.method)) {
|
|
242
|
+
csrfToken = await resolveCsrfToken(request);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Set CSRF header if token is available
|
|
246
|
+
const CSRFHeader = csrfToken ? { [CSRF_HEADER]: csrfToken } : {};
|
|
247
|
+
|
|
248
|
+
// Convert body to JSON string if not FormData
|
|
249
|
+
if (!(data.body instanceof FormData)) {
|
|
250
|
+
data.body = JSON.stringify(data.body);
|
|
251
|
+
data.headers = { 'Content-Type': 'application/json', ...data.headers };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Set request options
|
|
255
|
+
const options = {
|
|
256
|
+
...data,
|
|
257
|
+
headers: { ...data.headers, ...CSRFHeader },
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// Add Authorization header if token is provided
|
|
261
|
+
if (token) {
|
|
262
|
+
options.headers['Authorization'] = `Bearer ${token}`;
|
|
263
|
+
} else if ('credentials' in Request.prototype) {
|
|
264
|
+
options['credentials'] = 'include';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// A plugin's own path (`/plugins/<id>/...`) is unversioned: `/api/plugins/<id>/...` (decision 81).
|
|
268
|
+
if (!unversioned && isPluginOwnPath(path)) {
|
|
269
|
+
unversioned = true;
|
|
270
|
+
path = path.replace(/^\/api(?=\/plugins\/)/, '');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Callers pass paths relative to /api/v1; see resolveApiUrl for the four cases.
|
|
274
|
+
path = resolveApiUrl(path, {
|
|
275
|
+
apiUrl: API_URL,
|
|
276
|
+
hasEventFetch: !!(request && request.fetch),
|
|
277
|
+
browser,
|
|
278
|
+
prod: !!import.meta.env.PROD,
|
|
279
|
+
unversioned: !!unversioned,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const bodyHandler = (response) => (blob ? response.blob() : response.text());
|
|
283
|
+
const jsonParseHandler = (json) => {
|
|
284
|
+
try {
|
|
285
|
+
return JSON.parse(json);
|
|
286
|
+
} catch (err) {
|
|
287
|
+
return json;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const requestCall = (rejectHandler) => {
|
|
292
|
+
const reject = async (err) => {
|
|
293
|
+
console.log(err);
|
|
294
|
+
if (rejectHandler) {
|
|
295
|
+
throw new Error(err);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (this.interceptors.errorHandler && handler) {
|
|
299
|
+
this.interceptors.errorHandler(requestCall);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// A failure without a response is an envelope too: callers read `error.code`.
|
|
303
|
+
return networkErrorBody;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
if (onUploadProgress && browser && data.body instanceof FormData) {
|
|
307
|
+
return new Promise((resolve, rejectFn) => {
|
|
308
|
+
const xhr = new XMLHttpRequest();
|
|
309
|
+
xhr.open(data.method, path);
|
|
310
|
+
|
|
311
|
+
if (options.credentials === 'include') {
|
|
312
|
+
xhr.withCredentials = true;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const headersToSet = { ...options.headers };
|
|
316
|
+
delete headersToSet['Content-Type'];
|
|
317
|
+
|
|
318
|
+
Object.keys(headersToSet).forEach((key) => {
|
|
319
|
+
xhr.setRequestHeader(key, headersToSet[key]);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
xhr.upload.onprogress = (event) => {
|
|
323
|
+
if (event.lengthComputable) {
|
|
324
|
+
onUploadProgress(event.loaded / event.total);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
xhr.onload = async () => {
|
|
329
|
+
try {
|
|
330
|
+
let parsedJson;
|
|
331
|
+
try {
|
|
332
|
+
parsedJson = JSON.parse(xhr.responseText);
|
|
333
|
+
} catch (err) {
|
|
334
|
+
parsedJson = xhr.responseText;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (parsedJson?.error?.code === DISABLED_FOR_DEMO) {
|
|
338
|
+
if (browser) {
|
|
339
|
+
await show("components.toasts.demo-mode-restricted");
|
|
340
|
+
}
|
|
341
|
+
resolve();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const finalData = handler ? await handler(parsedJson, rejectFn) : parsedJson;
|
|
346
|
+
resolve(finalData);
|
|
347
|
+
} catch (err) {
|
|
348
|
+
rejectFn(err);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
xhr.onerror = () => rejectFn(NETWORK_ERROR);
|
|
353
|
+
|
|
354
|
+
xhr.send(data.body);
|
|
355
|
+
}).catch(reject);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Perform fetch request
|
|
359
|
+
const doFetch = () =>
|
|
360
|
+
(request && request.fetch ? request.fetch(path, options) : fetch(path, options)).then(noteStatus);
|
|
361
|
+
|
|
362
|
+
// A request that never got a response (fetch rejected) is retried ONCE before the
|
|
363
|
+
// offline splash: browsers reuse a pooled HTTP/3 connection that the peer may have
|
|
364
|
+
// just idled out (Firefox: 30 s), and the request on it fails instantly although the
|
|
365
|
+
// server is fine. A new connection succeeds. Only idempotent methods, so a POST/PUT
|
|
366
|
+
// is never sent twice; HTTP error responses are not retried (fetch resolves them).
|
|
367
|
+
const fetchMethod =
|
|
368
|
+
browser && isIdempotent(data.method)
|
|
369
|
+
? doFetch().catch((err) => {
|
|
370
|
+
if (err?.name === 'AbortError') throw err;
|
|
371
|
+
|
|
372
|
+
return new Promise((resolve) => setTimeout(resolve, NETWORK_RETRY_DELAY_MS)).then(
|
|
373
|
+
doFetch,
|
|
374
|
+
);
|
|
375
|
+
})
|
|
376
|
+
: doFetch();
|
|
377
|
+
|
|
378
|
+
// Handle response
|
|
379
|
+
return fetchMethod
|
|
380
|
+
.then(bodyHandler)
|
|
381
|
+
.then(jsonParseHandler)
|
|
382
|
+
.then(async (parsedJson) => {
|
|
383
|
+
if (parsedJson?.error?.code === DISABLED_FOR_DEMO) {
|
|
384
|
+
if (browser) {
|
|
385
|
+
await show("components.toasts.demo-mode-restricted");
|
|
386
|
+
}
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
return handler ? await handler(parsedJson, reject) : parsedJson;
|
|
390
|
+
})
|
|
391
|
+
.catch(reject);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
return requestCall();
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const PLUGIN_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Plugin-scoped client (doc 04 section 9). `createPluginApi('pano-plugin-market').get({ path: '/store/products' })`
|
|
402
|
+
* calls `/api/plugins/pano-plugin-market/store/products`; `.panel.get(...)` calls
|
|
403
|
+
* `/api/plugins/pano-plugin-market/panel/...` (decision 81: plugin endpoints are unversioned). Every method takes the options of the matching `ApiUtil` method.
|
|
404
|
+
* A path that starts with `/api` throws in dev, as it does for `ApiUtil`.
|
|
405
|
+
*
|
|
406
|
+
* @param {string} pluginId the full plugin id (`pano-plugin-market`), never the short namespace
|
|
407
|
+
*/
|
|
408
|
+
export function createPluginApi(pluginId) {
|
|
409
|
+
if (typeof pluginId !== 'string' || !PLUGIN_ID_PATTERN.test(pluginId)) {
|
|
410
|
+
throw new Error(`[pano] createPluginApi needs the full plugin id, got ${JSON.stringify(pluginId)}`);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const scoped = (prefix) => {
|
|
414
|
+
const wrap = (method) => async (options = {}) =>
|
|
415
|
+
ApiUtil[method]({
|
|
416
|
+
...options,
|
|
417
|
+
unversioned: true,
|
|
418
|
+
path: `${prefix}${normalizeApiPath(options.path, { prod: !!import.meta.env.PROD })}`,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
return {
|
|
422
|
+
get: wrap('get'),
|
|
423
|
+
post: wrap('post'),
|
|
424
|
+
put: wrap('put'),
|
|
425
|
+
delete: wrap('delete'),
|
|
426
|
+
customRequest: wrap('customRequest'),
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
return { ...scoped(`/plugins/${pluginId}`), panel: scoped(`/plugins/${pluginId}/panel`) };
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export default ApiUtil;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const ESCAPES = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Escapes the five HTML special characters.
|
|
5
|
+
* @param {unknown} s
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function escapeHtml(s) {
|
|
9
|
+
return String(s).replace(/[&<>"']/g, (c) => ESCAPES[c]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Shallow copy of `values` with string values HTML-escaped; other values are untouched.
|
|
14
|
+
* A non-object yields `{}`.
|
|
15
|
+
* @param {unknown} values
|
|
16
|
+
* @returns {Record<string, unknown>}
|
|
17
|
+
*/
|
|
18
|
+
export function escapeValues(values) {
|
|
19
|
+
if (values === null || typeof values !== 'object' || Array.isArray(values)) return {};
|
|
20
|
+
|
|
21
|
+
const out = {};
|
|
22
|
+
for (const [k, v] of Object.entries(values)) {
|
|
23
|
+
out[k] = typeof v === 'string' ? escapeHtml(v) : v;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
// plugins/<pluginId>/ is shared with the backend: it is also the plugin's data folder
|
|
5
|
+
// (config.conf, secret.key, ...). The UI engine may only touch what it writes itself.
|
|
6
|
+
export const UI_OWNED_ENTRIES = [
|
|
7
|
+
"client",
|
|
8
|
+
"server",
|
|
9
|
+
"manifest.json",
|
|
10
|
+
"contract",
|
|
11
|
+
"pano-plugin.json",
|
|
12
|
+
"controllers",
|
|
13
|
+
"samples",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export const PACKAGE_FILE_NAME = "pano-plugin.json";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Reads the package index (pano-plugin.json) of a plugin folder.
|
|
20
|
+
* A missing or unreadable file means an old plugin without a package: returns null.
|
|
21
|
+
* @param {string} pluginFolder
|
|
22
|
+
* @returns {{ namespace?: string, styles?: any, views?: any, package: object } | null}
|
|
23
|
+
*/
|
|
24
|
+
export function readPluginPackage(pluginFolder) {
|
|
25
|
+
let json;
|
|
26
|
+
try {
|
|
27
|
+
json = JSON.parse(fs.readFileSync(path.join(pluginFolder, PACKAGE_FILE_NAME), "utf8"));
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (!json || typeof json !== "object" || Array.isArray(json)) return null;
|
|
32
|
+
const out = { package: json };
|
|
33
|
+
if (typeof json.namespace === "string" && json.namespace) out.namespace = json.namespace;
|
|
34
|
+
if (json.styles !== undefined) out.styles = json.styles;
|
|
35
|
+
if (json.views !== undefined) out.views = json.views;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Removes only the UI-owned entries of a plugin folder, then the folder itself if it is empty. */
|
|
40
|
+
export function removePluginUiFiles(pluginFolder) {
|
|
41
|
+
for (const entry of UI_OWNED_ENTRIES) {
|
|
42
|
+
fs.rmSync(path.join(pluginFolder, entry), { recursive: true, force: true });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
fs.rmdirSync(pluginFolder); // only succeeds when empty
|
|
47
|
+
} catch {
|
|
48
|
+
// missing or holds foreign files (plugin data) - leave it alone
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** True when both paths hold the same file, or the same tree of files with the same bytes. */
|
|
53
|
+
export function sameContent(a, b) {
|
|
54
|
+
if (!fs.existsSync(a) || !fs.existsSync(b)) return false;
|
|
55
|
+
|
|
56
|
+
const statA = fs.statSync(a);
|
|
57
|
+
const statB = fs.statSync(b);
|
|
58
|
+
|
|
59
|
+
if (statA.isDirectory() !== statB.isDirectory()) return false;
|
|
60
|
+
|
|
61
|
+
if (!statA.isDirectory()) {
|
|
62
|
+
return statA.size === statB.size && fs.readFileSync(a).equals(fs.readFileSync(b));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const namesA = fs.readdirSync(a).sort();
|
|
66
|
+
const namesB = fs.readdirSync(b).sort();
|
|
67
|
+
|
|
68
|
+
if (namesA.length !== namesB.length || namesA.some((name, i) => name !== namesB[i])) return false;
|
|
69
|
+
|
|
70
|
+
return namesA.every((name) => sameContent(path.join(a, name), path.join(b, name)));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Replaces the UI-owned entries in pluginFolder with those of stagingDir, keeping all other files.
|
|
75
|
+
*
|
|
76
|
+
* An entry whose content did not change is left untouched on disk. Development mode downloads every
|
|
77
|
+
* plugin UI again on each server render; rewriting identical files made the dev server's file watcher
|
|
78
|
+
* reload the page right after it had loaded (a blank flash after every refresh).
|
|
79
|
+
*/
|
|
80
|
+
export function replacePluginUiFiles(stagingDir, pluginFolder) {
|
|
81
|
+
fs.mkdirSync(pluginFolder, { recursive: true });
|
|
82
|
+
|
|
83
|
+
for (const entry of UI_OWNED_ENTRIES) {
|
|
84
|
+
const target = path.join(pluginFolder, entry);
|
|
85
|
+
const source = path.join(stagingDir, entry);
|
|
86
|
+
|
|
87
|
+
if (sameContent(source, target)) continue;
|
|
88
|
+
|
|
89
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
90
|
+
|
|
91
|
+
if (fs.existsSync(source)) fs.renameSync(source, target);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
fs.rmSync(stagingDir, { recursive: true, force: true });
|
|
95
|
+
}
|
|
@@ -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
|
+
}
|