@arkstack/common 0.22.1 → 0.22.3

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.
@@ -3085,7 +3085,7 @@ function mergeDeep(target, source) {
3085
3085
  });
3086
3086
  import_dayjs_min.default.extend(import_customParseFormat.default);
3087
3087
  //#endregion
3088
- //#region ../http/dist/redirect-D4Oybkdd.js
3088
+ //#region ../http/dist/redirect-CRt-ETAb.js
3089
3089
  const unwrapRequestSource = (source) => {
3090
3090
  if (source.original) return unwrapRequestSource(source.original);
3091
3091
  if (source.headers) return source;
@@ -3122,6 +3122,7 @@ const isRecord = (value) => {
3122
3122
  };
3123
3123
  let fallbackRequest;
3124
3124
  const requestResolvers = /* @__PURE__ */ new Set();
3125
+ /** The request currently being handled, resolved through the registered request resolvers. */
3125
3126
  const currentRequest = () => {
3126
3127
  for (const resolver of requestResolvers) {
3127
3128
  const request = resolver();
package/dist/index.d.ts CHANGED
@@ -7,6 +7,24 @@ import pino from "pino";
7
7
  //#region src/lifecycle.d.ts
8
8
  declare const bindGracefulShutdown: (shutdown: () => Promise<void> | void, defer?: boolean) => void;
9
9
  //#endregion
10
+ //#region src/ErrorPage.d.ts
11
+ type ErrorPageOptions = {
12
+ message?: string;
13
+ stack?: string;
14
+ code?: number;
15
+ title?: string;
16
+ };
17
+ /**
18
+ * Renders the HTML error page, using the `~arkstack/common.error` view when
19
+ * `@arkstack/view` is installed and a built-in document otherwise.
20
+ */
21
+ declare class ErrorPage {
22
+ static readonly titles: Record<number, string>;
23
+ static render({ message, stack, title, code }?: ErrorPageOptions): string;
24
+ private static document;
25
+ private static escape;
26
+ }
27
+ //#endregion
10
28
  //#region src/network.d.ts
11
29
  /**
12
30
  * Boots the app using an available port close to the requested port
@@ -18,12 +36,8 @@ declare const bindGracefulShutdown: (shutdown: () => Promise<void> | void, defer
18
36
  * @param defer
19
37
  */
20
38
  declare const bootWithDetectedPort: <TApp, TRoutes = unknown, THandler = unknown>(boot: (port: number) => Promise<void>, preferredPort?: number, app?: Arkstack<TApp, TRoutes, THandler>, defer?: boolean) => Promise<void>;
21
- declare const renderError: ({ message, stack, title, code }: {
22
- message?: string;
23
- stack?: string;
24
- code?: number;
25
- title?: string;
26
- }) => string;
39
+ /** Renders the HTML error page, with or without `@arkstack/view` installed. */
40
+ declare const renderError: (options?: ErrorPageOptions) => string;
27
41
  //#endregion
28
42
  //#region src/prototypes.d.ts
29
43
  declare const loadPrototypes: () => void;
@@ -555,4 +569,4 @@ declare abstract class ServerDriver<TApp, TMiddleware> extends ArkstackKitDriver
555
569
  private localHost;
556
570
  }
557
571
  //#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 };
572
+ 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, ErrorPage, ErrorPageOptions, 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,5 +1,5 @@
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-DDV77Y54.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-BAQ2oTO0.js";
3
3
  import { ArkstackPlugin, Hook, Hook as Hook$1, Plugins } from "@arkstack/foundry";
4
4
  import { Arkstack, ArkstackKitDriver } from "@arkstack/contract";
5
5
  import { str } from "@h3ravel/support";
@@ -26,6 +26,68 @@ const bindGracefulShutdown = (shutdown, defer) => {
26
26
  });
27
27
  };
28
28
  //#endregion
29
+ //#region src/ErrorPage.ts
30
+ /**
31
+ * Renders the HTML error page, using the `~arkstack/common.error` view when
32
+ * `@arkstack/view` is installed and a built-in document otherwise.
33
+ */
34
+ var ErrorPage = class {
35
+ static titles = {
36
+ 400: "Bad Request",
37
+ 401: "Unauthorized",
38
+ 403: "Forbidden",
39
+ 404: "Not Found",
40
+ 500: "Internal Server Error",
41
+ 502: "Bad Gateway",
42
+ 503: "Service Unavailable",
43
+ 504: "Gateway Timeout"
44
+ };
45
+ static render({ message = "An unexpected error occurred.", stack, title, code = 500 } = {}) {
46
+ const data = {
47
+ code,
48
+ title: this.titles[code] || title || "Error",
49
+ stack,
50
+ message
51
+ };
52
+ const view = globalThis.view;
53
+ if (typeof view === "function") return view("~arkstack/common.error", data).renderSync();
54
+ return this.document(data);
55
+ }
56
+ static document({ code, title, stack, message }) {
57
+ return [
58
+ "<!DOCTYPE html>",
59
+ "<html lang=\"en\">",
60
+ "<head>",
61
+ "<meta charset=\"UTF-8\" />",
62
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />",
63
+ `<title>${code} | ${this.escape(title)}</title>`,
64
+ "<style>",
65
+ ":root{color-scheme:light dark}",
66
+ "body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;padding:2rem 1rem;box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;background:#0b0c0e;color:#f5f0e8}",
67
+ "@media (prefers-color-scheme: light){body{background:#f5f3ef;color:#1a1714}}",
68
+ ".page{max-width:620px;width:100%}",
69
+ ".code{font-size:3.5rem;font-weight:800;color:#e05252;margin:0 0 .5rem}",
70
+ ".title{font-size:1.2rem;font-weight:700;margin:0 0 .6rem}",
71
+ ".message{font-size:.8rem;opacity:.7;line-height:1.7;margin:0 0 2rem}",
72
+ "pre{font-size:.72rem;line-height:1.85;overflow-x:auto;padding:1.1rem 1.25rem;border:1px solid rgba(220,60,60,.22);border-radius:10px}",
73
+ "</style>",
74
+ "</head>",
75
+ "<body>",
76
+ "<div class=\"page\">",
77
+ `<div class="code">${code}</div>`,
78
+ `<div class="title">${this.escape(title)}</div>`,
79
+ `<p class="message">${this.escape(message)}</p>`,
80
+ ...stack ? [`<pre>${this.escape(stack)}</pre>`] : [],
81
+ "</div>",
82
+ "</body>",
83
+ "</html>"
84
+ ].join("\n");
85
+ }
86
+ static escape(value) {
87
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
88
+ }
89
+ };
90
+ //#endregion
29
91
  //#region src/network.ts
30
92
  /**
31
93
  * Boots the app using an available port close to the requested port
@@ -52,24 +114,8 @@ const bootWithDetectedPort = async (boot, preferredPort = 3e3, app, defer) => {
52
114
  bindGracefulShutdown(async () => await app?.shutdown(), defer);
53
115
  await Hook$1.emit("boot", "after", port, app);
54
116
  };
55
- const renderError = ({ message = "An unexpected error occurred.", stack, title, code = 500 }) => {
56
- title = {
57
- 400: "Bad Request",
58
- 401: "Unauthorized",
59
- 403: "Forbidden",
60
- 404: "Not Found",
61
- 500: "Internal Server Error",
62
- 502: "Bad Gateway",
63
- 503: "Service Unavailable",
64
- 504: "Gateway Timeout"
65
- }[code] || title || "Error";
66
- return globalThis.view("~arkstack/common.error", {
67
- code,
68
- title,
69
- stack,
70
- message
71
- }).renderSync();
72
- };
117
+ /** Renders the HTML error page, with or without `@arkstack/view` installed. */
118
+ const renderError = (options = {}) => ErrorPage.render(options);
73
119
  //#endregion
74
120
  //#region src/prototypes.ts
75
121
  const loadPrototypes = () => {
@@ -747,4 +793,4 @@ var ServerDriver = class extends ArkstackKitDriver {
747
793
  }
748
794
  };
749
795
  //#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 };
796
+ export { AppException, ArkstackPlugin, CONFIG_KEY, Cipher, Codec, ConfigLoader, Encryption, EncryptionKey, EnvLoader, ErrorHandler, ErrorPage, 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-DDV77Y54.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-BAQ2oTO0.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-CyPXnyte.js");
405
+ const { Request: Req, Response: Res, Session: Ses } = await import("./dist-D5RGcD_l.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.22.1",
3
+ "version": "0.22.3",
4
4
  "type": "module",
5
5
  "description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -44,13 +44,13 @@
44
44
  "otpauth": "^9.5.1",
45
45
  "pino": "^10.3.1",
46
46
  "selfsigned": "^2.4.1",
47
- "@arkstack/encryption": "^0.22.1"
47
+ "@arkstack/encryption": "^0.22.3"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@h3ravel/support": "^2.2.7",
51
51
  "arkormx": "^2.12.8",
52
- "@arkstack/contract": "^0.22.1",
53
- "@arkstack/foundry": "^0.22.1"
52
+ "@arkstack/contract": "^0.22.3",
53
+ "@arkstack/foundry": "^0.22.3"
54
54
  },
55
55
  "optionalDependencies": {
56
56
  "@faker-js/faker": "^10.4.0"