@astrale-os/cli 1.0.0-beta.10 → 1.0.0-beta.11

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,3 +1,5 @@
1
+ import type { AuthApi } from '@astrale-os/sdk/auth'
2
+ import type { IssuerId } from '@astrale-os/sdk/auth'
1
3
  import type { ReadableStream as WebReadableStream } from 'node:stream/web'
2
4
 
3
5
  import { readFile } from 'node:fs/promises'
@@ -23,8 +25,9 @@ export { ensureViewerAssets, viewerDistDir } from './assets'
23
25
  * heartbeat keeps a live session alive.
24
26
  */
25
27
 
26
- const TOKEN_REFRESH_MARGIN_MS = 5 * 60_000
27
- const FALLBACK_TOKEN_TTL_MS = 3600_000
28
+ const VIEW_TOKEN_TTL_SECONDS = 4 * 60
29
+ const TOKEN_REFRESH_MARGIN_MS = 60_000
30
+ const FALLBACK_TOKEN_TTL_MS = VIEW_TOKEN_TTL_SECONDS * 1_000
28
31
  const IDLE_SWEEP_MS = 60_000
29
32
 
30
33
  export type PageStatus = { state: string; error?: string; at: string }
@@ -44,7 +47,7 @@ export function startViewServer(config: ViewServeConfig): Server {
44
47
  async function freshGrant(): Promise<TokenGrant> {
45
48
  if (grant && grant.expiresAt - Date.now() > TOKEN_REFRESH_MARGIN_MS) return grant
46
49
  grant = await withClientSession(config.kernel, async ({ auth, target }) => {
47
- const token = await auth.mint({ audience: target.kernelIssuer, ttlSeconds: 3_600 })
50
+ const token = await mintViewCredential(auth, target.kernelIssuer)
48
51
  return {
49
52
  token,
50
53
  expiresAt: jwtExpiry(token) ?? Date.now() + FALLBACK_TOKEN_TTL_MS,
@@ -182,6 +185,17 @@ export function startViewServer(config: ViewServeConfig): Server {
182
185
  return server
183
186
  }
184
187
 
188
+ /** Mint a short-lived credential from the selected CLI identity proof. */
189
+ export async function mintViewCredential(
190
+ auth: Pick<AuthApi, 'mint'>,
191
+ audience: IssuerId,
192
+ ): Promise<string> {
193
+ return auth.mint({
194
+ audience,
195
+ ttlSeconds: VIEW_TOKEN_TTL_SECONDS,
196
+ })
197
+ }
198
+
185
199
  function jwtExpiry(token: string): number | null {
186
200
  try {
187
201
  const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString('utf8')) as {
@@ -0,0 +1 @@
1
+ import{r as e,t}from"./rolldown-runtime-Dd_uD5pT.js";var n=t(((t,n)=>{(function(e){if(typeof t==`object`&&n!==void 0)n.exports=e();else if(typeof define==`function`&&define.amd)define([],e);else{var r=typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this;r.ELK=e()}})(function(){return(function(){function t(n,r,i){function a(s,c){if(!r[s]){if(!n[s]){var l=typeof e==`function`&&e;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};n[s][0].call(d.exports,function(e){var t=n[s][1][e];return a(t||e)},d,d.exports,t,n,r,i)}return r[s].exports}for(var o=typeof e==`function`&&e,s=0;s<i.length;s++)a(i[s]);return a}return t})()({1:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;function r(e){"@babel/helpers - typeof";return r=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},r(e)}function i(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,s(r.key),r)}}function o(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=c(e,`string`);return r(t)==`symbol`?t:t+``}function c(e,t){if(r(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,t||`default`);if(r(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}n.default=function(){function e(){var t=this,n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=n.defaultLayoutOptions,a=r===void 0?{}:r,o=n.algorithms,s=o===void 0?[`layered`,`stress`,`mrtree`,`radial`,`force`,`disco`,`sporeOverlap`,`sporeCompaction`,`rectpacking`]:o,c=n.workerFactory,u=n.workerUrl;if(i(this,e),this.defaultLayoutOptions=a,this.initialized=!1,u===void 0&&c===void 0)throw Error(`Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.`);var d=c;u!==void 0&&c===void 0&&(d=function(e){return new Worker(e)});var f=d(u);if(typeof f.postMessage!=`function`)throw TypeError(`Created worker does not provide the required 'postMessage' function.`);this.worker=new l(f),this.worker.postMessage({cmd:`register`,algorithms:s}).then(function(e){return t.initialized=!0}).catch(console.err)}return o(e,[{key:`layout`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.layoutOptions,r=n===void 0?this.defaultLayoutOptions:n,i=t.logging,a=i!==void 0&&i,o=t.measureExecutionTime,s=o!==void 0&&o;return e?this.worker.postMessage({cmd:`layout`,graph:e,layoutOptions:r,options:{logging:a,measureExecutionTime:s}}):Promise.reject(Error(`Missing mandatory parameter 'graph'.`))}},{key:`knownLayoutAlgorithms`,value:function(){return this.worker.postMessage({cmd:`algorithms`})}},{key:`knownLayoutOptions`,value:function(){return this.worker.postMessage({cmd:`options`})}},{key:`knownLayoutCategories`,value:function(){return this.worker.postMessage({cmd:`categories`})}},{key:`terminateWorker`,value:function(){this.worker&&this.worker.terminate()}}])}();var l=function(){function e(t){var n=this;if(i(this,e),t===void 0)throw Error(`Missing mandatory parameter 'worker'.`);this.resolvers={},this.worker=t,this.worker.onmessage=function(e){setTimeout(function(){n.receive(n,e)},0)}}return o(e,[{key:`postMessage`,value:function(e){var t=this.id||0;this.id=t+1,e.id=t;var n=this;return new Promise(function(r,i){n.resolvers[t]=function(e,t){e?(n.convertGwtStyleError(e),i(e)):r(t)},n.worker.postMessage(e)})}},{key:`receive`,value:function(e,t){var n=t.data,r=e.resolvers[n.id];r&&(delete e.resolvers[n.id],n.error?r(n.error):r(null,n.data))}},{key:`terminate`,value:function(){this.worker&&this.worker.terminate()}},{key:`convertGwtStyleError`,value:function(e){if(e){var t=e.__java$exception;t&&(t.cause&&t.cause.backingJsObject&&(e.cause=t.cause.backingJsObject,this.convertGwtStyleError(e.cause)),delete e.__java$exception)}}}])}()},{}],2:[function(e,t,n){var r=e("./elk-api.js").default;Object.defineProperty(t.exports,"__esModule",{value:!0}),t.exports=r,r.default=r},{"./elk-api.js":1}]},{},[2])(2)})}));export default n();