@panomc/sdk 1.0.0-dev.8 → 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.
Files changed (162) hide show
  1. package/api/routes.core.json +3702 -0
  2. package/bin/api/__tests__/api-compat.test.mjs +97 -0
  3. package/bin/api/__tests__/check-paths.test.mjs +113 -0
  4. package/bin/api/__tests__/cli.test.mjs +44 -0
  5. package/bin/api/__tests__/extract-routes.test.mjs +132 -0
  6. package/bin/api/__tests__/fixtures/core-new/Pano/api/paths.old-new.json +82 -0
  7. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
  8. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
  9. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
  10. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
  11. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
  12. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
  13. package/bin/api/__tests__/fixtures/core-new/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
  14. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt +10 -0
  15. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/model/Bases.kt +21 -0
  16. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +19 -0
  17. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/auth/HostSsoAPI.kt +10 -0
  18. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt +28 -0
  19. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt +9 -0
  20. package/bin/api/__tests__/fixtures/core-old/Pano/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +9 -0
  21. package/bin/api/__tests__/fixtures/plugin-new/api/paths.old-new.json +66 -0
  22. package/bin/api/__tests__/fixtures/plugin-new/build.gradle.kts +42 -0
  23. package/bin/api/__tests__/fixtures/plugin-new/gradle.properties +4 -0
  24. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
  25. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
  26. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
  27. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
  28. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
  29. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
  30. package/bin/api/__tests__/fixtures/plugin-new/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
  31. package/bin/api/__tests__/fixtures/plugin-new/src/panel/Things.js +4 -0
  32. package/bin/api/__tests__/fixtures/plugin-new/src/theme/Logo.svelte +9 -0
  33. package/bin/api/__tests__/fixtures/plugin-new/src/theme/api.js +29 -0
  34. package/bin/api/__tests__/fixtures/plugin-old/build.gradle.kts +22 -0
  35. package/bin/api/__tests__/fixtures/plugin-old/gradle.properties +4 -0
  36. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/base/DemoApis.kt +13 -0
  37. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Errors.kt +16 -0
  38. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/error/Plain.kt +4 -0
  39. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt +16 -0
  40. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt +11 -0
  41. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt +18 -0
  42. package/bin/api/__tests__/fixtures/plugin-old/src/main/kotlin/com/example/demo/routes/WebhookAPI.kt +23 -0
  43. package/bin/api/__tests__/fixtures/plugin-old/src/panel/Things.js +4 -0
  44. package/bin/api/__tests__/fixtures/plugin-old/src/theme/Logo.svelte +9 -0
  45. package/bin/api/__tests__/fixtures/plugin-old/src/theme/api.js +29 -0
  46. package/bin/api/__tests__/fixtures/refusals/gradle.properties +1 -0
  47. package/bin/api/__tests__/fixtures/refusals/src/main/kotlin/x/Bad.kt +39 -0
  48. package/bin/api/__tests__/fixtures/unresolved/src/main/kotlin/x/Orphan.kt +19 -0
  49. package/bin/api/__tests__/helpers.mjs +48 -0
  50. package/bin/api/__tests__/migrate-v1.test.mjs +377 -0
  51. package/bin/api/__tests__/openapi-snapshot.test.mjs +120 -0
  52. package/bin/api/api-compat.mjs +204 -0
  53. package/bin/api/check-paths.mjs +135 -0
  54. package/bin/api/cli.mjs +83 -0
  55. package/bin/api/extract-routes.mjs +129 -0
  56. package/bin/api/js-scan.mjs +337 -0
  57. package/bin/api/kotlin.mjs +366 -0
  58. package/bin/api/migrate-v1.mjs +330 -0
  59. package/bin/api/openapi-snapshot.mjs +112 -0
  60. package/bin/api/project.mjs +172 -0
  61. package/bin/api/rename-table.mjs +66 -0
  62. package/bin/api/util.mjs +194 -0
  63. package/bin/pano-api.js +5 -0
  64. package/build/plugin-api-rollup.js +46 -0
  65. package/core/css/pano-tokens.css +225 -0
  66. package/core/favicon/apple-touch-icon.png +0 -0
  67. package/core/favicon/favicon-96x96.png +0 -0
  68. package/core/favicon/favicon.ico +0 -0
  69. package/core/favicon/favicon.svg +1 -0
  70. package/core/favicon/site.webmanifest +21 -0
  71. package/core/favicon/web-app-manifest-192x192.png +0 -0
  72. package/core/favicon/web-app-manifest-512x512.png +0 -0
  73. package/core/favicon_old/android-icon-144x144.png +0 -0
  74. package/core/favicon_old/android-icon-192x192.png +0 -0
  75. package/core/favicon_old/android-icon-36x36.png +0 -0
  76. package/core/favicon_old/android-icon-48x48.png +0 -0
  77. package/core/favicon_old/android-icon-72x72.png +0 -0
  78. package/core/favicon_old/android-icon-96x96.png +0 -0
  79. package/core/favicon_old/apple-icon-114x114.png +0 -0
  80. package/core/favicon_old/apple-icon-120x120.png +0 -0
  81. package/core/favicon_old/apple-icon-144x144.png +0 -0
  82. package/core/favicon_old/apple-icon-152x152.png +0 -0
  83. package/core/favicon_old/apple-icon-180x180.png +0 -0
  84. package/core/favicon_old/apple-icon-57x57.png +0 -0
  85. package/core/favicon_old/apple-icon-60x60.png +0 -0
  86. package/core/favicon_old/apple-icon-72x72.png +0 -0
  87. package/core/favicon_old/apple-icon-76x76.png +0 -0
  88. package/core/favicon_old/apple-icon-precomposed.png +0 -0
  89. package/core/favicon_old/apple-icon.png +0 -0
  90. package/core/favicon_old/browserconfig.xml +11 -0
  91. package/core/favicon_old/favicon-16x16.png +0 -0
  92. package/core/favicon_old/favicon-32x32.png +0 -0
  93. package/core/favicon_old/favicon-96x96.png +0 -0
  94. package/core/favicon_old/favicon.ico +0 -0
  95. package/core/favicon_old/manifest.json +41 -0
  96. package/core/favicon_old/ms-icon-144x144.png +0 -0
  97. package/core/favicon_old/ms-icon-150x150.png +0 -0
  98. package/core/favicon_old/ms-icon-310x310.png +0 -0
  99. package/core/favicon_old/ms-icon-70x70.png +0 -0
  100. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.eot +0 -0
  101. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.svg +483 -0
  102. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.ttf +0 -0
  103. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff +0 -0
  104. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-300.woff2 +0 -0
  105. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.eot +0 -0
  106. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.svg +486 -0
  107. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.ttf +0 -0
  108. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff +0 -0
  109. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-500.woff2 +0 -0
  110. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.eot +0 -0
  111. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.svg +484 -0
  112. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.ttf +0 -0
  113. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff +0 -0
  114. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-700.woff2 +0 -0
  115. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.eot +0 -0
  116. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.svg +486 -0
  117. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.ttf +0 -0
  118. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff +0 -0
  119. package/core/fonts/quicksand-v8-latin-ext_latin_vietnamese-regular.woff2 +0 -0
  120. package/core/js/ControllerRegistry.js +421 -0
  121. package/core/js/NotificationManager.js +62 -0
  122. package/core/js/PluginAPI.js +39 -0
  123. package/core/js/PluginManager.js +851 -0
  124. package/core/js/RouteMatcher.js +142 -0
  125. package/core/js/__tests__/ControllerRegistry.test.js +378 -0
  126. package/core/js/__tests__/NotificationManager.test.js +57 -0
  127. package/core/js/__tests__/PluginAPI.test.js +25 -0
  128. package/core/js/__tests__/RouteMatcher.test.js +33 -0
  129. package/core/js/__tests__/accessClient.test.js +582 -0
  130. package/core/js/__tests__/api.util.v1.test.js +336 -0
  131. package/core/js/__tests__/devBounce.test.js +28 -0
  132. package/core/js/__tests__/html.util.test.js +18 -0
  133. package/core/js/__tests__/pluginFolder.util.test.js +106 -0
  134. package/core/js/__tests__/pluginPackage.test.js +134 -0
  135. package/core/js/__tests__/pluginUiZip.test.js +47 -0
  136. package/core/js/__tests__/sdkLevel.test.js +34 -0
  137. package/core/js/api.util.js +433 -0
  138. package/core/js/html.util.js +26 -0
  139. package/core/js/pluginFolder.util.js +95 -0
  140. package/core/js/tooltip.util.js +59 -0
  141. package/core/js/variables.js +95 -0
  142. package/core/js/version.util.js +100 -0
  143. package/core/scss/_pano-tokens.scss +51 -0
  144. package/core/scss/custom-bootstrap.scss +196 -0
  145. package/core/scss/fonts.scss +85 -0
  146. package/core/scss/main.scss +389 -0
  147. package/core/scss/themes.scss +120 -0
  148. package/package.json +50 -10
  149. package/src/__tests__/controllers.test.js +220 -0
  150. package/src/__tests__/views.spike.test.js +472 -0
  151. package/src/components/{index.js → panel.js} +9 -6
  152. package/src/components/theme.js +18 -0
  153. package/src/controllers.js +127 -0
  154. package/src/index.js +1 -1
  155. package/src/svelte.js +3 -2
  156. package/src/types.js +5 -3
  157. package/src/utils/api.js +42 -1
  158. package/src/utils/auth.js +8 -0
  159. package/src/utils/component.js +4 -2
  160. package/src/utils/route.js +16 -0
  161. package/src/utils/text.js +8 -0
  162. package/src/views.js +29 -0
@@ -0,0 +1,97 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { breaks } from '../api-compat.mjs';
3
+
4
+ const op = (extra = {}) => ({
5
+ operationId: 'GetPosts',
6
+ responses: {
7
+ 200: {
8
+ description: 'ok',
9
+ content: {
10
+ 'application/json': {
11
+ schema: {
12
+ type: 'object',
13
+ properties: { items: { type: 'array', items: { $ref: '#/components/schemas/Post' } }, total: { type: 'integer' } },
14
+ },
15
+ },
16
+ },
17
+ },
18
+ },
19
+ ...extra,
20
+ });
21
+ const spec = (paths, schemas = {}) => ({
22
+ openapi: '3.1.0',
23
+ paths,
24
+ components: { schemas: { Post: { type: 'object', properties: { id: { type: 'integer' }, title: { type: 'string' } } }, ...schemas } },
25
+ });
26
+ const TODAY = '2026-10-08';
27
+
28
+ describe('api-compat', () => {
29
+ test('identical and additive changes pass', () => {
30
+ const a = spec({ '/posts': { get: op() } });
31
+ const b = spec(
32
+ { '/posts': { get: op() }, '/tags': { get: op() } },
33
+ { Post: { type: 'object', properties: { id: { type: 'integer' }, title: { type: 'string' }, slug: { type: 'string' } } } },
34
+ );
35
+ expect(breaks(a, a, TODAY)).toEqual([]);
36
+ expect(breaks(a, b, TODAY)).toEqual([]);
37
+ });
38
+
39
+ test('a removed operation fails', () => {
40
+ const a = spec({ '/posts': { get: op() }, '/tags': { get: op() } });
41
+ const b = spec({ '/posts': { get: op() } });
42
+ expect(breaks(a, b, TODAY)).toEqual(['GET /tags: operation was removed without being deprecated']);
43
+ });
44
+
45
+ test('deprecated and expired passes, deprecated but not yet expired fails', () => {
46
+ const dep = (removal) => op({ deprecated: true, 'x-pano-removal': removal, 'x-pano-deprecated-on': '2025-01-01' });
47
+ const gone = spec({ '/posts': { get: op() } });
48
+ expect(breaks(spec({ '/posts': { get: op() }, '/old': { get: dep('2026-06-01') } }), gone, TODAY)).toEqual([]);
49
+ expect(breaks(spec({ '/posts': { get: op() }, '/old': { get: dep('2027-06-01') } }), gone, TODAY)).toEqual([
50
+ 'GET /old: removed before its removal date 2027-06-01',
51
+ ]);
52
+ expect(breaks(spec({ '/old': { get: op({ deprecated: true }) } }), spec({}), TODAY)[0]).toContain('deprecated without x-pano-removal');
53
+ });
54
+
55
+ test('a removed response property (also through $ref) or a changed type fails', () => {
56
+ const a = spec({ '/posts': { get: op() } });
57
+ const noTitle = spec({ '/posts': { get: op() } }, { Post: { type: 'object', properties: { id: { type: 'integer' } } } });
58
+ expect(breaks(a, noTitle, TODAY)).toEqual(['GET /posts 200.items[].title: response property was removed']);
59
+ const retyped = spec({ '/posts': { get: op() } }, { Post: { type: 'object', properties: { id: { type: 'string' }, title: { type: 'string' } } } });
60
+ expect(breaks(a, retyped, TODAY)).toEqual(['GET /posts 200.items[].id: type changed from integer to string']);
61
+ const total = JSON.parse(JSON.stringify(a));
62
+ delete total.paths['/posts'].get.responses[200].content['application/json'].schema.properties.total;
63
+ expect(breaks(a, total, TODAY)).toEqual(['GET /posts 200.total: response property was removed']);
64
+ });
65
+
66
+ test('a removed response status fails', () => {
67
+ const a = spec({ '/posts': { get: op() } });
68
+ const b = spec({ '/posts': { get: { ...op(), responses: { 201: op().responses[200] } } } });
69
+ expect(breaks(a, b, TODAY)).toEqual(['GET /posts: response 200 was removed']);
70
+ });
71
+
72
+ test('a new required request property or parameter fails, an optional one passes', () => {
73
+ const body = (schema) => ({ required: true, content: { 'application/json': { schema } } });
74
+ const a = spec({ '/posts': { post: op({ requestBody: body({ type: 'object', properties: { title: { type: 'string' } }, required: ['title'] }) }) } });
75
+ const bad = spec({ '/posts': { post: op({ requestBody: body({ type: 'object', properties: { title: { type: 'string' }, slug: { type: 'string' } }, required: ['title', 'slug'] }) }) } });
76
+ const ok = spec({ '/posts': { post: op({ requestBody: body({ type: 'object', properties: { title: { type: 'string' }, slug: { type: 'string' } }, required: ['title'] }) }) } });
77
+ expect(breaks(a, bad, TODAY)).toEqual(['POST /posts request.slug: request property became required']);
78
+ expect(breaks(a, ok, TODAY)).toEqual([]);
79
+ const param = (required) => spec({ '/posts': { get: op({ parameters: [{ name: 'page', in: 'query', required, schema: { type: 'integer' } }] }) } });
80
+ expect(breaks(spec({ '/posts': { get: op() } }), param(true), TODAY)).toEqual(['GET /posts: new required query parameter "page"']);
81
+ expect(breaks(spec({ '/posts': { get: op() } }), param(false), TODAY)).toEqual([]);
82
+ expect(breaks(param(false), param(true), TODAY)).toEqual(['GET /posts: query parameter "page" became required']);
83
+ });
84
+
85
+ test('internal operations carry no promise', () => {
86
+ const a = spec({ '/panel/x': { get: op({ 'x-pano-stability': 'internal' }) } });
87
+ expect(breaks(a, spec({}), TODAY)).toEqual([]);
88
+ });
89
+
90
+ test('the deprecation floor: removal at least 6 months after x-pano-deprecated-on', () => {
91
+ const dep = (removal) => spec({ '/old': { get: op({ deprecated: true, 'x-pano-removal': removal, 'x-pano-deprecated-on': '2026-10-01' }) } });
92
+ expect(breaks(dep('2027-04-01'), dep('2027-04-01'), TODAY)).toEqual([]);
93
+ expect(breaks(dep('2027-03-01'), dep('2027-03-01'), TODAY)).toEqual([
94
+ 'GET /old: x-pano-removal 2027-03-01 is less than 6 months after x-pano-deprecated-on 2026-10-01',
95
+ ]);
96
+ });
97
+ });
@@ -0,0 +1,113 @@
1
+ import { afterAll, describe, expect, test } from 'bun:test';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { checkPaths, collectCalls, fits, suggest } from '../check-paths.mjs';
5
+ import { walk } from '../util.mjs';
6
+ import { FIXTURES, cleanup, copyFixture, runCli, tempDir } from './helpers.mjs';
7
+
8
+ afterAll(cleanup);
9
+
10
+ /** A routes.core.json written the way extract-routes --core writes it. */
11
+ function routesFile(paths) {
12
+ const f = path.join(tempDir(), 'routes.core.json');
13
+ fs.writeFileSync(f, JSON.stringify(paths.map((p) => ({ method: 'GET', path: `/api/v1${p}` }))));
14
+ return f;
15
+ }
16
+ const CORE = ['/site-info', '/posts', '/posts/:url', '/panel/addons', '/panel/addons/:pluginId', '/panel/basicData', '/ticket-categories'];
17
+
18
+ describe('check-paths', () => {
19
+ test('the migrated fixture passes (core routes, plugin routes through the plugin client)', () => {
20
+ const r = checkPaths({ root: path.join(FIXTURES, 'plugin-new'), routes: routesFile(CORE) });
21
+ expect(r.errors).toEqual([]);
22
+ expect(r.problems).toEqual([]);
23
+ expect(r.checked).toBe(6);
24
+ });
25
+
26
+ test('reports file:line, the literal and a suggestion', () => {
27
+ const dir = copyFixture('plugin-new');
28
+ fs.writeFileSync(
29
+ path.join(dir, 'src/panel/Bad.js'),
30
+ [
31
+ "import ApiUtil from '@panomc/sdk/utils/api';",
32
+ "ApiUtil.get({ path: '/panel/addon' });",
33
+ 'ApiUtil.get({ path: `/posts/${url}` });',
34
+ "ApiUtil.get({ path: '/api/posts' });",
35
+ "ApiUtil.get({ path: '/completely/different/route/here' });",
36
+ 'const dynamic = ApiUtil.get({ path: prefix + "/x" });',
37
+ ].join('\n'),
38
+ );
39
+ const r = checkPaths({ root: dir, routes: routesFile(CORE) });
40
+ expect(r.problems).toEqual([
41
+ "src/panel/Bad.js:2 '/panel/addon' is not a Pano route (did you mean '/panel/addons'?)",
42
+ "src/panel/Bad.js:4 '/api/posts' must not start with /api: write '/posts'",
43
+ "src/panel/Bad.js:5 '/completely/different/route/here' is not a Pano route",
44
+ ]);
45
+ });
46
+
47
+ test('plugin client paths are matched against the repository\'s own declared routes', () => {
48
+ const dir = copyFixture('plugin-new');
49
+ fs.writeFileSync(
50
+ path.join(dir, 'src/theme/Plugin.js'),
51
+ [
52
+ "import { api } from '@panomc/sdk/plugin-api';",
53
+ "api.get({ path: '/things/1' });",
54
+ "api.get({ path: '/thingz' });",
55
+ "api.panel.put({ path: `/things/${id}` });",
56
+ "api.panel.get({ path: '/things' });",
57
+ "const other = createPluginApi('pano-plugin-else'); other.get({ path: '/whatever' });",
58
+ ].join('\n'),
59
+ );
60
+ const r = checkPaths({ root: dir, routes: routesFile(CORE) });
61
+ expect(r.problems).toEqual([
62
+ "src/theme/Plugin.js:3 '/thingz' is not a Pano route (did you mean '/things'?)",
63
+ "src/theme/Plugin.js:5 '/things' is not a Pano route (did you mean '/things/:id'?)",
64
+ ]);
65
+ });
66
+
67
+ test('a missing routes file is an error, not a pass', () => {
68
+ const r = checkPaths({ root: path.join(FIXTURES, 'plugin-new'), routes: path.join(tempDir(), 'nope.json') });
69
+ expect(r.errors.length).toBe(1);
70
+ expect(runCli(['check-paths', '--routes', path.join(tempDir(), 'nope.json'), path.join(FIXTURES, 'plugin-new')]).code).toBe(2);
71
+ });
72
+
73
+ test('CLI exit codes', () => {
74
+ const f = routesFile(CORE);
75
+ expect(runCli(['check-paths', '--routes', f, path.join(FIXTURES, 'plugin-new')]).code).toBe(0);
76
+ expect(runCli(['check-paths', '--routes', f, path.join(FIXTURES, 'plugin-old')]).code).toBe(1);
77
+ });
78
+ });
79
+
80
+ describe('helpers', () => {
81
+ test('fits: holes and parameters are wildcards, segment counts must agree', () => {
82
+ expect(fits('/posts/${x}', '/posts/:url')).toBe(true);
83
+ expect(fits('/posts/file-${x}.png', '/posts/:name')).toBe(true);
84
+ expect(fits('/posts/${x}', '/posts')).toBe(false);
85
+ expect(fits('/posts/a', '/posts/b')).toBe(false);
86
+ expect(fits('/panel/${seg}/x', '/panel/anything/x')).toBe(true);
87
+ });
88
+
89
+ test('suggest only offers close routes', () => {
90
+ expect(suggest('/panel/addon', ['/panel/addons', '/posts'])).toBe('/panel/addons');
91
+ expect(suggest('/zzzzzzzzzzzzzzzz', ['/panel/addons', '/posts'])).toBe(null);
92
+ });
93
+
94
+ test('collectCalls reads path: of ApiUtil and api calls with their line', () => {
95
+ const calls = collectCalls("import ApiUtil from '@panomc/sdk/utils/api';\n\nApiUtil.post({\n path: `/a/${b}`,\n body });");
96
+ expect(calls.map((c) => [c.line, c.literal, c.kind])).toEqual([[4, '/a/${b}', 'core']]);
97
+ });
98
+ });
99
+
100
+ describe('the JS file walk', () => {
101
+ test('skips __tests__ folders, so test strings are never read as client calls', () => {
102
+ const dir = tempDir();
103
+ fs.mkdirSync(path.join(dir, 'src/__tests__'), { recursive: true });
104
+ fs.mkdirSync(path.join(dir, 'src/sub/__tests__/deep'), { recursive: true });
105
+ fs.writeFileSync(path.join(dir, 'src/api.js'), "ApiUtil.get({ path: '/site-info' });\n");
106
+ fs.writeFileSync(path.join(dir, 'src/__tests__/api.test.js'), "ApiUtil.get({ path: '/nope' });\n");
107
+ fs.writeFileSync(path.join(dir, 'src/sub/__tests__/deep/x.js'), "ApiUtil.get({ path: '/nope' });\n");
108
+ const files = walk(dir, { exts: ['.js'] }).map((f) => path.relative(dir, f));
109
+ expect(files).toEqual(['src/api.js']);
110
+ const result = checkPaths({ root: dir, routes: routesFile(CORE) });
111
+ expect(JSON.stringify(result)).not.toContain('/nope');
112
+ });
113
+ });
@@ -0,0 +1,44 @@
1
+ import { afterAll, describe, expect, test } from 'bun:test';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { FIXTURES, cleanup, runCli, tempDir } from './helpers.mjs';
5
+
6
+ afterAll(cleanup);
7
+
8
+ describe('pano-api CLI', () => {
9
+ test('help and unknown commands', () => {
10
+ expect(runCli(['--help']).code).toBe(0);
11
+ expect(runCli(['--help']).stdout).toContain('migrate-v1');
12
+ expect(runCli([]).code).toBe(1);
13
+ expect(runCli(['frobnicate']).code).toBe(1);
14
+ expect(runCli(['migrate-v1', '--bogus']).code).toBe(2);
15
+ });
16
+
17
+ test('extract-routes prints JSON on stdout', () => {
18
+ const r = runCli(['extract-routes', path.join(FIXTURES, 'plugin-new')]);
19
+ expect(r.code).toBe(0);
20
+ const routes = JSON.parse(r.stdout);
21
+ expect(routes.length).toBe(8);
22
+ expect(routes[0]).toHaveProperty('path');
23
+ });
24
+
25
+ test('api-compat compares two files', () => {
26
+ const dir = tempDir();
27
+ const op = { get: { responses: { 200: { description: 'ok' } } } };
28
+ fs.writeFileSync(path.join(dir, 'a.json'), JSON.stringify({ paths: { '/x': op, '/y': op } }));
29
+ fs.writeFileSync(path.join(dir, 'b.json'), JSON.stringify({ paths: { '/x': op } }));
30
+ const bad = runCli(['api-compat', path.join(dir, 'a.json'), path.join(dir, 'b.json')]);
31
+ expect(bad.code).toBe(1);
32
+ expect(bad.stderr).toContain('GET /y: operation was removed');
33
+ expect(runCli(['api-compat', path.join(dir, 'b.json'), path.join(dir, 'a.json')]).code).toBe(0);
34
+ });
35
+
36
+ test('--check is idempotent end to end: old tree fails, migrate, then check passes', () => {
37
+ const dir = tempDir();
38
+ fs.cpSync(path.join(FIXTURES, 'plugin-old'), dir, { recursive: true });
39
+ expect(runCli(['migrate-v1', '--check', '--strip', 'demo', dir]).code).toBe(1);
40
+ expect(runCli(['migrate-v1', '--strip', 'demo', dir]).code).toBe(0);
41
+ expect(runCli(['migrate-v1', '--check', '--strip', 'demo', dir]).code).toBe(0);
42
+ expect(runCli(['migrate-v1', '--strip', 'demo', dir]).stderr).toContain('0 file(s) changed');
43
+ });
44
+ });
@@ -0,0 +1,132 @@
1
+ import { afterAll, describe, expect, test } from 'bun:test';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { extractRoutes, checkRoutes, runExtractRoutes } from '../extract-routes.mjs';
5
+ import { FIXTURES, cleanup, runCli, tempDir } from './helpers.mjs';
6
+
7
+ afterAll(cleanup);
8
+
9
+ const byClass = (routes, cls) => routes.filter((r) => r.class === cls);
10
+
11
+ describe('extract-routes on a plugin', () => {
12
+ const { routes, errors } = extractRoutes(path.join(FIXTURES, 'plugin-new'));
13
+
14
+ test('reads every endpoint without errors', () => {
15
+ expect(errors).toEqual([]);
16
+ expect(routes.length).toBe(8);
17
+ });
18
+
19
+ test('finds the base class through supertypes (DemoMiddleApi -> DemoApi -> Api)', () => {
20
+ const r = byClass(routes, 'GetThingsAPI');
21
+ expect(r.map((x) => x.path)).toEqual([
22
+ '/api/plugins/pano-plugin-demo/other/list',
23
+ '/api/plugins/pano-plugin-demo/things',
24
+ '/api/plugins/pano-plugin-demo/things/:id',
25
+ ]);
26
+ expect(r.every((x) => x.namespace === 'SITE' && x.pluginId === 'pano-plugin-demo')).toBe(true);
27
+ });
28
+
29
+ test('a PanelApi subclass lands under /panel/plugins/<id>', () => {
30
+ const [r] = byClass(routes, 'PanelSaveThingAPI');
31
+ expect(r.path).toBe('/api/plugins/pano-plugin-demo/panel/things/:id');
32
+ expect(r.namespace).toBe('PANEL');
33
+ expect(r.method).toBe('PUT');
34
+ });
35
+
36
+ test('resolves const val paths, templates and concatenation across objects', () => {
37
+ const paths = byClass(routes, 'WebhookAPI').map((r) => `${r.method} ${r.declared}`);
38
+ expect(paths).toEqual([
39
+ 'GET /payments/:providerId/return/:name',
40
+ 'ANY /webhook/:id',
41
+ 'ANY /webhook/:id/:channel',
42
+ ]);
43
+ });
44
+
45
+ test('the pre-cutover form is reported as legacy and kept verbatim', () => {
46
+ const { routes: old } = extractRoutes(path.join(FIXTURES, 'plugin-old'));
47
+ const r = byClass(old, 'GetThingsAPI').find((x) => x.declared === '/api/demo/things');
48
+ expect(r.legacy).toBe(true);
49
+ expect(r.path).toBe('/api/demo/things');
50
+ expect(checkRoutes(old).length).toBeGreaterThan(0);
51
+ });
52
+
53
+ test('the migrated fixture fits the scheme', () => {
54
+ expect(checkRoutes(routes)).toEqual([]);
55
+ });
56
+ });
57
+
58
+ describe('extract-routes on core', () => {
59
+ const { routes, errors } = extractRoutes(path.join(FIXTURES, 'core-new'));
60
+ const at = (cls) => routes.filter((r) => r.class === cls).map((r) => r.path);
61
+
62
+ test('scans Pano/src/main/kotlin of a pano-web-platform checkout and finds no base classes as endpoints', () => {
63
+ expect(errors).toEqual([]);
64
+ expect(routes.some((r) => ['Api', 'PanelApi', 'Template'].includes(r.class))).toBe(false);
65
+ expect(routes.every((r) => r.pluginId === null)).toBe(true);
66
+ });
67
+
68
+ test('namespace and mount overrides win over the base class', () => {
69
+ expect(at('PanelGetDefaultServerIconAPI')).toEqual(['/api/v1/server/icon/default']);
70
+ expect(at('PanelIsUserExistsAPI')).toEqual(['/api/v1/panel/players/:username/exists']);
71
+ expect(at('HostSsoAPI')).toEqual(['/panel/host-sso']);
72
+ expect(at('IndexTemplate')).toEqual(['/*']);
73
+ });
74
+
75
+ test('renames are visible in the extracted paths', () => {
76
+ expect(at('GetSiteInfoAPI')).toEqual(['/api/v1/site-info']);
77
+ expect(at('PanelGetAddonsAPI')).toEqual(['/api/v1/panel/addons', '/api/v1/panel/addons/search']);
78
+ expect(at('GetPluginUiZipAPI')).toEqual(['/api/v1/plugins/:pluginId/_/ui.zip']);
79
+ expect(checkRoutes(routes)).toEqual([]);
80
+ });
81
+ });
82
+
83
+ describe('refusal table and failures', () => {
84
+ test('each refusal names the class and the fix, duplicates name both classes', () => {
85
+ const { routes } = extractRoutes(path.join(FIXTURES, 'refusals'));
86
+ const problems = checkRoutes(routes).join('\n');
87
+ expect(problems).toContain('LegacyAPI: path "/api/posts" starts with /api; declare "/posts", not "/api/posts"; Pano adds /api/v1 itself');
88
+ expect(problems).toContain('NoSlashAPI: path "hello" must start with "/"; declare "/hello"');
89
+ expect(problems).toContain('extend PanelApi and declare "/settings"; Pano adds /panel itself');
90
+ expect(problems).toContain('put a resource name first: "/items/:id"');
91
+ expect(problems).toMatch(/DupTwoAPI: duplicate of .*DupOneAPI/);
92
+ expect(problems.split('\n').filter((l) => l.includes('put a resource name first')).length).toBe(2);
93
+ });
94
+
95
+ test('anything unresolvable fails with file and line', () => {
96
+ const { errors } = extractRoutes(path.join(FIXTURES, 'unresolved'));
97
+ expect(errors.map((e) => `${e.file}:${e.line}`)).toEqual([
98
+ 'src/main/kotlin/x/Orphan.kt:7',
99
+ 'src/main/kotlin/x/Orphan.kt:12',
100
+ 'src/main/kotlin/x/Orphan.kt:18',
101
+ ]);
102
+ expect(errors[0].message).toContain('cannot resolve its base class');
103
+ expect(errors[2].message).toContain('MISSING_CONST');
104
+ });
105
+
106
+ test('--check exits 1 for problems and 2 for unreadable classes', () => {
107
+ expect(runCli(['extract-routes', '--check', path.join(FIXTURES, 'refusals')]).code).toBe(1);
108
+ expect(runCli(['extract-routes', '--check', path.join(FIXTURES, 'unresolved')]).code).toBe(2);
109
+ expect(runCli(['extract-routes', '--check', path.join(FIXTURES, 'plugin-new')]).code).toBe(0);
110
+ });
111
+ });
112
+
113
+ describe('--out / --core snapshot', () => {
114
+ test('writes, then --check notices a stale file and accepts a current one', () => {
115
+ const out = path.join(tempDir(), 'routes.json');
116
+ const root = path.join(FIXTURES, 'core-new');
117
+ const quiet = console.error;
118
+ console.error = () => {};
119
+ try {
120
+ expect(runExtractRoutes({ root, core: false, check: true, out })).toBe(1); // missing
121
+ expect(runExtractRoutes({ root, core: false, check: false, out })).toBe(0);
122
+ expect(runExtractRoutes({ root, core: false, check: true, out })).toBe(0);
123
+ fs.appendFileSync(out, ' ');
124
+ expect(runExtractRoutes({ root, core: false, check: true, out })).toBe(1);
125
+ } finally {
126
+ console.error = quiet;
127
+ }
128
+ const written = JSON.parse(fs.readFileSync(out, 'utf8'));
129
+ expect(written[0]).toHaveProperty('method');
130
+ expect(written[0]).not.toHaveProperty('line');
131
+ });
132
+ });
@@ -0,0 +1,82 @@
1
+ [
2
+ {
3
+ "method": "GET",
4
+ "old": "/api/panel/players/:username/exists",
5
+ "new": "/api/v1/panel/players/:username/exists",
6
+ "relative": "/panel/players/:username/exists",
7
+ "class": "PanelIsUserExistsAPI",
8
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt"
9
+ },
10
+ {
11
+ "method": "GET",
12
+ "old": "/api/panel/plugins",
13
+ "new": "/api/v1/panel/addons",
14
+ "relative": "/panel/addons",
15
+ "class": "PanelGetAddonsAPI",
16
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt"
17
+ },
18
+ {
19
+ "method": "GET",
20
+ "old": "/api/panel/plugins/search",
21
+ "new": "/api/v1/panel/addons/search",
22
+ "relative": "/panel/addons/search",
23
+ "class": "PanelGetAddonsAPI",
24
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt"
25
+ },
26
+ {
27
+ "method": "GET",
28
+ "old": "/api/panel/posts",
29
+ "new": "/api/v1/panel/posts",
30
+ "relative": "/panel/posts",
31
+ "class": "PanelGetPostsAPI",
32
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt"
33
+ },
34
+ {
35
+ "method": "GET",
36
+ "old": "/api/plugins/:pluginId/resources/plugin-ui.zip",
37
+ "new": "/api/v1/plugins/:pluginId/_/ui.zip",
38
+ "relative": "/plugins/:pluginId/_/ui.zip",
39
+ "class": "GetPluginUiZipAPI",
40
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/plugins/GetPluginUiZipAPI.kt"
41
+ },
42
+ {
43
+ "method": "GET",
44
+ "old": "/api/post/thumbnail/:filename",
45
+ "new": "/api/v1/posts/thumbnails/:filename",
46
+ "relative": "/posts/thumbnails/:filename",
47
+ "class": "GetThumbnailAPI",
48
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt"
49
+ },
50
+ {
51
+ "method": "GET",
52
+ "old": "/api/posts",
53
+ "new": "/api/v1/posts",
54
+ "relative": "/posts",
55
+ "class": "GetPostsAPI",
56
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt"
57
+ },
58
+ {
59
+ "method": "GET",
60
+ "old": "/api/posts/:url",
61
+ "new": "/api/v1/posts/:url",
62
+ "relative": "/posts/:url",
63
+ "class": "GetPostsAPI",
64
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt"
65
+ },
66
+ {
67
+ "method": "GET",
68
+ "old": "/api/server/icon/default",
69
+ "new": "/api/v1/server/icon/default",
70
+ "relative": "/server/icon/default",
71
+ "class": "PanelGetDefaultServerIconAPI",
72
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelAddonsAPI.kt"
73
+ },
74
+ {
75
+ "method": "GET",
76
+ "old": "/api/siteInfo",
77
+ "new": "/api/v1/site-info",
78
+ "relative": "/site-info",
79
+ "class": "GetSiteInfoAPI",
80
+ "file": "Pano/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt"
81
+ }
82
+ ]
@@ -0,0 +1,10 @@
1
+ package com.panomc.platform.error
2
+
3
+ import com.panomc.platform.model.Error
4
+
5
+ class NotExists(
6
+ statusMessage: String = "",
7
+ extras: Map<String, Any?> = mapOf()
8
+ ) : Error("NOT_EXISTS", 404, statusMessage, extras)
9
+
10
+ class Banned : NotExists()
@@ -0,0 +1,21 @@
1
+ package com.panomc.platform.model
2
+
3
+ abstract class Route {
4
+ abstract val paths: List<Path>
5
+ }
6
+
7
+ enum class Mount { API, ROOT }
8
+
9
+ enum class Namespace { SITE, PANEL }
10
+
11
+ abstract class Api : Route() {
12
+ override val mount = Mount.API
13
+ }
14
+
15
+ abstract class LoggedInApi : Api()
16
+
17
+ abstract class PanelApi : LoggedInApi() {
18
+ override val namespace = Namespace.PANEL
19
+ }
20
+
21
+ abstract class Template : Route()
@@ -0,0 +1,19 @@
1
+ package com.panomc.platform.route.api
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class GetSiteInfoAPI : Api() {
8
+ override val paths = listOf(Path("/site-info", RouteType.GET))
9
+ }
10
+
11
+ @Endpoint
12
+ class GetThumbnailAPI : Api() {
13
+ override val paths = listOf(Path("/posts/thumbnails/:filename", RouteType.GET))
14
+ }
15
+
16
+ @Endpoint
17
+ class GetPostsAPI : Api() {
18
+ override val paths = listOf(Path("/posts", RouteType.GET), Path("/posts/:url", RouteType.GET))
19
+ }
@@ -0,0 +1,10 @@
1
+ package com.panomc.platform.route.api.auth
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class HostSsoAPI : Api() {
8
+ override val mount = Mount.ROOT
9
+ override val paths = listOf(Path("/panel/host-sso", RouteType.GET))
10
+ }
@@ -0,0 +1,28 @@
1
+ package com.panomc.platform.route.api.panel
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class PanelGetAddonsAPI : PanelApi() {
8
+ override val paths = listOf(Path("/addons", RouteType.GET), Path("/addons/search", RouteType.GET))
9
+ }
10
+
11
+ @Endpoint
12
+ class PanelGetPostsAPI : PanelApi() {
13
+ override val paths = listOf(Path("/posts", RouteType.GET))
14
+ }
15
+
16
+ // A PanelApi that is a site path: the class overrides the namespace, so /panel is not touched.
17
+ @Endpoint
18
+ class PanelGetDefaultServerIconAPI : PanelApi() {
19
+ override val namespace = Namespace.SITE
20
+ override val paths = listOf(Path("/server/icon/default", RouteType.GET))
21
+ }
22
+
23
+ // Not a PanelApi but served under /panel: the class overrides the namespace.
24
+ @Endpoint
25
+ class PanelIsUserExistsAPI : Api() {
26
+ override val namespace = Namespace.PANEL
27
+ override val paths = listOf(Path("/players/:username/exists", RouteType.GET))
28
+ }
@@ -0,0 +1,9 @@
1
+ package com.panomc.platform.route.api.plugins
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class GetPluginUiZipAPI : Api() {
8
+ override val paths = listOf(Path("/plugins/:pluginId/_/ui.zip", RouteType.GET))
9
+ }
@@ -0,0 +1,9 @@
1
+ package com.panomc.platform.route.template
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class IndexTemplate : Template() {
8
+ override val paths = listOf(Path("/*", RouteType.ROUTE))
9
+ }
@@ -0,0 +1,10 @@
1
+ package com.panomc.platform.error
2
+
3
+ import com.panomc.platform.model.Error
4
+
5
+ class NotExists(
6
+ statusMessage: String = "",
7
+ extras: Map<String, Any?> = mapOf()
8
+ ) : Error(404, statusMessage, extras)
9
+
10
+ class Banned : NotExists()
@@ -0,0 +1,21 @@
1
+ package com.panomc.platform.model
2
+
3
+ abstract class Route {
4
+ abstract val paths: List<Path>
5
+ }
6
+
7
+ enum class Mount { API, ROOT }
8
+
9
+ enum class Namespace { SITE, PANEL }
10
+
11
+ abstract class Api : Route() {
12
+ override val mount = Mount.API
13
+ }
14
+
15
+ abstract class LoggedInApi : Api()
16
+
17
+ abstract class PanelApi : LoggedInApi() {
18
+ override val namespace = Namespace.PANEL
19
+ }
20
+
21
+ abstract class Template : Route()
@@ -0,0 +1,19 @@
1
+ package com.panomc.platform.route.api
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class GetSiteInfoAPI : Api() {
8
+ override val paths = listOf(Path("/api/siteInfo", RouteType.GET))
9
+ }
10
+
11
+ @Endpoint
12
+ class GetThumbnailAPI : Api() {
13
+ override val paths = listOf(Path("/api/post/thumbnail/:filename", RouteType.GET))
14
+ }
15
+
16
+ @Endpoint
17
+ class GetPostsAPI : Api() {
18
+ override val paths = listOf(Path("/api/posts", RouteType.GET), Path("/api/posts/:url", RouteType.GET))
19
+ }
@@ -0,0 +1,10 @@
1
+ package com.panomc.platform.route.api.auth
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class HostSsoAPI : Api() {
8
+ override val mount = Mount.ROOT
9
+ override val paths = listOf(Path("/panel/host-sso", RouteType.GET))
10
+ }