@ms-cloudpack/link-proxy 0.2.0 → 0.2.2

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.
@@ -1,2 +1,2 @@
1
- var e,r={},o={};function t(e){var n=o[e];if(void 0!==n)return n.exports;var _=o[e]={exports:{}};return r[e](_,_.exports,t),_.exports}t.m=r,t.d=(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};export default t;e={121:0},t.C=r=>{var o,n,{__webpack_ids__:_,__webpack_modules__:a,__webpack_runtime__:p}=r,i=0;for(o in a)t.o(a,o)&&(t.m[o]=a[o]);for(p&&p(t);i<_.length;i++)n=_[i],t.o(e,n)&&e[n]&&e[n][0](),e[_[i]]=0};
1
+ var e,r,t,o,n={},f={};function i(e){var r=f[e];if(void 0!==r)return r.exports;var t=f[e]={id:e,exports:{}};return n[e](t,t.exports,i),t.exports}i.m=n,i.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return i.d(r,{a:r}),r},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(t,o){if(1&o&&(t=this(t)),8&o)return t;if("object"==typeof t&&t){if(4&o&&t.__esModule)return t;if(16&o&&"function"==typeof t.then)return t}var n=Object.create(null);i.r(n);var f={};e=e||[null,r({}),r([]),r(r)];for(var u=2&o&&t;"object"==typeof u&&!~e.indexOf(u);u=r(u))Object.getOwnPropertyNames(u).forEach((e=>f[e]=()=>t[e]));return f.default=()=>t,i.d(n,f),n},i.d=(e,r)=>{for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.f={},i.e=e=>Promise.all(Object.keys(i.f).reduce(((r,t)=>(i.f[t](e,r),r)),[])),i.u=e=>e+".chunk.js",i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};export default i;t={121:0},o=e=>{var r,o,{__webpack_ids__:n,__webpack_modules__:f,__webpack_runtime__:u}=e,a=0;for(r in f)i.o(f,r)&&(i.m[r]=f[r]);for(u&&u(i);a<n.length;a++)o=n[a],i.o(t,o)&&t[o]&&t[o][0](),t[n[a]]=0},i.f.j=(e,r)=>{var n=i.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[1]);else if(121!=e){var f=import("./"+i.u(e)).then(o,(r=>{throw 0!==t[e]&&(t[e]=void 0),r}));f=Promise.race([f,new Promise((r=>n=t[e]=[r]))]),r.push(n[1]=f)}else t[e]=0},i.C=o,i.nc=void 0;
2
2
  //# sourceMappingURL=runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","mappings":"IAKIA,E,KCJAC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaE,QAGrB,IAAIC,EAASN,EAAyBE,GAAY,CAGjDG,QAAS,CAAC,GAOX,OAHAE,EAAoBL,GAAUI,EAAQA,EAAOD,QAASJ,GAG/CK,EAAOD,OACf,CAGAJ,EAAoBO,EAAID,ECxBxBN,EAAoBQ,EAAI,CAACJ,EAASK,KACjC,IAAI,IAAIC,KAAOD,EACXT,EAAoBW,EAAEF,EAAYC,KAASV,EAAoBW,EAAEP,EAASM,IAC5EE,OAAOC,eAAeT,EAASM,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDV,EAAoBW,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFjB,EAAoBqB,EAAKjB,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CX,OAAOC,eAAeT,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DZ,OAAOC,eAAeT,EAAS,aAAc,CAAEoB,OAAO,GAAO,iBCL/CxB,ELKXF,EAAkB,CACrB,IAAK,GA8BNE,EAAoByB,EA3BAC,IACnB,IAGIzB,EAAU0B,GAHV,gBAACC,EAAe,oBAAEtB,EAAmB,oBAAEuB,GAAuBH,EAG3CI,EAAI,EAC3B,IAAI7B,KAAYK,EACZN,EAAoBW,EAAEL,EAAqBL,KAC7CD,EAAoBO,EAAEN,GAAYK,EAAoBL,IAIxD,IADG4B,GAAqBA,EAAoB7B,GACvC8B,EAAIF,EAAgBG,OAAQD,IAChCH,EAAUC,EAAgBE,GACvB9B,EAAoBW,EAAEb,EAAiB6B,IAAY7B,EAAgB6B,IACrE7B,EAAgB6B,GAAS,KAE1B7B,EAAgB8B,EAAgBE,IAAM,CACvC","sources":["webpack://@ms-cloudpack/link-proxy/webpack/runtime/import chunk loading","webpack://@ms-cloudpack/link-proxy/webpack/bootstrap","webpack://@ms-cloudpack/link-proxy/webpack/runtime/define property getters","webpack://@ms-cloudpack/link-proxy/webpack/runtime/hasOwnProperty shorthand","webpack://@ms-cloudpack/link-proxy/webpack/runtime/make namespace object","webpack://@ms-cloudpack/link-proxy/webpack/runtime/export webpack runtime"],"sourcesContent":["// no baseURI\n\n// object to store loaded and loading chunks\n// undefined = chunk not loaded, null = chunk preloaded/prefetched\n// [resolve, Promise] = chunk loading, 0 = chunk loaded\nvar installedChunks = {\n\t121: 0\n};\n\nvar installChunk = (data) => {\n\tvar {__webpack_ids__, __webpack_modules__, __webpack_runtime__} = data;\n\t// add \"modules\" to the modules object,\n\t// then flag all \"ids\" as loaded and fire callback\n\tvar moduleId, chunkId, i = 0;\n\tfor(moduleId in __webpack_modules__) {\n\t\tif(__webpack_require__.o(__webpack_modules__, moduleId)) {\n\t\t\t__webpack_require__.m[moduleId] = __webpack_modules__[moduleId];\n\t\t}\n\t}\n\tif(__webpack_runtime__) __webpack_runtime__(__webpack_require__);\n\tfor(;i < __webpack_ids__.length; i++) {\n\t\tchunkId = __webpack_ids__[i];\n\t\tif(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {\n\t\t\tinstalledChunks[chunkId][0]();\n\t\t}\n\t\tinstalledChunks[__webpack_ids__[i]] = 0;\n\t}\n\n}\n\n// no chunk on demand loading\n\n// no prefetching\n\n// no preloaded\n\n__webpack_require__.C = installChunk;\n\n// no on chunks loaded","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default __webpack_require__;"],"names":["installedChunks","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","__webpack_modules__","m","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","C","data","chunkId","__webpack_ids__","__webpack_runtime__","i","length"],"sourceRoot":""}
1
+ {"version":3,"file":"runtime.js","mappings":"IACIA,EADAC,ECKAC,EAIAC,E,KCRAC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaE,QAGrB,IAAIC,EAASN,EAAyBE,GAAY,CACjDK,GAAIL,EAEJG,QAAS,CAAC,GAOX,OAHAG,EAAoBN,GAAUI,EAAQA,EAAOD,QAASJ,GAG/CK,EAAOD,OACf,CAGAJ,EAAoBQ,EAAID,ECxBxBP,EAAoBS,EAAKJ,IACxB,IAAIK,EAASL,GAAUA,EAAOM,WAC7B,IAAON,EAAiB,QACxB,IAAM,EAEP,OADAL,EAAoBY,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,EHNVd,EAAWkB,OAAOC,eAAkBC,GAASF,OAAOC,eAAeC,GAASA,GAASA,EAAa,UAQtGhB,EAAoBiB,EAAI,SAASC,EAAOC,GAEvC,GADU,EAAPA,IAAUD,EAAQE,KAAKF,IAChB,EAAPC,EAAU,OAAOD,EACpB,GAAoB,iBAAVA,GAAsBA,EAAO,CACtC,GAAW,EAAPC,GAAaD,EAAMP,WAAY,OAAOO,EAC1C,GAAW,GAAPC,GAAoC,mBAAfD,EAAMG,KAAqB,OAAOH,CAC5D,CACA,IAAII,EAAKR,OAAOS,OAAO,MACvBvB,EAAoBwB,EAAEF,GACtB,IAAIG,EAAM,CAAC,EACX9B,EAAiBA,GAAkB,CAAC,KAAMC,EAAS,CAAC,GAAIA,EAAS,IAAKA,EAASA,IAC/E,IAAI,IAAI8B,EAAiB,EAAPP,GAAYD,EAAyB,iBAAXQ,KAAyB/B,EAAegC,QAAQD,GAAUA,EAAU9B,EAAS8B,GACxHZ,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AAgByC,GAAS,KAE1BzC,EAAgBuD,EAAgBE,IAAM,CACvC,EAIDtD,EAAoBoC,EAAEoB,EAAI,CAAClB,EAASK,KAElC,IAAIc,EAAqBzD,EAAoBgC,EAAEnC,EAAiByC,GAAWzC,EAAgByC,QAAWnC,EACtG,GAA0B,IAAvBsD,EAGF,GAAGA,EACFd,EAASe,KAAKD,EAAmB,SAEjC,GAAG,KAAOnB,EAAS,CAElB,IAAIqB,EAAUC,OAAO,KAAO5D,EAAoB4C,EAAEN,IAAUjB,KAAKvB,GAAeuC,IAE/E,MADgC,IAA7BxC,EAAgByC,KAAgBzC,EAAgByC,QAAWnC,GACxDkC,CAAC,IAEJsB,EAAUpB,QAAQsB,KAAK,CAACF,EAAS,IAAIpB,SAASuB,GAAaL,EAAqB5D,EAAgByC,GAAW,CAACwB,OAChHnB,EAASe,KAAKD,EAAmB,GAAKE,EACvC,MAAO9D,EAAgByC,GAAW,CAEpC,EAOFtC,EAAoB+D,EAAIjE,ESxDxBE,EAAoBgE,QAAK7D","sources":["webpack://@ms-cloudpack/link-proxy/webpack/runtime/create fake namespace object","webpack://@ms-cloudpack/link-proxy/webpack/runtime/import chunk loading","webpack://@ms-cloudpack/link-proxy/webpack/bootstrap","webpack://@ms-cloudpack/link-proxy/webpack/runtime/compat get default export","webpack://@ms-cloudpack/link-proxy/webpack/runtime/define property getters","webpack://@ms-cloudpack/link-proxy/webpack/runtime/ensure chunk","webpack://@ms-cloudpack/link-proxy/webpack/runtime/get javascript chunk filename","webpack://@ms-cloudpack/link-proxy/webpack/runtime/hasOwnProperty shorthand","webpack://@ms-cloudpack/link-proxy/webpack/runtime/make namespace object","webpack://@ms-cloudpack/link-proxy/webpack/runtime/export webpack runtime","webpack://@ms-cloudpack/link-proxy/webpack/runtime/nonce"],"sourcesContent":["var getProto = Object.getPrototypeOf ? (obj) => (Object.getPrototypeOf(obj)) : (obj) => (obj.__proto__);\nvar leafPrototypes;\n// create a fake namespace object\n// mode & 1: value is a module id, require it\n// mode & 2: merge all properties of value into the ns\n// mode & 4: return value when already ns object\n// mode & 16: return value when it's Promise-like\n// mode & 8|1: behave like require\n__webpack_require__.t = function(value, mode) {\n\tif(mode & 1) value = this(value);\n\tif(mode & 8) return value;\n\tif(typeof value === 'object' && value) {\n\t\tif((mode & 4) && value.__esModule) return value;\n\t\tif((mode & 16) && typeof value.then === 'function') return value;\n\t}\n\tvar ns = Object.create(null);\n\t__webpack_require__.r(ns);\n\tvar def = {};\n\tleafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];\n\tfor(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {\n\t\tObject.getOwnPropertyNames(current).forEach((key) => (def[key] = () => (value[key])));\n\t}\n\tdef['default'] = () => (value);\n\t__webpack_require__.d(ns, def);\n\treturn ns;\n};","// no baseURI\n\n// object to store loaded and loading chunks\n// undefined = chunk not loaded, null = chunk preloaded/prefetched\n// [resolve, Promise] = chunk loading, 0 = chunk loaded\nvar installedChunks = {\n\t121: 0\n};\n\nvar installChunk = (data) => {\n\tvar {__webpack_ids__, __webpack_modules__, __webpack_runtime__} = data;\n\t// add \"modules\" to the modules object,\n\t// then flag all \"ids\" as loaded and fire callback\n\tvar moduleId, chunkId, i = 0;\n\tfor(moduleId in __webpack_modules__) {\n\t\tif(__webpack_require__.o(__webpack_modules__, moduleId)) {\n\t\t\t__webpack_require__.m[moduleId] = __webpack_modules__[moduleId];\n\t\t}\n\t}\n\tif(__webpack_runtime__) __webpack_runtime__(__webpack_require__);\n\tfor(;i < __webpack_ids__.length; i++) {\n\t\tchunkId = __webpack_ids__[i];\n\t\tif(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {\n\t\t\tinstalledChunks[chunkId][0]();\n\t\t}\n\t\tinstalledChunks[__webpack_ids__[i]] = 0;\n\t}\n\n}\n\n__webpack_require__.f.j = (chunkId, promises) => {\n\t\t// import() chunk loading for javascript\n\t\tvar installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;\n\t\tif(installedChunkData !== 0) { // 0 means \"already installed\".\n\n\t\t\t// a Promise means \"currently loading\".\n\t\t\tif(installedChunkData) {\n\t\t\t\tpromises.push(installedChunkData[1]);\n\t\t\t} else {\n\t\t\t\tif(121 != chunkId) {\n\t\t\t\t\t// setup Promise in chunk cache\n\t\t\t\t\tvar promise = import(\"./\" + __webpack_require__.u(chunkId)).then(installChunk, (e) => {\n\t\t\t\t\t\tif(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;\n\t\t\t\t\t\tthrow e;\n\t\t\t\t\t});\n\t\t\t\t\tvar promise = Promise.race([promise, new Promise((resolve) => (installedChunkData = installedChunks[chunkId] = [resolve]))])\n\t\t\t\t\tpromises.push(installedChunkData[1] = promise);\n\t\t\t\t} else installedChunks[chunkId] = 0;\n\t\t\t}\n\t\t}\n};\n\n// no prefetching\n\n// no preloaded\n\n__webpack_require__.C = installChunk;\n\n// no on chunks loaded","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\tid: moduleId,\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.f = {};\n// This file contains only the entry chunk.\n// The chunk loading function for additional chunks\n__webpack_require__.e = (chunkId) => {\n\treturn Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {\n\t\t__webpack_require__.f[key](chunkId, promises);\n\t\treturn promises;\n\t}, []));\n};","// This function allow to reference async chunks\n__webpack_require__.u = (chunkId) => {\n\t// return url for filenames based on template\n\treturn \"\" + chunkId + \".chunk.js\";\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default __webpack_require__;","__webpack_require__.nc = undefined;"],"names":["leafPrototypes","getProto","installedChunks","installChunk","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","id","__webpack_modules__","m","n","getter","__esModule","d","a","Object","getPrototypeOf","obj","t","value","mode","this","then","ns","create","r","def","current","indexOf","getOwnPropertyNames","forEach","key","definition","o","defineProperty","enumerable","get","f","e","chunkId","Promise","all","keys","reduce","promises","u","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","data","__webpack_ids__","__webpack_runtime__","i","length","j","installedChunkData","push","promise","import","race","resolve","C","nc"],"sourceRoot":""}
@@ -0,0 +1,41 @@
1
+ import type { CloudpackClient } from '@ms-cloudpack/api-server/browser';
2
+ type ClientId = 'link' | 'host';
3
+ /**
4
+ * Connection Manager for handling client connections
5
+ */
6
+ export declare class ConnectionManager {
7
+ private clients;
8
+ private connectionStates;
9
+ private checkInterval;
10
+ private readonly checkIntervalMs;
11
+ /**
12
+ * Add a client to be monitored
13
+ */
14
+ addClient(id: ClientId, client: CloudpackClient): void;
15
+ /**
16
+ * Get a client by ID
17
+ */
18
+ getClient(id: ClientId): CloudpackClient | undefined;
19
+ /**
20
+ * Check if a client is connected
21
+ */
22
+ checkConnection(id: ClientId): Promise<boolean>;
23
+ /**
24
+ * Start monitoring all client connections
25
+ */
26
+ startMonitoring(onConnectionChange: (params: {
27
+ id: ClientId;
28
+ isConnected: boolean;
29
+ wasConnected: boolean;
30
+ }) => Promise<void>): void;
31
+ /**
32
+ * Stop monitoring connections
33
+ */
34
+ stopMonitoring(): void;
35
+ /**
36
+ * Close all clients
37
+ */
38
+ closeAll(): Promise<void>;
39
+ }
40
+ export {};
41
+ //# sourceMappingURL=ConnectionManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionManager.d.ts","sourceRoot":"","sources":["../src/ConnectionManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAExE,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgB;IAEhD;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI;IAKtD;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,eAAe,GAAG,SAAS;IAIpD;;OAEG;IACG,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAarD;;OAEG;IACH,eAAe,CACb,kBAAkB,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,QAAQ,CAAC;QAAC,WAAW,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAC3G,IAAI;IAyBP;;OAEG;IACH,cAAc,IAAI,IAAI;IAOtB;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAYhC"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Connection Manager for handling client connections
3
+ */
4
+ export class ConnectionManager {
5
+ clients = new Map();
6
+ connectionStates = new Map();
7
+ checkInterval = null;
8
+ checkIntervalMs = 5000; // 5 seconds
9
+ /**
10
+ * Add a client to be monitored
11
+ */
12
+ addClient(id, client) {
13
+ this.clients.set(id, client);
14
+ this.connectionStates.set(id, true);
15
+ }
16
+ /**
17
+ * Get a client by ID
18
+ */
19
+ getClient(id) {
20
+ return this.clients.get(id);
21
+ }
22
+ /**
23
+ * Check if a client is connected
24
+ */
25
+ async checkConnection(id) {
26
+ const client = this.clients.get(id);
27
+ if (!client)
28
+ return false;
29
+ try {
30
+ await client.getSessionId.query();
31
+ return true;
32
+ }
33
+ catch (e) {
34
+ console.warn(`${id} client connection lost:`, e);
35
+ return false;
36
+ }
37
+ }
38
+ /**
39
+ * Start monitoring all client connections
40
+ */
41
+ startMonitoring(onConnectionChange) {
42
+ if (this.checkInterval) {
43
+ window.clearInterval(this.checkInterval);
44
+ }
45
+ this.checkInterval = window.setInterval(() => {
46
+ (async () => {
47
+ for (const [id, _] of this.clients) {
48
+ if (id != 'link' && id != 'host')
49
+ throw new Error(`Invalid client ID: ${id}`);
50
+ const wasConnected = this.connectionStates.get(id) || false;
51
+ const isConnected = await this.checkConnection(id);
52
+ if (wasConnected !== isConnected) {
53
+ await onConnectionChange({ id, isConnected, wasConnected });
54
+ }
55
+ this.connectionStates.set(id, isConnected);
56
+ }
57
+ })().catch((error) => {
58
+ console.error('Error in connection monitoring:', error);
59
+ });
60
+ }, this.checkIntervalMs);
61
+ }
62
+ /**
63
+ * Stop monitoring connections
64
+ */
65
+ stopMonitoring() {
66
+ if (this.checkInterval) {
67
+ window.clearInterval(this.checkInterval);
68
+ this.checkInterval = null;
69
+ }
70
+ }
71
+ /**
72
+ * Close all clients
73
+ */
74
+ async closeAll() {
75
+ for (const [id, client] of this.clients) {
76
+ try {
77
+ await client.close();
78
+ console.log(`Closed ${id} client`);
79
+ }
80
+ catch (err) {
81
+ console.error(`Error closing ${id} client:`, err);
82
+ }
83
+ }
84
+ this.clients.clear();
85
+ this.connectionStates.clear();
86
+ }
87
+ }
88
+ //# sourceMappingURL=ConnectionManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionManager.js","sourceRoot":"","sources":["../src/ConnectionManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACpB,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC7C,gBAAgB,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC9C,aAAa,GAAkB,IAAI,CAAC;IAC3B,eAAe,GAAW,IAAI,CAAC,CAAC,YAAY;IAE7D;;OAEG;IACH,SAAS,CAAC,EAAY,EAAE,MAAuB;QAC7C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,EAAY;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,EAAY;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAE1B,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAA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AE,CAAC;YACvB,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACzC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,KAAK,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACxC,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;gBACrB,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { CloudpackClient } from '@ms-cloudpack/api-server/browser';\n\ntype ClientId = 'link' | 'host';\n\n/**\n * Connection Manager for handling client connections\n */\nexport class ConnectionManager {\n private clients = new Map<string, CloudpackClient>();\n private connectionStates = new Map<string, boolean>();\n private checkInterval: number | null = null;\n private readonly checkIntervalMs: number = 5000; // 5 seconds\n\n /**\n * Add a client to be monitored\n */\n addClient(id: ClientId, client: CloudpackClient): void {\n this.clients.set(id, client);\n this.connectionStates.set(id, true);\n }\n\n /**\n * Get a client by ID\n */\n getClient(id: ClientId): CloudpackClient | undefined {\n return this.clients.get(id);\n }\n\n /**\n * Check if a client is connected\n */\n async checkConnection(id: ClientId): Promise<boolean> {\n const client = this.clients.get(id);\n if (!client) return false;\n\n try {\n await client.getSessionId.query();\n return true;\n } catch (e) {\n console.warn(`${id} client connection lost:`, e);\n return false;\n }\n }\n\n /**\n * Start monitoring all client connections\n */\n startMonitoring(\n onConnectionChange: (params: { id: ClientId; isConnected: boolean; wasConnected: boolean }) => Promise<void>,\n ): void {\n if (this.checkInterval) {\n window.clearInterval(this.checkInterval);\n }\n\n this.checkInterval = window.setInterval(() => {\n (async () => {\n for (const [id, _] of this.clients) {\n if (id != 'link' && id != 'host') throw new Error(`Invalid client ID: ${id}`);\n\n const wasConnected = this.connectionStates.get(id) || false;\n const isConnected = await this.checkConnection(id);\n\n if (wasConnected !== isConnected) {\n await onConnectionChange({ id, isConnected, wasConnected });\n }\n\n this.connectionStates.set(id, isConnected);\n }\n })().catch((error) => {\n console.error('Error in connection monitoring:', error);\n });\n }, this.checkIntervalMs);\n }\n\n /**\n * Stop monitoring connections\n */\n stopMonitoring(): void {\n if (this.checkInterval) {\n window.clearInterval(this.checkInterval);\n this.checkInterval = null;\n }\n }\n\n /**\n * Close all clients\n */\n async closeAll(): Promise<void> {\n for (const [id, client] of this.clients) {\n try {\n await client.close();\n console.log(`Closed ${id} client`);\n } catch (err) {\n console.error(`Error closing ${id} client:`, err);\n }\n }\n this.clients.clear();\n this.connectionStates.clear();\n }\n}\n"]}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Link Proxy application that handles communication between host and link sessions
3
+ */
4
+ export declare class LinkProxyApp {
5
+ private ui;
6
+ private connectionManager;
7
+ private linkedPathData;
8
+ constructor();
9
+ /**
10
+ * Handle a connection state change
11
+ */
12
+ private handleConnectionChange;
13
+ /**
14
+ * Handle host disconnection
15
+ */
16
+ private handleHostDisconnection;
17
+ /**
18
+ * Handle link disconnection
19
+ */
20
+ private handleLinkDisconnection;
21
+ /**
22
+ * Set up event handlers and subscriptions
23
+ */
24
+ private setupLinkUpdateHandler;
25
+ /**
26
+ * Handle link path setup and changes
27
+ */
28
+ private setupLinkPathHandler;
29
+ /**
30
+ * Set up configuration
31
+ */
32
+ private setupConfig;
33
+ /**
34
+ * Clean up resources
35
+ */
36
+ private cleanup;
37
+ /**
38
+ * Initialize the application
39
+ */
40
+ initialize(): Promise<void>;
41
+ }
42
+ //# sourceMappingURL=LinkProxyApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkProxyApp.d.ts","sourceRoot":"","sources":["../src/LinkProxyApp.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,EAAE,CAAY;IACtB,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,cAAc,CAA8B;;IAOpD;;OAEG;IACH,OAAO,CAAC,sBAAsB,CAc5B;IAEF;;OAEG;YACW,uBAAuB;IA+CrC;;OAEG;YACW,uBAAuB;IAqCrC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAyB9B;;OAEG;YACW,oBAAoB;IAwClC;;OAEG;YACW,WAAW;IAgCzB;;OAEG;YACW,OAAO;IAKrB;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAsFzC"}
@@ -0,0 +1,298 @@
1
+ import { createCloudpackClient, linkUpdateSource, linkConfigSource, linkPathsSource, linkDoneSource, linkDisconnectedSource, } from '@ms-cloudpack/api-server/browser';
2
+ import { UIManager } from './UIManager.js';
3
+ import { ConnectionManager } from './ConnectionManager.js';
4
+ import { isApiServerActive } from './isApiServerActive.js';
5
+ /**
6
+ * Link Proxy application that handles communication between host and link sessions
7
+ */
8
+ export class LinkProxyApp {
9
+ ui;
10
+ connectionManager;
11
+ linkedPathData = null;
12
+ constructor() {
13
+ this.ui = new UIManager();
14
+ this.connectionManager = new ConnectionManager();
15
+ }
16
+ /**
17
+ * Handle a connection state change
18
+ */
19
+ handleConnectionChange = async (params) => {
20
+ const { id, isConnected, wasConnected } = params;
21
+ // Only handle disconnections
22
+ if (wasConnected && !isConnected) {
23
+ if (id === 'host') {
24
+ await this.handleHostDisconnection();
25
+ }
26
+ else if (id === 'link') {
27
+ await this.handleLinkDisconnection();
28
+ }
29
+ }
30
+ };
31
+ /**
32
+ * Handle host disconnection
33
+ */
34
+ async handleHostDisconnection(options) {
35
+ const isUnreachable = options?.unreachable ?? false;
36
+ const reason = isUnreachable ? 'unreachable' : 'lost';
37
+ // This is shown momentarily before the cleanup.
38
+ this.ui.updateStatus({
39
+ message: `Connection to host ${reason}. The session will be terminated.`,
40
+ isError: true,
41
+ });
42
+ const linkClient = this.connectionManager.getClient('link');
43
+ let isLinkClosed = false;
44
+ if (linkClient) {
45
+ try {
46
+ await linkClient.publishData.mutate({
47
+ ...linkDisconnectedSource,
48
+ data: { reason },
49
+ });
50
+ isLinkClosed = true;
51
+ }
52
+ catch (err) {
53
+ // This is also shown momentarily before the cleanup.
54
+ this.ui.updateStatus({ message: `Error notifying link client of host connection ${reason}.`, isError: true });
55
+ }
56
+ }
57
+ await this.cleanup();
58
+ // Generate the appropriate tip based on the situation
59
+ let tip;
60
+ if (isUnreachable) {
61
+ tip =
62
+ 'Make sure you have a <code>cloudpack start</code> session running and use the URL from your app to run link with the following command: <code>cloudpack link --remote [URL]</code>';
63
+ }
64
+ else {
65
+ tip = 'If you did not close the start session terminal, this is a bug. Please report it.';
66
+ // Append additional information about link client notification if needed
67
+ if (!isLinkClosed) {
68
+ tip +=
69
+ ' Link client was not successfully notified of host disconnection. You may need to terminate the link session in the terminal.';
70
+ }
71
+ }
72
+ // This is the message the user will see after the cleanup.
73
+ this.ui.updateStatus({
74
+ message: `Connection to host ${reason}. You can close this page.`,
75
+ tip,
76
+ isError: true,
77
+ });
78
+ }
79
+ /**
80
+ * Handle link disconnection
81
+ */
82
+ async handleLinkDisconnection() {
83
+ // This is shown momentarily before the cleanup, more information on following messages.
84
+ this.ui.updateStatus({
85
+ message: 'Connection to link client lost. Cleaning up linked paths...',
86
+ isError: true,
87
+ });
88
+ const hostClient = this.connectionManager.getClient('host');
89
+ if (hostClient && this.linkedPathData) {
90
+ const { linkedPath } = this.linkedPathData;
91
+ const unlinkedPath = linkedPath.path;
92
+ try {
93
+ await hostClient.unlinkPath.mutate({ linkedPath: { path: unlinkedPath } });
94
+ this.ui.updateStatus({
95
+ message: 'Connection to link client lost. Successfully unlinked paths on host. You can close this page.',
96
+ tip: 'If you did not close the link client terminal. This is a bug. Please report it.',
97
+ });
98
+ }
99
+ catch (err) {
100
+ this.ui.updateStatus({
101
+ message: 'Connection to link client lost. Failed to unlink paths on host.',
102
+ // TODO: Add unlinking logic for this case
103
+ tip: 'You may need to restart the host application to unlink the paths.',
104
+ isError: true,
105
+ data: err,
106
+ });
107
+ }
108
+ }
109
+ else {
110
+ this.ui.updateStatus({
111
+ message: 'Cannot clean up: host client or link data not available',
112
+ tip: 'You may need to restart the host application to unlink the paths.',
113
+ isError: true,
114
+ });
115
+ }
116
+ await this.cleanup();
117
+ }
118
+ /**
119
+ * Set up event handlers and subscriptions
120
+ */
121
+ setupLinkUpdateHandler() {
122
+ const linkClient = this.connectionManager.getClient('link');
123
+ const hostClient = this.connectionManager.getClient('host');
124
+ if (!linkClient || !hostClient)
125
+ return;
126
+ // Setup link update handler
127
+ linkClient.onDataChanged.subscribe(linkUpdateSource, {
128
+ onData: (updateData) => {
129
+ this.ui.updateStatus({ message: 'Forwarding package update to the host...', data: updateData });
130
+ hostClient.notifyLinkChange
131
+ .mutate(updateData)
132
+ .then(() => this.ui.updateStatus({ message: 'Cloudpack Link Proxy listening for updates...' }))
133
+ .catch((err) => {
134
+ this.ui.updateStatus({
135
+ message: 'Error forwarding package update to the host. This is a bug. Please report it.',
136
+ isError: true,
137
+ data: err,
138
+ });
139
+ });
140
+ },
141
+ });
142
+ }
143
+ /**
144
+ * Handle link path setup and changes
145
+ */
146
+ async setupLinkPathHandler() {
147
+ const hostClient = this.connectionManager.getClient('host');
148
+ const linkClient = this.connectionManager.getClient('link');
149
+ if (!linkClient || !hostClient)
150
+ return;
151
+ // Check if the link server has already set up the paths
152
+ if (await linkClient.getData.query(linkPathsSource))
153
+ return;
154
+ linkClient.onDataChanged.subscribe(linkPathsSource, {
155
+ onData: (setupData) => {
156
+ this.ui.updateStatus({ message: 'Processing link setup...', data: setupData });
157
+ // Store the linked path data for potential cleanup
158
+ this.linkedPathData = setupData;
159
+ void hostClient.linkPath.mutate(this.linkedPathData).then((result) => {
160
+ const { resolveMap, linkedPaths } = result;
161
+ this.ui.updateStatus({ message: 'Sending link setup result back to the link server...', data: result });
162
+ void linkClient.publishData
163
+ .mutate({
164
+ ...linkDoneSource,
165
+ data: { resolveMap, linkedPaths },
166
+ })
167
+ .then(() => {
168
+ this.ui.updateStatus({ message: 'Cloudpack Link Proxy listening for updates...' });
169
+ })
170
+ .catch((err) => {
171
+ this.ui.updateStatus({
172
+ message: 'Error sending link setup result back to the link server. Please try to run link again.',
173
+ tip: 'This is a bug. Please report it.',
174
+ isError: true,
175
+ data: err,
176
+ });
177
+ });
178
+ });
179
+ },
180
+ });
181
+ }
182
+ /**
183
+ * Set up configuration
184
+ */
185
+ async setupConfig() {
186
+ const linkClient = this.connectionManager.getClient('link');
187
+ const hostClient = this.connectionManager.getClient('host');
188
+ if (!linkClient || !hostClient)
189
+ return;
190
+ try {
191
+ const config = (await linkClient.getData.query(linkConfigSource));
192
+ if (!config) {
193
+ this.ui.updateStatus({ message: 'Fetching host configuration...' });
194
+ const hostConfig = await hostClient.getLinkConfig.query();
195
+ this.ui.updateStatus({ message: 'Sending host configuration to the link server...', data: hostConfig });
196
+ await linkClient.publishData.mutate({
197
+ ...linkConfigSource,
198
+ data: hostConfig,
199
+ });
200
+ this.ui.updateStatus({ message: 'Host configuration sent to the link server.' });
201
+ }
202
+ }
203
+ catch (err) {
204
+ this.ui.updateStatus({
205
+ message: 'Error setting up configuration. Please try to run link again.',
206
+ tip: 'This is a bug. Please report it.',
207
+ isError: true,
208
+ data: err,
209
+ });
210
+ }
211
+ }
212
+ /**
213
+ * Clean up resources
214
+ */
215
+ async cleanup() {
216
+ this.connectionManager.stopMonitoring();
217
+ await this.connectionManager.closeAll();
218
+ }
219
+ /**
220
+ * Initialize the application
221
+ */
222
+ async initialize() {
223
+ this.ui.updateStatus({ message: 'Initializing Cloudpack Link Proxy...' });
224
+ try {
225
+ // Validate Cloudpack context
226
+ if (!window.__cloudpack) {
227
+ this.ui.updateStatus({
228
+ message: 'Cloudpack context not found on window.',
229
+ tip: 'This is a bug. Please report it.',
230
+ isError: true,
231
+ });
232
+ throw new Error('Cloudpack not found on window.');
233
+ }
234
+ const { pageSessionContext } = window.__cloudpack;
235
+ if (!pageSessionContext) {
236
+ this.ui.updateStatus({
237
+ message: 'Session context not found on window.__cloudpack.',
238
+ tip: 'This is a bug. Please report it.',
239
+ isError: true,
240
+ data: window.__cloudpack,
241
+ });
242
+ throw new Error('Session context not found on window.__cloudpack');
243
+ }
244
+ const { apiUrl, hostApiServerUrls } = pageSessionContext;
245
+ if (!hostApiServerUrls || hostApiServerUrls.length <= 0) {
246
+ this.ui.updateStatus({
247
+ message: 'No host URL provided.',
248
+ tip: 'This is a bug. Please report it.',
249
+ data: pageSessionContext,
250
+ isError: true,
251
+ });
252
+ return;
253
+ }
254
+ // Initialize link client
255
+ const linkClient = await createCloudpackClient({ url: apiUrl });
256
+ this.connectionManager.addClient('link', linkClient);
257
+ // Find an active host API server
258
+ let hostUrl;
259
+ for (const url of hostApiServerUrls) {
260
+ this.ui.updateStatus({ message: `Checking host API server at ${url}...` });
261
+ const isActive = await isApiServerActive(url);
262
+ if (isActive) {
263
+ this.ui.updateStatus({ message: `Host API server is active at ${url}.` });
264
+ hostUrl = url;
265
+ break;
266
+ }
267
+ }
268
+ if (!hostUrl) {
269
+ await this.handleHostDisconnection({ unreachable: true });
270
+ return;
271
+ }
272
+ // Initialize host client
273
+ const hostClient = await createCloudpackClient({ url: hostUrl });
274
+ this.connectionManager.addClient('host', hostClient);
275
+ // Display session information
276
+ const linkSessionId = await linkClient.getSessionId.query();
277
+ const hostSessionId = await hostClient.getSessionId.query();
278
+ this.ui.updateStatus({ message: `Link Session: ${linkSessionId}, Host Session: ${hostSessionId}` });
279
+ // Set up connection monitoring
280
+ this.connectionManager.startMonitoring(this.handleConnectionChange);
281
+ // Set up event handlers and configuration
282
+ this.setupLinkUpdateHandler();
283
+ await this.setupLinkPathHandler();
284
+ await this.setupConfig();
285
+ }
286
+ catch (err) {
287
+ const errorMessage = err instanceof Error ? err.message : String(err);
288
+ this.ui.updateStatus({
289
+ message: errorMessage,
290
+ isError: true,
291
+ tip: 'This is a bug. Please report it.',
292
+ data: err,
293
+ });
294
+ await this.cleanup();
295
+ }
296
+ }
297
+ }
298
+ //# sourceMappingURL=LinkProxyApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkProxyApp.js","sourceRoot":"","sources":["../src/LinkProxyApp.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,EAAE,CAAY;IACd,iBAAiB,CAAoB;IACrC,cAAc,GAAyB,IAAI,CAAC;IAEpD;QACE,IAAI,CAAC,EAAE,GAAG,IAAI,SAAS,EAAE,CAAC;QAC1B,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACnD,CAAC;IAED;;OAEG;IACK,sBAAsB,GAAG,KAAK,EAAE,MAIvC,EAAiB,EAAE;QAClB,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QACjD,6BAA6B;QAC7B,IAAI,YAAY,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;gBAClB,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;YACvC,CAAC;iBAAM,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;gBACzB,MAAM,IAAI,CAAC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I,CAAC,oBAAoB,EAAE,CAAC;YAClC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,YAAY,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACtE,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC;gBACnB,OAAO,EAAE,YAAY;gBACrB,OAAO,EAAE,IAAI;gBACb,GAAG,EAAE,kCAAkC;gBACvC,IAAI,EAAE,GAAG;aACV,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { NotifyLinkChangeInput, LinkPathInput, GetLinkConfigOutput } from '@ms-cloudpack/api-server/browser';\nimport {\n createCloudpackClient,\n linkUpdateSource,\n linkConfigSource,\n linkPathsSource,\n linkDoneSource,\n linkDisconnectedSource,\n} from '@ms-cloudpack/api-server/browser';\nimport { UIManager } from './UIManager.js';\nimport { ConnectionManager } from './ConnectionManager.js';\nimport { isApiServerActive } from './isApiServerActive.js';\n\n/**\n * Link Proxy application that handles communication between host and link sessions\n */\nexport class LinkProxyApp {\n private ui: UIManager;\n private connectionManager: ConnectionManager;\n private linkedPathData: LinkPathInput | null = null;\n\n constructor() {\n this.ui = new UIManager();\n this.connectionManager = new ConnectionManager();\n }\n\n /**\n * Handle a connection state change\n */\n private handleConnectionChange = async (params: {\n id: string;\n isConnected: boolean;\n wasConnected: boolean;\n }): Promise<void> => {\n const { id, isConnected, wasConnected } = params;\n // Only handle disconnections\n if (wasConnected && !isConnected) {\n if (id === 'host') {\n await this.handleHostDisconnection();\n } else if (id === 'link') {\n await this.handleLinkDisconnection();\n }\n }\n };\n\n /**\n * Handle host disconnection\n */\n private async handleHostDisconnection(options?: { unreachable?: boolean }): Promise<void> {\n const isUnreachable = options?.unreachable ?? false;\n const reason = isUnreachable ? 'unreachable' : 'lost';\n // This is shown momentarily before the cleanup.\n this.ui.updateStatus({\n message: `Connection to host ${reason}. The session will be terminated.`,\n isError: true,\n });\n\n const linkClient = this.connectionManager.getClient('link');\n let isLinkClosed = false;\n if (linkClient) {\n try {\n await linkClient.publishData.mutate({\n ...linkDisconnectedSource,\n data: { reason },\n });\n isLinkClosed = true;\n } catch (err) {\n // This is also shown momentarily before the cleanup.\n this.ui.updateStatus({ message: `Error notifying link client of host connection ${reason}.`, isError: true });\n }\n }\n\n await this.cleanup();\n\n // Generate the appropriate tip based on the situation\n let tip: string;\n if (isUnreachable) {\n tip =\n 'Make sure you have a <code>cloudpack start</code> session running and use the URL from your app to run link with the following command: <code>cloudpack link --remote [URL]</code>';\n } else {\n tip = 'If you did not close the start session terminal, this is a bug. Please report it.';\n // Append additional information about link client notification if needed\n if (!isLinkClosed) {\n tip +=\n ' Link client was not successfully notified of host disconnection. You may need to terminate the link session in the terminal.';\n }\n }\n // This is the message the user will see after the cleanup.\n this.ui.updateStatus({\n message: `Connection to host ${reason}. You can close this page.`,\n tip,\n isError: true,\n });\n }\n\n /**\n * Handle link disconnection\n */\n private async handleLinkDisconnection(): Promise<void> {\n // This is shown momentarily before the cleanup, more information on following messages.\n this.ui.updateStatus({\n message: 'Connection to link client lost. Cleaning up linked paths...',\n isError: true,\n });\n\n const hostClient = this.connectionManager.getClient('host');\n if (hostClient && this.linkedPathData) {\n const { linkedPath } = this.linkedPathData;\n const unlinkedPath = linkedPath.path;\n try {\n await hostClient.unlinkPath.mutate({ linkedPath: { path: unlinkedPath } });\n this.ui.updateStatus({\n message: 'Connection to link client lost. Successfully unlinked paths on host. You can close this page.',\n tip: 'If you did not close the link client terminal. This is a bug. Please report it.',\n });\n } catch (err) {\n this.ui.updateStatus({\n message: 'Connection to link client lost. Failed to unlink paths on host.',\n // TODO: Add unlinking logic for this case\n tip: 'You may need to restart the host application to unlink the paths.',\n isError: true,\n data: err,\n });\n }\n } else {\n this.ui.updateStatus({\n message: 'Cannot clean up: host client or link data not available',\n tip: 'You may need to restart the host application to unlink the paths.',\n isError: true,\n });\n }\n\n await this.cleanup();\n }\n\n /**\n * Set up event handlers and subscriptions\n */\n private setupLinkUpdateHandler(): void {\n const linkClient = this.connectionManager.getClient('link');\n const hostClient = this.connectionManager.getClient('host');\n\n if (!linkClient || !hostClient) return;\n\n // Setup link update handler\n linkClient.onDataChanged.subscribe(linkUpdateSource, {\n onData: (updateData) => {\n this.ui.updateStatus({ message: 'Forwarding package update to the host...', data: updateData });\n\n hostClient.notifyLinkChange\n .mutate(updateData as NotifyLinkChangeInput)\n .then(() => this.ui.updateStatus({ message: 'Cloudpack Link Proxy listening for updates...' }))\n .catch((err) => {\n this.ui.updateStatus({\n message: 'Error forwarding package update to the host. This is a bug. Please report it.',\n isError: true,\n data: err,\n });\n });\n },\n });\n }\n\n /**\n * Handle link path setup and changes\n */\n private async setupLinkPathHandler(): Promise<void> {\n const hostClient = this.connectionManager.getClient('host');\n const linkClient = this.connectionManager.getClient('link');\n if (!linkClient || !hostClient) return;\n\n // Check if the link server has already set up the paths\n if (await linkClient.getData.query(linkPathsSource)) return;\n\n linkClient.onDataChanged.subscribe(linkPathsSource, {\n onData: (setupData) => {\n this.ui.updateStatus({ message: 'Processing link setup...', data: setupData });\n\n // Store the linked path data for potential cleanup\n this.linkedPathData = setupData as LinkPathInput;\n\n void hostClient.linkPath.mutate(this.linkedPathData).then((result) => {\n const { resolveMap, linkedPaths } = result;\n this.ui.updateStatus({ message: 'Sending link setup result back to the link server...', data: result });\n\n void linkClient.publishData\n .mutate({\n ...linkDoneSource,\n data: { resolveMap, linkedPaths },\n })\n .then(() => {\n this.ui.updateStatus({ message: 'Cloudpack Link Proxy listening for updates...' });\n })\n .catch((err) => {\n this.ui.updateStatus({\n message: 'Error sending link setup result back to the link server. Please try to run link again.',\n tip: 'This is a bug. Please report it.',\n isError: true,\n data: err,\n });\n });\n });\n },\n });\n }\n\n /**\n * Set up configuration\n */\n private async setupConfig(): Promise<void> {\n const linkClient = this.connectionManager.getClient('link');\n const hostClient = this.connectionManager.getClient('host');\n\n if (!linkClient || !hostClient) return;\n\n try {\n const config = (await linkClient.getData.query(linkConfigSource)) as GetLinkConfigOutput | undefined;\n\n if (!config) {\n this.ui.updateStatus({ message: 'Fetching host configuration...' });\n\n const hostConfig = await hostClient.getLinkConfig.query();\n this.ui.updateStatus({ message: 'Sending host configuration to the link server...', data: hostConfig });\n\n await linkClient.publishData.mutate({\n ...linkConfigSource,\n data: hostConfig,\n });\n\n this.ui.updateStatus({ message: 'Host configuration sent to the link server.' });\n }\n } catch (err) {\n this.ui.updateStatus({\n message: 'Error setting up configuration. Please try to run link again.',\n tip: 'This is a bug. Please report it.',\n isError: true,\n data: err,\n });\n }\n }\n\n /**\n * Clean up resources\n */\n private async cleanup(): Promise<void> {\n this.connectionManager.stopMonitoring();\n await this.connectionManager.closeAll();\n }\n\n /**\n * Initialize the application\n */\n public async initialize(): Promise<void> {\n this.ui.updateStatus({ message: 'Initializing Cloudpack Link Proxy...' });\n\n try {\n // Validate Cloudpack context\n if (!window.__cloudpack) {\n this.ui.updateStatus({\n message: 'Cloudpack context not found on window.',\n tip: 'This is a bug. Please report it.',\n isError: true,\n });\n throw new Error('Cloudpack not found on window.');\n }\n\n const { pageSessionContext } = window.__cloudpack;\n\n if (!pageSessionContext) {\n this.ui.updateStatus({\n message: 'Session context not found on window.__cloudpack.',\n tip: 'This is a bug. Please report it.',\n isError: true,\n data: window.__cloudpack,\n });\n throw new Error('Session context not found on window.__cloudpack');\n }\n\n const { apiUrl, hostApiServerUrls } = pageSessionContext;\n\n if (!hostApiServerUrls || hostApiServerUrls.length <= 0) {\n this.ui.updateStatus({\n message: 'No host URL provided.',\n tip: 'This is a bug. Please report it.',\n data: pageSessionContext,\n isError: true,\n });\n return;\n }\n\n // Initialize link client\n const linkClient = await createCloudpackClient({ url: apiUrl });\n this.connectionManager.addClient('link', linkClient);\n\n // Find an active host API server\n let hostUrl: string | undefined;\n for (const url of hostApiServerUrls) {\n this.ui.updateStatus({ message: `Checking host API server at ${url}...` });\n const isActive = await isApiServerActive(url);\n if (isActive) {\n this.ui.updateStatus({ message: `Host API server is active at ${url}.` });\n hostUrl = url;\n break;\n }\n }\n\n if (!hostUrl) {\n await this.handleHostDisconnection({ unreachable: true });\n return;\n }\n\n // Initialize host client\n const hostClient = await createCloudpackClient({ url: hostUrl });\n this.connectionManager.addClient('host', hostClient);\n\n // Display session information\n const linkSessionId = await linkClient.getSessionId.query();\n const hostSessionId = await hostClient.getSessionId.query();\n this.ui.updateStatus({ message: `Link Session: ${linkSessionId}, Host Session: ${hostSessionId}` });\n\n // Set up connection monitoring\n this.connectionManager.startMonitoring(this.handleConnectionChange);\n\n // Set up event handlers and configuration\n this.setupLinkUpdateHandler();\n await this.setupLinkPathHandler();\n await this.setupConfig();\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n this.ui.updateStatus({\n message: errorMessage,\n isError: true,\n tip: 'This is a bug. Please report it.',\n data: err,\n });\n await this.cleanup();\n }\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * UI Manager for handling status display
3
+ */
4
+ export declare class UIManager {
5
+ private element;
6
+ constructor(elementId?: string);
7
+ /**
8
+ * Display a status message to the user
9
+ */
10
+ updateStatus(input: {
11
+ message: string;
12
+ tip?: string;
13
+ isError?: boolean;
14
+ data?: unknown;
15
+ }): void;
16
+ }
17
+ //# sourceMappingURL=UIManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UIManager.d.ts","sourceRoot":"","sources":["../src/UIManager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAqB;gBAExB,SAAS,GAAE,MAAe;IAItC;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAoBhG"}
@@ -0,0 +1,33 @@
1
+ import styles from './UIManager.module.css';
2
+ /**
3
+ * UI Manager for handling status display
4
+ */
5
+ export class UIManager {
6
+ element;
7
+ constructor(elementId = 'root') {
8
+ this.element = document.getElementById(elementId);
9
+ }
10
+ /**
11
+ * Display a status message to the user
12
+ */
13
+ updateStatus(input) {
14
+ const { message, tip, isError = false, data } = input;
15
+ if (isError) {
16
+ data ? console.error(message, data) : console.error(message);
17
+ }
18
+ else {
19
+ data ? console.debug(message, data) : console.debug(message);
20
+ }
21
+ if (!this.element)
22
+ return;
23
+ this.element.innerHTML = `
24
+ <div class="${styles.statusContainer + (isError ? ` ${styles.errorContainer}` : '')}">
25
+ <h2 class="${styles.title}">Cloudpack Link Proxy</h2>
26
+ <p class="${styles.message}">${isError ? 'Error: ' : ''}${message}</p>
27
+ ${tip ? `<p class="${styles.message}"><strong>Tip:</strong> ${tip}</p>` : ''}
28
+ <p class="${styles.warning}">Do not close this page while Cloudpack link is running.</p>
29
+ </div>
30
+ `;
31
+ }
32
+ }
33
+ //# sourceMappingURL=UIManager.js.map