@arkstack/common 0.21.1 → 0.22.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.
@@ -29,7 +29,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  enumerable: true
30
30
  }) : target, mod));
31
31
  //#endregion
32
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/ClearRequest.mjs
32
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/ClearRequest.mjs
33
33
  var ClearRequest = class {
34
34
  /**
35
35
  * @param body - Parsed request body
@@ -49,7 +49,7 @@ var ClearRequest = class {
49
49
  }
50
50
  };
51
51
  //#endregion
52
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/Route.mjs
52
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/Route.mjs
53
53
  /**
54
54
  * Parse the placeholder parameters declared in a domain/host pattern such as
55
55
  * `{account}.example.com`. Mirrors the path parameter syntax (supporting the
@@ -323,7 +323,7 @@ var Route = class Route {
323
323
  }
324
324
  };
325
325
  //#endregion
326
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/core/helpers.mjs
326
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/core/helpers.mjs
327
327
  const wrap = (value) => {
328
328
  if (value === null || value === void 0) return [];
329
329
  return Array.isArray(value) ? value : [value];
@@ -348,7 +348,7 @@ const importFile = async (filePath, userOptions, resolveOptions) => {
348
348
  }).import(resolvedPath, resolveOptions);
349
349
  };
350
350
  //#endregion
351
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/RouteGroup.mjs
351
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/RouteGroup.mjs
352
352
  /**
353
353
  * @class clear-router RouteGroup
354
354
  * @description A route group describes a collection of routes on clear-router
@@ -493,7 +493,7 @@ var RouteGroup = class {
493
493
  }
494
494
  };
495
495
  //#endregion
496
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/RouteRegistrar.mjs
496
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/RouteRegistrar.mjs
497
497
  /**
498
498
  * @class clear-router RouteRegistrar
499
499
  * @description Fluent builder returned by `Router.domain()` that lets routes be
@@ -558,7 +558,7 @@ var RouteRegistrar = class {
558
558
  }
559
559
  };
560
560
  //#endregion
561
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/core/Request.mjs
561
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/core/Request.mjs
562
562
  var Request = class extends ClearRequest {
563
563
  original;
564
564
  method = "GET";
@@ -589,7 +589,7 @@ var Request = class extends ClearRequest {
589
589
  }
590
590
  };
591
591
  //#endregion
592
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/core/Response.mjs
592
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/core/Response.mjs
593
593
  var Response = class {
594
594
  body;
595
595
  headers = new Headers();
@@ -645,7 +645,7 @@ var Response = class {
645
645
  }
646
646
  };
647
647
  //#endregion
648
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/core/bindings.mjs
648
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/core/bindings.mjs
649
649
  const metadataKey$1 = Symbol.for("clear-router:binding-metadata");
650
650
  const bindings = /* @__PURE__ */ new WeakMap();
651
651
  var InjectionToken = class {
@@ -894,7 +894,7 @@ function isClass(value) {
894
894
  return typeof value === "function" && /^class\s/.test(Function.prototype.toString.call(value));
895
895
  }
896
896
  //#endregion
897
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/decorators/middleware.mjs
897
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/decorators/middleware.mjs
898
898
  const CLASS_KEY = "__class__";
899
899
  const metadataKey = Symbol.for("clear-router:middleware-metadata");
900
900
  const store = /* @__PURE__ */ new WeakMap();
@@ -926,7 +926,7 @@ function getStandardMetadata(metadata, propertyKey) {
926
926
  return record ? record[propertyKey] : void 0;
927
927
  }
928
928
  //#endregion
929
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/ResourceRouteSelection.mjs
929
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/ResourceRouteSelection.mjs
930
930
  var ResourceRouteSelection = class {
931
931
  constructor(routes) {
932
932
  this.routes = routes;
@@ -949,7 +949,7 @@ var ResourceRouteSelection = class {
949
949
  }
950
950
  };
951
951
  //#endregion
952
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/ResourceRoutes.mjs
952
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/ResourceRoutes.mjs
953
953
  /**
954
954
  * @class clear-router ResourceRoutes
955
955
  * @description A ResourceRoutes creates a collection of resourceful routes in a single call
@@ -1105,7 +1105,7 @@ var ResourceRoutes = class ResourceRoutes {
1105
1105
  }
1106
1106
  };
1107
1107
  //#endregion
1108
- //#region ../../node_modules/.pnpm/clear-router@2.9.3_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._15be2e62531296a83319dbccad2fa4ea/node_modules/clear-router/dist/core/CoreRouter.mjs
1108
+ //#region ../../node_modules/.pnpm/clear-router@2.9.4_@h3ravel+support@2.2.7_@types+node@25.6.2_h3@2.0.1-rc.22__express@5._2bab133bbd66d26d3ddd3ee96a6f2175/node_modules/clear-router/dist/core/CoreRouter.mjs
1109
1109
  /**
1110
1110
  * @class clear-router CoreRouter
1111
1111
  * @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference path="./app.d.ts" />
2
2
  import { $ as HookPos, A as SealedBox, B as ConfigShape, C as Encryption, D as KeyPair, E as KeyInput, F as ArkstackErrorShape, G as EnvRegistry, H as DotPathValue, I as Choice, J as GlobalConfig, K as EnvReturn, L as Choices, M as SerializedKeyPair, N as AppConfig, O as Keys, P as ArkstackErrorPayload, Q as HookName, R as Concrete, S as DerivedKey, T as FingerprintOptions, U as EnvKey, V as DotPath, W as EnvLookup, X as HookArgs, Y as GlobalEnv, Z as HookFor, _ as ChannelOptions, a as abort, at as LoggerLog, b as Codec, c as getModel, ct as PaginationOptions, d as isClass, dt as PublishEntry, et as HookPositions, f as normalizePositiveInteger, ft as PublishFilter, g as Hash, h as setModelResolver, ht as Logger, i as ModelResolver, it as LoggerChalk, j as SecureChannel, k as NodeCipher, l as getModelSync, lt as Primitive, m as resolvePagination, mt as UnionToIntersection, n as ModelConstructor, nt as HookResult, o as abortIf, ot as LoggerParseSignature, p as perPage, pt as PublishGroup, q as FileImporter, r as ModelRegistry, rt as IHook, s as assertFound, st as MergedConfig, t as AbstractModelConstructor, tt as HookRegistry, u as initializeGlobalContext, ut as PublishConfirmation, v as Cipher, w as EncryptionKey, x as DeriveOptions, y as CipherOptions, z as ConfigRegistry } from "./helpers-CiymRnyw.js";
3
- import { Hook } from "@arkstack/foundry";
4
- import { Arkstack } from "@arkstack/contract";
3
+ import { ArkstackPlugin, Hook, Plugins } from "@arkstack/foundry";
4
+ import { Arkstack, ArkstackKitDriver, ServerStartInfo } from "@arkstack/contract";
5
5
  import { ForkOptions } from "node:child_process";
6
6
  import pino from "pino";
7
7
  //#region src/lifecycle.d.ts
@@ -480,4 +480,79 @@ declare const devServer: (options: DevServerRunnerOptions) => {
480
480
  closeWatcher(): Promise<void>;
481
481
  };
482
482
  //#endregion
483
- export { AbstractModelConstructor, AppConfig, AppException, ArkstackErrorPayload, ArkstackErrorShape, CONFIG_KEY, type ChannelOptions, Choice, Choices, Cipher, type CipherOptions, Codec, Concrete, ConfigLoader, ConfigRegistry, ConfigShape, type DeriveOptions, type DerivedKey, DevServerRunnerOptions, DotPath, DotPathValue, Encryption, EncryptionKey, EnvKey, EnvLoader, EnvLookup, EnvRegistry, EnvReturn, ErrorHandler, Exception, FileImporter, type FingerprintOptions, GlobalConfig, GlobalEnv, Hash, Hook, type HookArgs, type HookFor, type HookName, type HookPos, type HookPositions, type HookRegistry, type HookResult, type IHook, type KeyInput, KeyPair, Keys, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, MergedConfig, ModelConstructor, ModelRegistry, ModelResolver, NodeCipher, PaginationOptions, Primitive, PublishConfirmation, PublishEntry, PublishFilter, PublishGroup, Publisher, RequestException, SealedBox, SecureChannel, type SerializedKeyPair, TlsCredentials, UnionToIntersection, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, setModelResolver, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
483
+ //#region src/ServerDriver.d.ts
484
+ /**
485
+ * Where and how a driver should bind its server, read from the environment.
486
+ */
487
+ interface ServerBinding {
488
+ host: string;
489
+ port: number;
490
+ scheme: ServerStartInfo['scheme'];
491
+ secure: boolean;
492
+ }
493
+ /**
494
+ * Base driver for runtimes that listen on a port. It resolves the bind address,
495
+ * opens the dev tunnel, prints the startup lines and runs the `server:start` hook,
496
+ * leaving only the runtime-specific listen call to each driver.
497
+ */
498
+ declare abstract class ServerDriver<TApp, TMiddleware> extends ArkstackKitDriver<TApp, TMiddleware> {
499
+ protected tunnel_url?: string;
500
+ /**
501
+ * If trafic has been proxied via ngrok, this will return the tunnel URL.
502
+ *
503
+ * @returns
504
+ */
505
+ geTunnelUrl(): string | undefined;
506
+ /**
507
+ * Resolves the bind address from `APP_HOST` (or `HOST`) and `APP_SECURE`.
508
+ *
509
+ * The host defaults to `0.0.0.0` so the server is reachable on all network
510
+ * interfaces, which platforms like Railway require for their healthcheck.
511
+ *
512
+ * @param port
513
+ * @returns
514
+ */
515
+ protected binding(port: number): ServerBinding;
516
+ /**
517
+ * Announces a server that is now listening: opens or records the tunnel,
518
+ * prints the startup lines and runs the `server:start` hook.
519
+ *
520
+ * @param binding
521
+ */
522
+ protected announce(binding: ServerBinding): Promise<void>;
523
+ /**
524
+ * Uses a preset `TUNNEL_URL`, or opens an ngrok tunnel when `TUNNEL` is set.
525
+ *
526
+ * @param port
527
+ * @returns The public tunnel URL, if any.
528
+ */
529
+ protected openTunnel(port: number): Promise<string | undefined>;
530
+ /**
531
+ * Opens an ngrok tunnel to the given port.
532
+ *
533
+ * @param port
534
+ * @returns The public tunnel URL, if ngrok returned one.
535
+ */
536
+ protected forward(port: number): Promise<string | undefined>;
537
+ /**
538
+ * Builds the "Server is running" lines, adding a local-network URL when the
539
+ * server is bound to all interfaces so other devices can reach it.
540
+ *
541
+ * @param binding
542
+ * @returns
543
+ */
544
+ protected startupLines({ host, port, scheme }: ServerBinding): string[];
545
+ /**
546
+ * Runs the `server:start` hook: `after` always, then `tunneled` when a tunnel
547
+ * is open. A failing listener is logged, never thrown, so it cannot take down
548
+ * a running server or skip the next position.
549
+ *
550
+ * @param info
551
+ */
552
+ protected emitServerStart(info: ServerStartInfo): Promise<void>;
553
+ private emitPosition;
554
+ private bindsAll;
555
+ private localHost;
556
+ }
557
+ //#endregion
558
+ export { AbstractModelConstructor, AppConfig, AppException, ArkstackErrorPayload, ArkstackErrorShape, ArkstackPlugin, CONFIG_KEY, type ChannelOptions, Choice, Choices, Cipher, type CipherOptions, Codec, Concrete, ConfigLoader, ConfigRegistry, ConfigShape, type DeriveOptions, type DerivedKey, DevServerRunnerOptions, DotPath, DotPathValue, Encryption, EncryptionKey, EnvKey, EnvLoader, EnvLookup, EnvRegistry, EnvReturn, ErrorHandler, Exception, FileImporter, type FingerprintOptions, GlobalConfig, GlobalEnv, Hash, Hook, type HookArgs, type HookFor, type HookName, type HookPos, type HookPositions, type HookRegistry, type HookResult, type IHook, type KeyInput, KeyPair, Keys, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, MergedConfig, ModelConstructor, ModelRegistry, ModelResolver, NodeCipher, PaginationOptions, Plugins, Primitive, PublishConfirmation, PublishEntry, PublishFilter, PublishGroup, Publisher, RequestException, SealedBox, SecureChannel, type SerializedKeyPair, ServerBinding, ServerDriver, TlsCredentials, UnionToIntersection, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, setModelResolver, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { _ as EnvLoader, a as env, c as nodeEnv, d as resolveRuntimeDir, f as resolveRuntimeModule, g as configLoader, h as ConfigLoader, i as discoverCommands, l as outputDir, m as CONFIG_KEY, n as appUrl, o as importFile, p as toOutputPath, r as config, s as interopDefault, t as appKey, u as rebuildOutput, v as envLoader } from "./system-DzAzwH__.js";
2
- import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, b as Exception, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, k as SealedBox, l as assertFound, m as normalizePositiveInteger, p as isClass, s as abort, u as getModel, v as RequestException, w as Encryption, x as Hash, y as AppException } from "./utils-B3uw4pWD.js";
3
- import { Hook, Hook as Hook$1 } from "@arkstack/foundry";
4
- import { Arkstack } from "@arkstack/contract";
2
+ import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, b as Exception, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, k as SealedBox, l as assertFound, m as normalizePositiveInteger, p as isClass, s as abort, u as getModel, v as RequestException, w as Encryption, x as Hash, y as AppException } from "./utils-DDV77Y54.js";
3
+ import { ArkstackPlugin, Hook, Hook as Hook$1, Plugins } from "@arkstack/foundry";
4
+ import { Arkstack, ArkstackKitDriver } from "@arkstack/contract";
5
5
  import { str } from "@h3ravel/support";
6
6
  import path from "node:path";
7
7
  import { access, stat } from "node:fs/promises";
@@ -10,6 +10,7 @@ import { detect } from "detect-port";
10
10
  import pino from "pino";
11
11
  import chalk from "chalk";
12
12
  import { networkInterfaces } from "node:os";
13
+ import ngrok from "@ngrok/ngrok";
13
14
  //#region src/lifecycle.ts
14
15
  const bindGracefulShutdown = (shutdown, defer) => {
15
16
  if (defer) return;
@@ -616,4 +617,134 @@ const devServer = (options) => {
616
617
  };
617
618
  };
618
619
  //#endregion
619
- export { AppException, CONFIG_KEY, Cipher, Codec, ConfigLoader, Encryption, EncryptionKey, EnvLoader, ErrorHandler, Exception, Hash, Hook, KeyPair, Keys, Logger, NodeCipher, Publisher, RequestException, SealedBox, SecureChannel, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, setModelResolver, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
620
+ //#region src/ServerDriver.ts
621
+ /**
622
+ * Base driver for runtimes that listen on a port. It resolves the bind address,
623
+ * opens the dev tunnel, prints the startup lines and runs the `server:start` hook,
624
+ * leaving only the runtime-specific listen call to each driver.
625
+ */
626
+ var ServerDriver = class extends ArkstackKitDriver {
627
+ tunnel_url;
628
+ /**
629
+ * If trafic has been proxied via ngrok, this will return the tunnel URL.
630
+ *
631
+ * @returns
632
+ */
633
+ geTunnelUrl() {
634
+ return this.tunnel_url;
635
+ }
636
+ /**
637
+ * Resolves the bind address from `APP_HOST` (or `HOST`) and `APP_SECURE`.
638
+ *
639
+ * The host defaults to `0.0.0.0` so the server is reachable on all network
640
+ * interfaces, which platforms like Railway require for their healthcheck.
641
+ *
642
+ * @param port
643
+ * @returns
644
+ */
645
+ binding(port) {
646
+ const secure = env("APP_SECURE", false) === true;
647
+ return {
648
+ host: env("APP_HOST", env("HOST", "0.0.0.0")),
649
+ port,
650
+ scheme: secure ? "https" : "http",
651
+ secure
652
+ };
653
+ }
654
+ /**
655
+ * Announces a server that is now listening: opens or records the tunnel,
656
+ * prints the startup lines and runs the `server:start` hook.
657
+ *
658
+ * @param binding
659
+ */
660
+ async announce(binding) {
661
+ const { host, port, scheme, secure } = binding;
662
+ const lines = this.startupLines(binding);
663
+ const tunnelUrl = await this.openTunnel(port);
664
+ if (tunnelUrl) lines.push(Logger.log([["Traffic has been tunnelled to", "white"], [tunnelUrl, "green"]], " ", false));
665
+ console.log(lines.join("\n"));
666
+ await this.emitServerStart({
667
+ host,
668
+ port,
669
+ scheme,
670
+ secure,
671
+ url: `${scheme}://${this.localHost(host)}:${port}`,
672
+ tunnelUrl
673
+ });
674
+ }
675
+ /**
676
+ * Uses a preset `TUNNEL_URL`, or opens an ngrok tunnel when `TUNNEL` is set.
677
+ *
678
+ * @param port
679
+ * @returns The public tunnel URL, if any.
680
+ */
681
+ async openTunnel(port) {
682
+ let url = env("TUNNEL_URL") || void 0;
683
+ if (!url && env("TUNNEL", false) === true) {
684
+ url = await this.forward(port);
685
+ if (url) process.env.TUNNEL_URL = url;
686
+ }
687
+ if (url) {
688
+ const tunnelUrl = url;
689
+ this.tunnel_url = tunnelUrl;
690
+ globalThis.tunnelUrl = () => tunnelUrl;
691
+ }
692
+ return url;
693
+ }
694
+ /**
695
+ * Opens an ngrok tunnel to the given port.
696
+ *
697
+ * @param port
698
+ * @returns The public tunnel URL, if ngrok returned one.
699
+ */
700
+ async forward(port) {
701
+ return (await ngrok.forward({
702
+ addr: port,
703
+ authtoken: env("NGROK_AUTHTOKEN"),
704
+ domain: env("NGROK_DOMAIN")
705
+ })).url() || void 0;
706
+ }
707
+ /**
708
+ * Builds the "Server is running" lines, adding a local-network URL when the
709
+ * server is bound to all interfaces so other devices can reach it.
710
+ *
711
+ * @param binding
712
+ * @returns
713
+ */
714
+ startupLines({ host, port, scheme }) {
715
+ const lines = [Logger.log([["Server is running on", "white"], [`${scheme}://${this.localHost(host)}:${port}`, "cyan"]], " ", false)];
716
+ const address = this.bindsAll(host) ? localNetworkAddress() : void 0;
717
+ if (address) lines.push(Logger.log([["Network access via", "white"], [`${scheme}://${address}:${port}`, "cyan"]], " ", false));
718
+ return lines;
719
+ }
720
+ /**
721
+ * Runs the `server:start` hook: `after` always, then `tunneled` when a tunnel
722
+ * is open. A failing listener is logged, never thrown, so it cannot take down
723
+ * a running server or skip the next position.
724
+ *
725
+ * @param info
726
+ */
727
+ async emitServerStart(info) {
728
+ await this.emitPosition("after", () => Hook$1.emit("server:start", "after", info));
729
+ const { tunnelUrl } = info;
730
+ if (tunnelUrl) await this.emitPosition("tunneled", () => Hook$1.emit("server:start", "tunneled", {
731
+ ...info,
732
+ tunnelUrl
733
+ }));
734
+ }
735
+ async emitPosition(position, run) {
736
+ try {
737
+ await run();
738
+ } catch (error) {
739
+ Logger.error(`server:start ${position} hook failed: ${error instanceof Error ? error.message : String(error)}`, false);
740
+ }
741
+ }
742
+ bindsAll(host) {
743
+ return host === "0.0.0.0" || host === "::";
744
+ }
745
+ localHost(host) {
746
+ return this.bindsAll(host) ? "localhost" : host;
747
+ }
748
+ };
749
+ //#endregion
750
+ export { AppException, ArkstackPlugin, CONFIG_KEY, Cipher, Codec, ConfigLoader, Encryption, EncryptionKey, EnvLoader, ErrorHandler, Exception, Hash, Hook, KeyPair, Keys, Logger, NodeCipher, Plugins, Publisher, RequestException, SealedBox, SecureChannel, ServerDriver, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, setModelResolver, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
@@ -1,2 +1,2 @@
1
- import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, a as use, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, i as trait, k as SealedBox, l as assertFound, m as normalizePositiveInteger, n as crc32, o as uses, p as isClass, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, w as Encryption, x as Hash } from "../utils-B3uw4pWD.js";
1
+ import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, a as use, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, i as trait, k as SealedBox, l as assertFound, m as normalizePositiveInteger, n as crc32, o as uses, p as isClass, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, w as Encryption, x as Hash } from "../utils-DDV77Y54.js";
2
2
  export { Cipher, Codec, Encryption, EncryptionKey, Hash, KeyPair, Keys, NodeCipher, SealedBox, SecureChannel, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getModelSync, getTraitMethods, initializeGlobalContext, isClass, normalizePositiveInteger, perPage, resolvePagination, setModelResolver, trait, use, uses };
@@ -402,7 +402,7 @@ function getModelSync(modelName) {
402
402
  }
403
403
  const initializeGlobalContext = async ({ Request, Response, Session } = {}) => {
404
404
  try {
405
- const { Request: Req, Response: Res, Session: Ses } = await import("./dist-kJyHYqUy.js");
405
+ const { Request: Req, Response: Res, Session: Ses } = await import("./dist-CyPXnyte.js");
406
406
  Session ??= new Ses();
407
407
  Request ??= new Req();
408
408
  Response ??= new Res();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/common",
3
- "version": "0.21.1",
3
+ "version": "0.22.1",
4
4
  "type": "module",
5
5
  "description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -34,6 +34,7 @@
34
34
  "./package.json": "./package.json"
35
35
  },
36
36
  "dependencies": {
37
+ "@ngrok/ngrok": "^1.7.0",
37
38
  "@pictwo/faker": "^1.1.0",
38
39
  "bcryptjs": "^3.0.3",
39
40
  "chalk": "^5.6.2",
@@ -43,13 +44,13 @@
43
44
  "otpauth": "^9.5.1",
44
45
  "pino": "^10.3.1",
45
46
  "selfsigned": "^2.4.1",
46
- "@arkstack/encryption": "^0.21.1"
47
+ "@arkstack/encryption": "^0.22.1"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "@h3ravel/support": "^2.2.7",
50
51
  "arkormx": "^2.12.8",
51
- "@arkstack/contract": "^0.21.1",
52
- "@arkstack/foundry": "^0.21.1"
52
+ "@arkstack/contract": "^0.22.1",
53
+ "@arkstack/foundry": "^0.22.1"
53
54
  },
54
55
  "optionalDependencies": {
55
56
  "@faker-js/faker": "^10.4.0"
@@ -60,7 +61,7 @@
60
61
  }
61
62
  },
62
63
  "inlinedDependencies": {
63
- "clear-router": "2.9.3",
64
+ "clear-router": "2.9.4",
64
65
  "dayjs": "1.11.20",
65
66
  "kanun": "1.2.0"
66
67
  },