@panomc/sdk 1.0.0-dev.9 → 2.0.0-dev.1

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 (166) 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__/appStores.test.js +47 -0
  132. package/core/js/__tests__/devBounce.test.js +28 -0
  133. package/core/js/__tests__/html.util.test.js +18 -0
  134. package/core/js/__tests__/pluginFolder.util.test.js +106 -0
  135. package/core/js/__tests__/pluginPackage.test.js +134 -0
  136. package/core/js/__tests__/pluginUiZip.test.js +47 -0
  137. package/core/js/__tests__/sdkLevel.test.js +34 -0
  138. package/core/js/api.util.js +433 -0
  139. package/core/js/appStores.js +93 -0
  140. package/core/js/basePath.js +10 -0
  141. package/core/js/html.util.js +26 -0
  142. package/core/js/pluginFolder.util.js +95 -0
  143. package/core/js/tooltip.util.js +59 -0
  144. package/core/js/variables.js +95 -0
  145. package/core/js/version.util.js +100 -0
  146. package/core/scss/_pano-tokens.scss +51 -0
  147. package/core/scss/custom-bootstrap.scss +210 -0
  148. package/core/scss/fonts.scss +85 -0
  149. package/core/scss/main.scss +389 -0
  150. package/core/scss/themes.scss +122 -0
  151. package/package.json +63 -11
  152. package/src/__tests__/controllers.test.js +220 -0
  153. package/src/__tests__/views.spike.test.js +472 -0
  154. package/src/components/{index.js → panel.js} +9 -7
  155. package/src/components/theme.js +18 -0
  156. package/src/controllers.js +127 -0
  157. package/src/index.js +1 -1
  158. package/src/runtime-specifiers.js +88 -0
  159. package/src/svelte.js +3 -2
  160. package/src/types.js +5 -3
  161. package/src/utils/api.js +42 -1
  162. package/src/utils/auth.js +8 -0
  163. package/src/utils/component.js +4 -2
  164. package/src/utils/route.js +16 -0
  165. package/src/utils/text.js +8 -0
  166. package/src/views.js +29 -0
@@ -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("/api/panel/plugins", RouteType.GET), Path("/api/panel/plugins/search", RouteType.GET))
9
+ }
10
+
11
+ @Endpoint
12
+ class PanelGetPostsAPI : PanelApi() {
13
+ override val paths = listOf(Path("/api/panel/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("/api/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("/api/panel/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("/api/plugins/:pluginId/resources/plugin-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,66 @@
1
+ [
2
+ {
3
+ "method": "GET",
4
+ "old": "/api/demo/payments/:providerId/return/:name",
5
+ "new": "/api/plugins/pano-plugin-demo/payments/:providerId/return/:name",
6
+ "relative": "/plugins/pano-plugin-demo/payments/:providerId/return/:name",
7
+ "class": "WebhookAPI",
8
+ "file": "src/main/kotlin/com/example/demo/routes/WebhookAPI.kt"
9
+ },
10
+ {
11
+ "method": "GET",
12
+ "old": "/api/demo/things",
13
+ "new": "/api/plugins/pano-plugin-demo/things",
14
+ "relative": "/plugins/pano-plugin-demo/things",
15
+ "class": "GetThingsAPI",
16
+ "file": "src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt"
17
+ },
18
+ {
19
+ "method": "GET",
20
+ "old": "/api/demo/things/:id",
21
+ "new": "/api/plugins/pano-plugin-demo/things/:id",
22
+ "relative": "/plugins/pano-plugin-demo/things/:id",
23
+ "class": "GetThingsAPI",
24
+ "file": "src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt"
25
+ },
26
+ {
27
+ "method": "POST",
28
+ "old": "/api/demo/validated",
29
+ "new": "/api/plugins/pano-plugin-demo/validated",
30
+ "relative": "/plugins/pano-plugin-demo/validated",
31
+ "class": "ValidatedAPI",
32
+ "file": "src/main/kotlin/com/example/demo/routes/ValidatedAPI.kt"
33
+ },
34
+ {
35
+ "method": "ANY",
36
+ "old": "/api/demo/webhook/:id",
37
+ "new": "/api/plugins/pano-plugin-demo/webhook/:id",
38
+ "relative": "/plugins/pano-plugin-demo/webhook/:id",
39
+ "class": "WebhookAPI",
40
+ "file": "src/main/kotlin/com/example/demo/routes/WebhookAPI.kt"
41
+ },
42
+ {
43
+ "method": "ANY",
44
+ "old": "/api/demo/webhook/:id/:channel",
45
+ "new": "/api/plugins/pano-plugin-demo/webhook/:id/:channel",
46
+ "relative": "/plugins/pano-plugin-demo/webhook/:id/:channel",
47
+ "class": "WebhookAPI",
48
+ "file": "src/main/kotlin/com/example/demo/routes/WebhookAPI.kt"
49
+ },
50
+ {
51
+ "method": "GET",
52
+ "old": "/api/other/list",
53
+ "new": "/api/plugins/pano-plugin-demo/other/list",
54
+ "relative": "/plugins/pano-plugin-demo/other/list",
55
+ "class": "GetThingsAPI",
56
+ "file": "src/main/kotlin/com/example/demo/routes/GetThingsAPI.kt"
57
+ },
58
+ {
59
+ "method": "PUT",
60
+ "old": "/api/panel/demo/things/:id",
61
+ "new": "/api/plugins/pano-plugin-demo/panel/things/:id",
62
+ "relative": "/plugins/pano-plugin-demo/panel/things/:id",
63
+ "class": "PanelSaveThingAPI",
64
+ "file": "src/main/kotlin/com/example/demo/routes/PanelThingAPI.kt"
65
+ }
66
+ ]
@@ -0,0 +1,42 @@
1
+ import java.util.Properties
2
+ import java.util.zip.ZipFile
3
+
4
+ plugins {
5
+ kotlin("jvm") version "2.2.21"
6
+ }
7
+
8
+ version = "local-build"
9
+
10
+ val pluginId: String by project
11
+
12
+ // api-level (pano-api migrate-v1): "panoApiLevel" of the pano-web-platform tree this plugin is built in, else "current" from
13
+ // the pano-api-level.properties inside the Pano jar on compileClasspath. `apiLevel=` in gradle.properties lowers it.
14
+ val panoApiLevel: String? by lazy {
15
+ (findProperty("apiLevel") as String?)
16
+ ?: (rootProject.findProperty("panoApiLevel") as String?)
17
+ ?: configurations.findByName("compileClasspath")?.files?.firstNotNullOfOrNull { jar ->
18
+ if (!jar.isFile || !jar.name.endsWith(".jar")) null
19
+ else ZipFile(jar).use { zip ->
20
+ zip.getEntry("pano-api-level.properties")?.let { entry ->
21
+ Properties().apply { load(zip.getInputStream(entry)) }.getProperty("current")
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ val pluginName: String by project
28
+ val pluginPanoVersion: String by project
29
+
30
+ tasks {
31
+ shadowJar {
32
+ manifest {
33
+ attributes["id"] = pluginId
34
+ panoApiLevel?.let { attributes["api-level"] = it }
35
+ attributes["name"] = pluginName
36
+ attributes["pano-version"] = pluginPanoVersion
37
+ attributes["version"] = version
38
+ }
39
+
40
+ archiveFileName.set("$pluginId-$version.jar")
41
+ }
42
+ }
@@ -0,0 +1,4 @@
1
+ pluginId=pano-plugin-demo
2
+ pluginName=Demo
3
+ pluginPanoVersion=local-build
4
+ pluginClass=com.example.demo.DemoPlugin
@@ -0,0 +1,13 @@
1
+ package com.example.demo.base
2
+
3
+ import com.panomc.platform.model.Api
4
+ import com.panomc.platform.model.PanelApi
5
+
6
+ /** Base of the site endpoints. KDoc nests: /* inner */ still a comment. */
7
+ abstract class DemoApi : Api() {
8
+ open val needsLogin = false
9
+ }
10
+
11
+ abstract class DemoPanelApi : PanelApi()
12
+
13
+ abstract class DemoMiddleApi : DemoApi()
@@ -0,0 +1,16 @@
1
+ package com.example.demo.error
2
+
3
+ import com.panomc.platform.model.Error
4
+
5
+ class EmptyCart : Error("EMPTY_CART", 400)
6
+
7
+ class NotFoundThing(extras: Map<String, Any?> = mapOf()) : Error("NOT_FOUND_THING", 404, extras = extras)
8
+
9
+ class TwoFactorRequired : Error("TWO_FACTOR_REQUIRED")
10
+
11
+ class MultiLine : Error("MULTI_LINE",
12
+ 403,
13
+ "forbidden"
14
+ )
15
+
16
+ class AlreadyMigrated : Error("ALREADY_MIGRATED", 409)
@@ -0,0 +1,4 @@
1
+ package com.example.demo.error
2
+
3
+ // kotlin.Error: not imported from the platform, so step b must leave it alone.
4
+ class Plain : Error("just a message")
@@ -0,0 +1,16 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoMiddleApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+
8
+ // The base class is found through two supertypes: DemoMiddleApi -> DemoApi -> Api.
9
+ @Endpoint
10
+ class GetThingsAPI(private val plugin: DemoPlugin) : DemoMiddleApi() {
11
+ override val paths = listOf(
12
+ Path("/things", RouteType.GET),
13
+ Path("/things/:id", RouteType.GET),
14
+ Path("/other/list", RouteType.GET)
15
+ )
16
+ }
@@ -0,0 +1,11 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoPanelApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+
8
+ @Endpoint
9
+ class PanelSaveThingAPI : DemoPanelApi() {
10
+ override val paths = listOf(Path("/things/:id", RouteType.PUT))
11
+ }
@@ -0,0 +1,18 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+ import io.vertx.ext.web.validation.ValidationHandler
8
+ import com.panomc.platform.schema.dsl.Bodies.json
9
+ import com.panomc.platform.schema.dsl.Parameters.param
10
+ import com.panomc.platform.schema.dsl.ValidationHandlerBuilder
11
+
12
+ @Endpoint
13
+ class ValidatedAPI : DemoApi() {
14
+ override val paths = listOf(Path("/validated", RouteType.POST))
15
+
16
+ // "/api/demo/not-a-path" inside a string that is not a Path is left alone by step a
17
+ val doc = "see /api/demo/validated"
18
+ }
@@ -0,0 +1,23 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+
8
+ @Endpoint
9
+ class WebhookAPI : DemoApi() {
10
+ override val paths = listOf(
11
+ Path(WEBHOOK_PATH, RouteType.ROUTE),
12
+ Path("$WEBHOOK_PATH/:channel", RouteType.ROUTE),
13
+ Path(Inbound.RETURN_PATH + "/:name", RouteType.GET)
14
+ )
15
+
16
+ companion object {
17
+ const val WEBHOOK_PATH = "/webhook/:id"
18
+ }
19
+ }
20
+
21
+ object Inbound {
22
+ const val RETURN_PATH = "/payments/:providerId/return"
23
+ }
@@ -0,0 +1,4 @@
1
+ import ApiUtil from '@panomc/sdk/utils/api';
2
+
3
+ export const addons = () => ApiUtil.get({ path: '/panel/addons' });
4
+ export const thing = (id) => ApiUtil.get({ path: `/plugins/pano-plugin-demo/panel/things/${id}` });
@@ -0,0 +1,9 @@
1
+ <script>
2
+ export let id;
3
+ const socket = new WebSocket(`ws://${location.host}/api/v1/ws`);
4
+ const ping = () => fetch('/api/plugins/pano-plugin-demo/panel/things/1', { method: 'PUT' });
5
+ </script>
6
+
7
+ <img src="/api/v1/website-logo" alt="logo" />
8
+ <a href="/api/plugins/pano-plugin-demo/things/{id}">things</a>
9
+ <p>Don't break on an apostrophe in the markup</p>
@@ -0,0 +1,29 @@
1
+ import ApiUtil from '@panomc/sdk/utils/api';
2
+
3
+ export async function load(event, id, body) {
4
+ const things = await ApiUtil.get({ path: '/plugins/pano-plugin-demo/things', request: event });
5
+ if (!things.error) {
6
+ console.log(things.items);
7
+ }
8
+ if (things.error?.code === 'NOT_FOUND_THING') {
9
+ return null;
10
+ }
11
+
12
+ // not an API value: must stay as it is
13
+ const other = { error: 'X', result: 'ok', errors: {} };
14
+ if (other.error === 'X') {
15
+ console.log(other.errors, other.result);
16
+ }
17
+
18
+ const saved = await ApiUtil.post({ path: `/plugins/pano-plugin-demo/things/${id}`, body });
19
+ if (!!saved.error) {
20
+ return saved.error?.fields;
21
+ }
22
+
23
+ ApiUtil.get({ path: '/site-info' }).then((res) => {
24
+ if (res.error?.code !== 'A') return !!res.error;
25
+ });
26
+
27
+ const hook = await ApiUtil.get({ path: `/plugins/pano-plugin-demo/payments/${id}/return/done?x=1` });
28
+ return !hook.error;
29
+ }
@@ -0,0 +1,22 @@
1
+ plugins {
2
+ kotlin("jvm") version "2.2.21"
3
+ }
4
+
5
+ version = "local-build"
6
+
7
+ val pluginId: String by project
8
+ val pluginName: String by project
9
+ val pluginPanoVersion: String by project
10
+
11
+ tasks {
12
+ shadowJar {
13
+ manifest {
14
+ attributes["id"] = pluginId
15
+ attributes["name"] = pluginName
16
+ attributes["pano-version"] = pluginPanoVersion
17
+ attributes["version"] = version
18
+ }
19
+
20
+ archiveFileName.set("$pluginId-$version.jar")
21
+ }
22
+ }
@@ -0,0 +1,4 @@
1
+ pluginId=pano-plugin-demo
2
+ pluginName=Demo
3
+ pluginPanoVersion=local-build
4
+ pluginClass=com.example.demo.DemoPlugin
@@ -0,0 +1,13 @@
1
+ package com.example.demo.base
2
+
3
+ import com.panomc.platform.model.Api
4
+ import com.panomc.platform.model.PanelApi
5
+
6
+ /** Base of the site endpoints. KDoc nests: /* inner */ still a comment. */
7
+ abstract class DemoApi : Api() {
8
+ open val needsLogin = false
9
+ }
10
+
11
+ abstract class DemoPanelApi : PanelApi()
12
+
13
+ abstract class DemoMiddleApi : DemoApi()
@@ -0,0 +1,16 @@
1
+ package com.example.demo.error
2
+
3
+ import com.panomc.platform.model.Error
4
+
5
+ class EmptyCart : Error(400)
6
+
7
+ class NotFoundThing(extras: Map<String, Any?> = mapOf()) : Error(404, extras = extras)
8
+
9
+ class TwoFactorRequired : Error()
10
+
11
+ class MultiLine : Error(
12
+ 403,
13
+ "forbidden"
14
+ )
15
+
16
+ class AlreadyMigrated : Error("ALREADY_MIGRATED", 409)
@@ -0,0 +1,4 @@
1
+ package com.example.demo.error
2
+
3
+ // kotlin.Error: not imported from the platform, so step b must leave it alone.
4
+ class Plain : Error("just a message")
@@ -0,0 +1,16 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoMiddleApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+
8
+ // The base class is found through two supertypes: DemoMiddleApi -> DemoApi -> Api.
9
+ @Endpoint
10
+ class GetThingsAPI(private val plugin: DemoPlugin) : DemoMiddleApi() {
11
+ override val paths = listOf(
12
+ Path("/api/demo/things", RouteType.GET),
13
+ Path("/api/demo/things/:id", RouteType.GET),
14
+ Path("/api/other/list", RouteType.GET)
15
+ )
16
+ }
@@ -0,0 +1,11 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoPanelApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+
8
+ @Endpoint
9
+ class PanelSaveThingAPI : DemoPanelApi() {
10
+ override val paths = listOf(Path("/api/panel/demo/things/:id", RouteType.PUT))
11
+ }
@@ -0,0 +1,18 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+ import io.vertx.ext.web.validation.ValidationHandler
8
+ import io.vertx.ext.web.validation.builder.Bodies.json
9
+ import io.vertx.ext.web.validation.builder.Parameters.param
10
+ import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder
11
+
12
+ @Endpoint
13
+ class ValidatedAPI : DemoApi() {
14
+ override val paths = listOf(Path("/api/demo/validated", RouteType.POST))
15
+
16
+ // "/api/demo/not-a-path" inside a string that is not a Path is left alone by step a
17
+ val doc = "see /api/demo/validated"
18
+ }
@@ -0,0 +1,23 @@
1
+ package com.example.demo.routes
2
+
3
+ import com.example.demo.base.DemoApi
4
+ import com.panomc.platform.annotation.Endpoint
5
+ import com.panomc.platform.model.Path
6
+ import com.panomc.platform.model.RouteType
7
+
8
+ @Endpoint
9
+ class WebhookAPI : DemoApi() {
10
+ override val paths = listOf(
11
+ Path(WEBHOOK_PATH, RouteType.ROUTE),
12
+ Path("$WEBHOOK_PATH/:channel", RouteType.ROUTE),
13
+ Path(Inbound.RETURN_PATH + "/:name", RouteType.GET)
14
+ )
15
+
16
+ companion object {
17
+ const val WEBHOOK_PATH = "/api/demo/webhook/:id"
18
+ }
19
+ }
20
+
21
+ object Inbound {
22
+ const val RETURN_PATH = "/api/demo/payments/:providerId/return"
23
+ }
@@ -0,0 +1,4 @@
1
+ import ApiUtil from '@panomc/sdk/utils/api';
2
+
3
+ export const addons = () => ApiUtil.get({ path: '/api/panel/plugins' });
4
+ export const thing = (id) => ApiUtil.get({ path: `/api/panel/demo/things/${id}` });
@@ -0,0 +1,9 @@
1
+ <script>
2
+ export let id;
3
+ const socket = new WebSocket(`ws://${location.host}/api/ws`);
4
+ const ping = () => fetch('/api/panel/demo/things/1', { method: 'PUT' });
5
+ </script>
6
+
7
+ <img src="/api/websiteLogo" alt="logo" />
8
+ <a href="/api/demo/things/{id}">things</a>
9
+ <p>Don't break on an apostrophe in the markup</p>
@@ -0,0 +1,29 @@
1
+ import ApiUtil from '@panomc/sdk/utils/api';
2
+
3
+ export async function load(event, id, body) {
4
+ const things = await ApiUtil.get({ path: '/api/demo/things', request: event });
5
+ if (things.result === 'ok') {
6
+ console.log(things.items);
7
+ }
8
+ if (things.error === 'NOT_FOUND_THING') {
9
+ return null;
10
+ }
11
+
12
+ // not an API value: must stay as it is
13
+ const other = { error: 'X', result: 'ok', errors: {} };
14
+ if (other.error === 'X') {
15
+ console.log(other.errors, other.result);
16
+ }
17
+
18
+ const saved = await ApiUtil.post({ path: `/api/demo/things/${id}`, body });
19
+ if (saved.result === 'error') {
20
+ return saved.errors;
21
+ }
22
+
23
+ ApiUtil.get({ path: '/api/siteInfo' }).then((res) => {
24
+ if (res.error !== 'A') return res.result !== 'ok';
25
+ });
26
+
27
+ const hook = await ApiUtil.get({ path: `/api/demo/payments/${id}/return/done?x=1` });
28
+ return hook.result == 'ok';
29
+ }
@@ -0,0 +1 @@
1
+ pluginId=pano-plugin-bad
@@ -0,0 +1,39 @@
1
+ package x
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class LegacyAPI : Api() {
8
+ override val paths = listOf(Path("/api/posts", RouteType.GET))
9
+ }
10
+
11
+ @Endpoint
12
+ class NoSlashAPI : Api() {
13
+ override val paths = listOf(Path("hello", RouteType.GET))
14
+ }
15
+
16
+ @Endpoint
17
+ class PanelPrefixAPI : Api() {
18
+ override val paths = listOf(Path("/panel/settings", RouteType.GET))
19
+ }
20
+
21
+ @Endpoint
22
+ class ParamFirstAPI : Api() {
23
+ override val paths = listOf(Path("/:id", RouteType.GET))
24
+ }
25
+
26
+ @Endpoint
27
+ class ReservedAPI : Api() {
28
+ override val paths = listOf(Path("/_/x", RouteType.GET))
29
+ }
30
+
31
+ @Endpoint
32
+ class DupOneAPI : Api() {
33
+ override val paths = listOf(Path("/items/:id", RouteType.GET))
34
+ }
35
+
36
+ @Endpoint
37
+ class DupTwoAPI : Api() {
38
+ override val paths = listOf(Path("/items/:other", RouteType.GET))
39
+ }
@@ -0,0 +1,19 @@
1
+ package x
2
+
3
+ import com.panomc.platform.annotation.Endpoint
4
+ import com.panomc.platform.model.*
5
+
6
+ @Endpoint
7
+ class OrphanAPI : Unknown() {
8
+ override val paths = listOf(Path("/orphan", RouteType.GET))
9
+ }
10
+
11
+ @Endpoint
12
+ class NoPathAPI : Api() {
13
+ override val paths = emptyList<Path>()
14
+ }
15
+
16
+ @Endpoint
17
+ class BadConstAPI : Api() {
18
+ override val paths = listOf(Path(MISSING_CONST, RouteType.GET))
19
+ }
@@ -0,0 +1,48 @@
1
+ // Shared test helpers: fixture copies in a temp dir and directory snapshots.
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ export const HERE = path.dirname(fileURLToPath(import.meta.url));
8
+ export const FIXTURES = path.join(HERE, 'fixtures');
9
+ export const CLI = path.join(HERE, '..', '..', 'pano-api.js');
10
+ const made = [];
11
+
12
+ /** Copies a fixture folder into a fresh temp dir. @param {string} name */
13
+ export function copyFixture(name) {
14
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pano-api-test-'));
15
+ made.push(dir);
16
+ fs.cpSync(path.join(FIXTURES, name), dir, { recursive: true });
17
+ return dir;
18
+ }
19
+
20
+ export function tempDir() {
21
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pano-api-test-'));
22
+ made.push(dir);
23
+ return dir;
24
+ }
25
+
26
+ export function cleanup() {
27
+ for (const d of made.splice(0)) fs.rmSync(d, { recursive: true, force: true });
28
+ }
29
+
30
+ /** @param {string} dir @returns {Record<string, string>} relative path -> content */
31
+ export function snapshot(dir) {
32
+ const out = {};
33
+ const visit = (d) => {
34
+ for (const e of fs.readdirSync(d, { withFileTypes: true })) {
35
+ const full = path.join(d, e.name);
36
+ if (e.isDirectory()) visit(full);
37
+ else out[path.relative(dir, full).split(path.sep).join('/')] = fs.readFileSync(full, 'utf8');
38
+ }
39
+ };
40
+ visit(dir);
41
+ return out;
42
+ }
43
+
44
+ /** Runs the CLI in-process-free (child process) and returns { code, stdout, stderr }. */
45
+ export function runCli(args, cwd) {
46
+ const r = Bun.spawnSync(['node', CLI, ...args], { cwd: cwd || HERE });
47
+ return { code: r.exitCode, stdout: r.stdout.toString(), stderr: r.stderr.toString() };
48
+ }