@armdesk/connect-sdk 0.0.0-stage → 1.1.0

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 (49) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE.txt +15 -0
  3. package/README.md +525 -3
  4. package/dist/armdesk-connect.js +41 -0
  5. package/dist/esm/browser.d.ts +3 -0
  6. package/dist/esm/browser.js +18 -0
  7. package/dist/esm/client.d.ts +46 -0
  8. package/dist/esm/client.js +307 -0
  9. package/dist/esm/defaults.d.ts +8 -0
  10. package/dist/esm/defaults.js +22 -0
  11. package/dist/esm/elements.d.ts +3 -0
  12. package/dist/esm/elements.js +368 -0
  13. package/dist/esm/errors.d.ts +12 -0
  14. package/dist/esm/errors.js +34 -0
  15. package/dist/esm/handler.d.ts +40 -0
  16. package/dist/esm/handler.js +106 -0
  17. package/dist/esm/http.d.ts +22 -0
  18. package/dist/esm/http.js +66 -0
  19. package/dist/esm/index.d.ts +30 -0
  20. package/dist/esm/index.js +30 -0
  21. package/dist/esm/messenger.d.ts +8 -0
  22. package/dist/esm/messenger.js +269 -0
  23. package/dist/esm/mount.d.ts +8 -0
  24. package/dist/esm/mount.js +213 -0
  25. package/dist/esm/protocol.d.ts +37 -0
  26. package/dist/esm/protocol.js +57 -0
  27. package/dist/esm/react.d.ts +89 -0
  28. package/dist/esm/react.js +311 -0
  29. package/dist/esm/register.d.ts +1 -0
  30. package/dist/esm/register.js +5 -0
  31. package/dist/esm/sanitize.d.ts +8 -0
  32. package/dist/esm/sanitize.js +57 -0
  33. package/dist/esm/server.d.ts +17 -0
  34. package/dist/esm/server.js +93 -0
  35. package/dist/esm/sign.d.ts +54 -0
  36. package/dist/esm/sign.js +77 -0
  37. package/dist/esm/theme.d.ts +8 -0
  38. package/dist/esm/theme.js +46 -0
  39. package/dist/esm/types.d.ts +375 -0
  40. package/dist/esm/types.js +1 -0
  41. package/examples/express-server/package.json +10 -0
  42. package/examples/express-server/server.mjs +35 -0
  43. package/examples/mock-idp.mjs +30 -0
  44. package/examples/react-vite/index.html +11 -0
  45. package/examples/react-vite/package.json +15 -0
  46. package/examples/react-vite/src/main.jsx +25 -0
  47. package/examples/react-vite/vite.config.js +4 -0
  48. package/examples/wso2-browser.html +86 -0
  49. package/package.json +59 -4
@@ -0,0 +1,86 @@
1
+ <!doctype html>
2
+ <!--
3
+ ARM Desk Connect, browser mode (WSO2 / OIDC), no backend of your own.
4
+
5
+ Two ways to run it (open the file in a browser, or serve this folder):
6
+
7
+ 1. Standalone demo (default): a mock IdP signs an RS256 ID token in this page (WebCrypto) and a mock desk
8
+ (a fetch stub) verifies nothing but answers like ARM Desk, so you can see the flow and the library calls offline.
9
+
10
+ 2. Against a real ARM Desk: wso2-browser.html?desk=https://desk.example.com&org=org_xxx
11
+ Needs the organisation to allow Browser sessions and to trust an issuer. For a local desk run
12
+ node examples/mock-idp.mjs (serves /.well-known/jwks.json and /issuer on http://localhost:4010)
13
+ trust issuer http://localhost:4010 with audience "demo-product" in Admin > Connect > Identity, add this page's
14
+ origin to the allowed origins, and add &idp=http://localhost:4010 to the URL.
15
+ -->
16
+ <html lang="en">
17
+ <head>
18
+ <meta charset="utf-8" />
19
+ <title>ARM Desk Connect - WSO2 browser mode</title>
20
+ <style>
21
+ body { font-family: system-ui, sans-serif; max-width: 760px; margin: 2rem auto; padding: 0 1rem; }
22
+ pre { background: #f3f4f6; padding: .75rem; overflow: auto; font-size: 12px; }
23
+ code { background: #f3f4f6; }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <h1>Acme product (signed in with WSO2)</h1>
28
+ <p id="mode"></p>
29
+ <armdesk-tickets limit="5"></armdesk-tickets>
30
+ <h2>Log</h2>
31
+ <pre id="log"></pre>
32
+
33
+ <script>
34
+ const q = new URLSearchParams(location.search);
35
+ const log = (m) => { document.getElementById("log").textContent += m + "\n"; };
36
+ const b64u = (buf) => btoa(String.fromCharCode(...new Uint8Array(buf))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
37
+ const enc = (o) => b64u(new TextEncoder().encode(JSON.stringify(o)));
38
+
39
+ // ---- the mock IdP (stand-in for WSO2): signs ID tokens with RS256 ----
40
+ let keyPair;
41
+ async function mockIdToken() {
42
+ keyPair ??= await crypto.subtle.generateKey({ name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" }, true, ["sign"]);
43
+ const now = Math.floor(Date.now() / 1000);
44
+ const input = enc({ alg: "RS256", typ: "JWT", kid: "mock-1" }) + "." + enc({
45
+ iss: q.get("idp") || "https://mock-idp.local", aud: "demo-product", sub: "demo-user-1", email: "ana@example.com", email_verified: true,
46
+ given_name: "Ana", family_name: "Silva", roles: "manager", iat: now, exp: now + 300,
47
+ });
48
+ const sig = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", keyPair.privateKey, new TextEncoder().encode(input));
49
+ return input + "." + b64u(sig);
50
+ }
51
+ async function idToken() {
52
+ if (q.get("idp")) return (await (await fetch(q.get("idp") + "/issue", { method: "POST" })).json()).idToken; // mock-idp.mjs
53
+ return mockIdToken();
54
+ }
55
+
56
+ // ---- standalone: a stub desk so the page works offline ----
57
+ const standalone = !q.get("desk");
58
+ const stubDesk = async (url, init = {}) => {
59
+ const path = new URL(url, location.href).pathname;
60
+ const reply = (b, s = 200) => new Response(JSON.stringify(b), { status: s, headers: { "Content-Type": "application/json" } });
61
+ log(`desk <- ${init.method || "GET"} ${path}`);
62
+ if (path.endsWith("/sessions/browser")) return reply({ token: "demo-connect-token", expiresIn: 900, user: { id: "u1" } });
63
+ if (path.endsWith("/config")) return reply({ organization: { name: "Acme" }, theme: { primaryColor: "#0f766e" }, features: {} });
64
+ if (path.endsWith("/tickets")) return reply({ items: [{ id: "t1", number: "TKT-1042", subject: "VPN drops every hour", status: "OPEN", priority: "HIGH", createdAt: "", updatedAt: new Date().toISOString(), lastReplyAt: null }], total: 1 });
65
+ return reply({ message: "not in the demo" }, 404);
66
+ };
67
+
68
+ document.getElementById("mode").textContent = standalone ? "Standalone demo: mock IdP + stub desk." : "Real desk: " + q.get("desk");
69
+ </script>
70
+ <!-- In your product: <script src="https://<your-desk>/connect/armdesk-connect.js"></script>
71
+ For this example the built script is expected next to the package: ../dist/armdesk-connect.js -->
72
+ <script src="../dist/armdesk-connect.js"></script>
73
+ <script>
74
+ const client = ArmDeskConnect.init({
75
+ orgKey: q.get("org") || "org_demo",
76
+ desk: q.get("desk") || "https://desk.example.com",
77
+ apiBase: standalone ? "https://desk.example.com/api/proxy" : undefined,
78
+ fetch: standalone ? stubDesk : undefined,
79
+ auth: { idToken },
80
+ });
81
+ client.on("error", (e) => log("error: " + e.code + " " + e.message));
82
+ client.on("session.expired", () => log("session expired, sign in again"));
83
+ client.me().then((m) => log("me: " + JSON.stringify(m)), () => undefined);
84
+ </script>
85
+ </body>
86
+ </html>
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@armdesk/connect-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "ARM Desk Connect: embed ITSM tickets in another product. Headless client, web components, React, and a server helper.",
5
+ "keywords": [
6
+ "armdesk",
7
+ "embed",
8
+ "web-components",
9
+ "react",
10
+ "itsm"
11
+ ],
12
+ "author": "DHRP",
13
+ "homepage": "https://armdesk.org",
14
+ "license": "UNLICENSED",
15
+ "type": "module",
16
+ "main": "./dist/esm/index.js",
17
+ "module": "./dist/esm/index.js",
18
+ "types": "./dist/esm/index.d.ts",
19
+ "unpkg": "./dist/armdesk-connect.js",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/esm/index.d.ts",
23
+ "import": "./dist/esm/index.js"
24
+ },
25
+ "./server": {
26
+ "types": "./dist/esm/server.d.ts",
27
+ "import": "./dist/esm/server.js"
28
+ },
29
+ "./react": {
30
+ "types": "./dist/esm/react.d.ts",
31
+ "import": "./dist/esm/react.js"
32
+ },
33
+ "./elements": {
34
+ "types": "./dist/esm/register.d.ts",
35
+ "import": "./dist/esm/register.js"
36
+ },
37
+ "./iife": "./dist/armdesk-connect.js"
38
+ },
39
+ "sideEffects": [
40
+ "./dist/esm/register.js",
41
+ "./dist/esm/browser.js"
42
+ ],
43
+ "files": [
44
+ "dist",
45
+ "README.md",
46
+ "CHANGELOG.md",
47
+ "examples",
48
+ "LICENSE.txt"
49
+ ],
50
+ "peerDependencies": {
51
+ "react": ">=17"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "react": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
61
+ }