@uns-kit/api 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,16 +16,25 @@ Make sure `@uns-kit/core` is also installed; the plugin augments its runtime typ
16
16
 
17
17
  ```ts
18
18
  import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process";
19
- import unsApiPlugin, { type UnsProxyProcessWithApi } from "@uns-kit/api";
19
+ import type { UnsProxyProcessWithApi } from "@uns-kit/api";
20
+ import "@uns-kit/api"; // registers the plugin side-effect
20
21
 
21
- const process = new UnsProxyProcess("mqtt-broker:1883", { processName: "api-gateway" }) as UnsProxyProcessWithApi;
22
- unsApiPlugin;
22
+ async function main() {
23
+ const process = new UnsProxyProcess("mqtt-broker:1883", { processName: "api-gateway" }) as UnsProxyProcessWithApi;
23
24
 
24
- const api = await process.createApiProxy("gateway", { jwtSecret: "super-secret" });
25
- await api.get("factory/", "status", {
26
- apiDescription: "Factory status endpoint",
27
- tags: ["status"],
28
- });
25
+ const api = await process.createApiProxy("gateway", { jwtSecret: "super-secret" });
26
+
27
+ api.get("factory/", "status", {
28
+ apiDescription: "Factory status endpoint",
29
+ tags: ["status"],
30
+ });
31
+
32
+ api.event.on("apiGetEvent", (event) => {
33
+ event.res.json({ status: "ok" });
34
+ });
35
+ }
36
+
37
+ void main();
29
38
  ```
30
39
 
31
40
  ## Scripts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/api",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Express-powered API gateway plugin for UnsProxyProcess with JWT/JWKS support.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,6 +22,10 @@
22
22
  "dist"
23
23
  ],
24
24
  "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
25
29
  "./*": "./dist/*"
26
30
  },
27
31
  "main": "dist/index.js",
@@ -31,7 +35,7 @@
31
35
  "cookie-parser": "^1.4.7",
32
36
  "express": "^5.1.0",
33
37
  "multer": "^2.0.2",
34
- "@uns-kit/core": "0.0.19"
38
+ "@uns-kit/core": "0.0.22"
35
39
  },
36
40
  "devDependencies": {
37
41
  "@types/jsonwebtoken": "^9.0.10",
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process";
2
- import unsApiPlugin from "./uns-api-plugin.js";
3
- import { ConfigFile } from "@uns-kit/core/config-file";
4
- /**
5
- * Load the configuration from a file.
6
- * On the server, this file is provided by the `uns-datahub-controller`.
7
- * In the development environment, you are responsible for creating and maintaining this file and its contents.
8
- */
9
- const config = await ConfigFile.loadConfig();
10
- /**
11
- * Connect to the API proxy process
12
- */
13
- const unsProxyProcess = new UnsProxyProcess(config.infra.host, { processName: config.uns.processName });
14
- unsApiPlugin;
15
- const apiOptions = config.uns?.jwksWellKnownUrl
16
- ? {
17
- jwks: {
18
- wellKnownJwksUrl: config.uns.jwksWellKnownUrl,
19
- activeKidUrl: config.uns.kidWellKnownUrl,
20
- },
21
- }
22
- : {
23
- jwtSecret: "CHANGEME",
24
- };
25
- const apiInput = await unsProxyProcess.createApiProxy("templateUnsApiInput", apiOptions);
26
- /**
27
- * Register an API endpoint and event handler
28
- */
29
- apiInput.get("sij/", "summary-1", {
30
- tags: ["Tag1"],
31
- apiDescription: "Test API endpoint 1",
32
- queryParams: [
33
- { name: "filter", type: "string", required: true, description: "Filter za podatke" },
34
- { name: "limit", type: "number", required: false, description: "Koliko podatkov želiš" },
35
- ]
36
- });
37
- apiInput.get("sij/", "summary-2", {
38
- tags: ["Tag2"],
39
- apiDescription: "Test API endpoint 2",
40
- queryParams: [
41
- { name: "filter", type: "string", required: true, description: "Filter za podatke" },
42
- { name: "limit", type: "number", required: false, description: "Koliko podatkov želiš" },
43
- ]
44
- });
45
- apiInput.event.on("apiGetEvent", (event) => {
46
- try {
47
- const appContext = event.req.appContext;
48
- // Add SQL query or any other code here
49
- event.res.send("OK");
50
- }
51
- catch (error) {
52
- event.res.status(400).send("Error");
53
- }
54
- });