@arkstack/common 0.22.1 → 0.22.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.
- package/dist/index.d.ts +21 -7
- package/dist/index.js +65 -19
- package/package.json +4 -4
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
|
-
|
|
22
|
-
|
|
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
|
@@ -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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
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
|
-
|
|
56
|
-
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/common",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
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.
|
|
47
|
+
"@arkstack/encryption": "^0.22.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@h3ravel/support": "^2.2.7",
|
|
51
51
|
"arkormx": "^2.12.8",
|
|
52
|
-
"@arkstack/contract": "^0.22.
|
|
53
|
-
"@arkstack/foundry": "^0.22.
|
|
52
|
+
"@arkstack/contract": "^0.22.2",
|
|
53
|
+
"@arkstack/foundry": "^0.22.2"
|
|
54
54
|
},
|
|
55
55
|
"optionalDependencies": {
|
|
56
56
|
"@faker-js/faker": "^10.4.0"
|