elit 3.6.4 → 3.6.6

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.
Files changed (52) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +14 -1
  4. package/dist/build.d.ts +4 -1
  5. package/dist/cli.cjs +746 -166
  6. package/dist/cli.mjs +746 -166
  7. package/dist/config.d.ts +8 -1
  8. package/dist/coverage.d.ts +4 -1
  9. package/dist/desktop-auto-render.cjs +5 -4
  10. package/dist/desktop-auto-render.d.ts +4 -1
  11. package/dist/desktop-auto-render.js +5 -4
  12. package/dist/desktop-auto-render.mjs +5 -4
  13. package/dist/dom.cjs +5 -4
  14. package/dist/dom.d.ts +2 -0
  15. package/dist/dom.js +5 -4
  16. package/dist/dom.mjs +5 -4
  17. package/dist/el.d.ts +2 -0
  18. package/dist/index.cjs +5 -4
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +5 -4
  21. package/dist/index.mjs +5 -4
  22. package/dist/native.cjs +5 -4
  23. package/dist/native.d.ts +2 -0
  24. package/dist/native.js +5 -4
  25. package/dist/native.mjs +5 -4
  26. package/dist/render-context.d.ts +4 -1
  27. package/dist/router.cjs +5 -4
  28. package/dist/router.d.ts +2 -0
  29. package/dist/router.js +5 -4
  30. package/dist/router.mjs +5 -4
  31. package/dist/{server-CcBFc2F5.d.ts → server-uMQvZAll.d.ts} +9 -0
  32. package/dist/server.cjs +146 -4
  33. package/dist/server.d.ts +4 -1
  34. package/dist/server.js +4494 -285
  35. package/dist/server.mjs +146 -4
  36. package/dist/smtp-server.cjs +115 -0
  37. package/dist/smtp-server.d.ts +41 -0
  38. package/dist/smtp-server.js +4186 -0
  39. package/dist/smtp-server.mjs +87 -0
  40. package/dist/state.cjs +5 -4
  41. package/dist/state.d.ts +2 -0
  42. package/dist/state.js +5 -4
  43. package/dist/state.mjs +5 -4
  44. package/dist/test-runtime.cjs +184 -141
  45. package/dist/test-runtime.js +193 -150
  46. package/dist/test-runtime.mjs +184 -141
  47. package/dist/test.cjs +143 -134
  48. package/dist/test.js +152 -143
  49. package/dist/test.mjs +143 -134
  50. package/dist/types.d.ts +34 -2
  51. package/dist/universal.d.ts +2 -0
  52. package/package.json +9 -1
package/dist/router.mjs CHANGED
@@ -424,6 +424,7 @@ var DomNode = class {
424
424
  html += `</${tagName}>${newLine}`;
425
425
  return html;
426
426
  }
427
+ const isRawText = tagName === "script" || tagName === "style";
427
428
  if (children && children.length > 0) {
428
429
  const resolvedChildren = children.map((c) => {
429
430
  const resolved = this.resolveStateValue(c);
@@ -439,11 +440,11 @@ var DomNode = class {
439
440
  if (Array.isArray(child)) {
440
441
  for (const c of child) {
441
442
  if (!shouldSkipChild(c)) {
442
- html += this.renderToString(c, { pretty, indent: indent + 1 });
443
+ html += isRawText && typeof c === "string" ? c : this.renderToString(c, { pretty, indent: indent + 1 });
443
444
  }
444
445
  }
445
446
  } else {
446
- html += this.renderToString(child, { pretty, indent: indent + 1 });
447
+ html += isRawText && typeof child === "string" ? child : this.renderToString(child, { pretty, indent: indent + 1 });
447
448
  }
448
449
  }
449
450
  html += indentStr;
@@ -453,11 +454,11 @@ var DomNode = class {
453
454
  if (Array.isArray(child)) {
454
455
  for (const c of child) {
455
456
  if (!shouldSkipChild(c)) {
456
- html += this.renderToString(c, { pretty: false, indent: 0 });
457
+ html += isRawText && typeof c === "string" ? c : this.renderToString(c, { pretty: false, indent: 0 });
457
458
  }
458
459
  }
459
460
  } else {
460
- html += this.renderToString(child, { pretty: false, indent: 0 });
461
+ html += isRawText && typeof child === "string" ? child : this.renderToString(child, { pretty: false, indent: 0 });
461
462
  }
462
463
  }
463
464
  }
@@ -2,6 +2,7 @@ import { IncomingMessage, ServerResponse } from './http.js';
2
2
  import { WebSocket } from './ws.js';
3
3
  import { Server } from 'http';
4
4
  import { WebSocketServer } from 'ws';
5
+ import { ElitSMTPServerConfig, ElitSMTPServerHandle } from './smtp-server.js';
5
6
 
6
7
  /**
7
8
  * Elit - Types and Interfaces
@@ -79,6 +80,8 @@ interface ClientConfig {
79
80
  api?: Router;
80
81
  /** WebSocket endpoints specific to this client */
81
82
  ws?: WebSocketEndpointConfig[];
83
+ /** SMTP listeners specific to this client */
84
+ smtp?: ElitSMTPServerConfig | ElitSMTPServerConfig[];
82
85
  /** Server mode: 'dev' uses source files, 'preview' uses built files (default: 'dev') */
83
86
  mode?: 'dev' | 'preview';
84
87
  }
@@ -137,6 +140,8 @@ interface DevServerOptions {
137
140
  api?: Router;
138
141
  /** WebSocket endpoints */
139
142
  ws?: WebSocketEndpointConfig[];
143
+ /** SMTP listeners started alongside the HTTP server */
144
+ smtp?: ElitSMTPServerConfig | ElitSMTPServerConfig[];
140
145
  /** SSR render function - returns HTML VNode or string */
141
146
  ssr?: () => Child | string;
142
147
  /** Proxy configuration for API requests */
@@ -157,6 +162,8 @@ interface DevServer {
157
162
  server: Server;
158
163
  /** WebSocket server for HMR */
159
164
  wss: WebSocketServer;
165
+ /** Managed SMTP listeners started from dev or preview config */
166
+ smtpServers: ElitSMTPServerHandle[];
160
167
  /** Server URL */
161
168
  url: string;
162
169
  /** Shared state manager */
@@ -248,6 +255,8 @@ interface PreviewOptions {
248
255
  api?: Router;
249
256
  /** WebSocket endpoints */
250
257
  ws?: WebSocketEndpointConfig[];
258
+ /** SMTP listeners started alongside the preview server */
259
+ smtp?: ElitSMTPServerConfig | ElitSMTPServerConfig[];
251
260
  /** SSR render function - returns HTML VNode or string */
252
261
  ssr?: () => Child | string;
253
262
  /** Proxy configuration for API requests */
package/dist/server.cjs CHANGED
@@ -55643,6 +55643,71 @@ function lookup(path) {
55643
55643
  // src/server.ts
55644
55644
  init_runtime();
55645
55645
 
55646
+ // src/smtp-server.ts
55647
+ var import_smtp_server = require("smtp-server");
55648
+ var DEFAULT_SMTP_PORT = 2525;
55649
+ var DEFAULT_SMTP_HOST = "127.0.0.1";
55650
+ function resolveSmtpServerConfig(config = {}) {
55651
+ const { port = DEFAULT_SMTP_PORT, host = DEFAULT_SMTP_HOST, label, ...serverOptions } = config;
55652
+ return {
55653
+ ...serverOptions,
55654
+ port,
55655
+ host,
55656
+ label
55657
+ };
55658
+ }
55659
+ function normalizeSmtpServerConfigs(input) {
55660
+ const configs = Array.isArray(input) ? input : input ? [input] : [];
55661
+ return configs.map((config) => resolveSmtpServerConfig(config));
55662
+ }
55663
+ function closeSmtpServer(server) {
55664
+ return new Promise((resolve2, reject) => {
55665
+ let settled = false;
55666
+ const finish = (error) => {
55667
+ if (settled) {
55668
+ return;
55669
+ }
55670
+ settled = true;
55671
+ if (error) {
55672
+ reject(error);
55673
+ return;
55674
+ }
55675
+ resolve2();
55676
+ };
55677
+ const handleCloseError = (error) => {
55678
+ const errorCode = error.code;
55679
+ if (errorCode === "ERR_SERVER_NOT_RUNNING") {
55680
+ finish();
55681
+ return;
55682
+ }
55683
+ finish(error);
55684
+ };
55685
+ try {
55686
+ server.close(() => finish());
55687
+ } catch (error) {
55688
+ handleCloseError(error);
55689
+ }
55690
+ });
55691
+ }
55692
+ function createSmtpServer(config = {}) {
55693
+ const resolvedConfig = resolveSmtpServerConfig(config);
55694
+ const { port, host, label: _label, ...serverOptions } = resolvedConfig;
55695
+ const server = new import_smtp_server.SMTPServer(serverOptions);
55696
+ return {
55697
+ server,
55698
+ config: resolvedConfig,
55699
+ listen(callback) {
55700
+ return callback ? server.listen(port, host, callback) : server.listen(port, host);
55701
+ },
55702
+ address() {
55703
+ return server.server.address();
55704
+ },
55705
+ close() {
55706
+ return closeSmtpServer(server);
55707
+ }
55708
+ };
55709
+ }
55710
+
55646
55711
  // src/render-context.ts
55647
55712
  var RUNTIME_TARGET_KEY = "__ELIT_RUNTIME_TARGET__";
55648
55713
  var CAPTURED_RENDER_KEY = "__ELIT_CAPTURED_RENDER__";
@@ -56069,6 +56134,7 @@ var DomNode = class {
56069
56134
  html2 += `</${tagName}>${newLine}`;
56070
56135
  return html2;
56071
56136
  }
56137
+ const isRawText = tagName === "script" || tagName === "style";
56072
56138
  if (children && children.length > 0) {
56073
56139
  const resolvedChildren = children.map((c) => {
56074
56140
  const resolved = this.resolveStateValue(c);
@@ -56084,11 +56150,11 @@ var DomNode = class {
56084
56150
  if (Array.isArray(child)) {
56085
56151
  for (const c of child) {
56086
56152
  if (!shouldSkipChild(c)) {
56087
- html2 += this.renderToString(c, { pretty, indent: indent + 1 });
56153
+ html2 += isRawText && typeof c === "string" ? c : this.renderToString(c, { pretty, indent: indent + 1 });
56088
56154
  }
56089
56155
  }
56090
56156
  } else {
56091
- html2 += this.renderToString(child, { pretty, indent: indent + 1 });
56157
+ html2 += isRawText && typeof child === "string" ? child : this.renderToString(child, { pretty, indent: indent + 1 });
56092
56158
  }
56093
56159
  }
56094
56160
  html2 += indentStr;
@@ -56098,11 +56164,11 @@ var DomNode = class {
56098
56164
  if (Array.isArray(child)) {
56099
56165
  for (const c of child) {
56100
56166
  if (!shouldSkipChild(c)) {
56101
- html2 += this.renderToString(c, { pretty: false, indent: 0 });
56167
+ html2 += isRawText && typeof c === "string" ? c : this.renderToString(c, { pretty: false, indent: 0 });
56102
56168
  }
56103
56169
  }
56104
56170
  } else {
56105
- html2 += this.renderToString(child, { pretty: false, indent: 0 });
56171
+ html2 += isRawText && typeof child === "string" ? child : this.renderToString(child, { pretty: false, indent: 0 });
56106
56172
  }
56107
56173
  }
56108
56174
  }
@@ -57383,6 +57449,56 @@ var defaultOptions = {
57383
57449
  worker: [],
57384
57450
  mode: "dev"
57385
57451
  };
57452
+ function createSmtpBindingKey(config) {
57453
+ return `${config.host}:${config.port}`;
57454
+ }
57455
+ function createSmtpServerLabel(config) {
57456
+ return config.label || createSmtpBindingKey(config);
57457
+ }
57458
+ function formatSmtpServerAddress(address, fallback) {
57459
+ if (typeof address === "string") {
57460
+ return address;
57461
+ }
57462
+ if (address) {
57463
+ return `${address.address}:${address.port}`;
57464
+ }
57465
+ return createSmtpBindingKey(fallback);
57466
+ }
57467
+ function collectSmtpServerConfigs(config, usesClientArray) {
57468
+ const modeLabel = config.mode || "dev";
57469
+ const smtpConfigs = normalizeSmtpServerConfigs(config.smtp).map((smtpConfig, index) => ({
57470
+ ...smtpConfig,
57471
+ label: smtpConfig.label || `${modeLabel}.smtp[${index}]`
57472
+ }));
57473
+ if (!usesClientArray || !config.clients) {
57474
+ return smtpConfigs;
57475
+ }
57476
+ for (let clientIndex = 0; clientIndex < config.clients.length; clientIndex += 1) {
57477
+ const client = config.clients[clientIndex];
57478
+ const clientDescriptor = client.basePath || client.root;
57479
+ const clientPrefix = clientDescriptor ? `${modeLabel}.clients[${clientIndex}] (${clientDescriptor})` : `${modeLabel}.clients[${clientIndex}]`;
57480
+ smtpConfigs.push(...normalizeSmtpServerConfigs(client.smtp).map((smtpConfig, smtpIndex) => ({
57481
+ ...smtpConfig,
57482
+ label: smtpConfig.label || `${clientPrefix}.smtp[${smtpIndex}]`
57483
+ })));
57484
+ }
57485
+ return smtpConfigs;
57486
+ }
57487
+ function assertUniqueSmtpServerBindings(configs) {
57488
+ const seenBindings = /* @__PURE__ */ new Map();
57489
+ for (const smtpConfig of configs) {
57490
+ if (smtpConfig.port === 0) {
57491
+ continue;
57492
+ }
57493
+ const bindingKey = createSmtpBindingKey(smtpConfig);
57494
+ const currentLabel = createSmtpServerLabel(smtpConfig);
57495
+ const previousLabel = seenBindings.get(bindingKey);
57496
+ if (previousLabel) {
57497
+ throw new Error(`Duplicate SMTP server binding "${bindingKey}" configured for ${previousLabel} and ${currentLabel}`);
57498
+ }
57499
+ seenBindings.set(bindingKey, currentLabel);
57500
+ }
57501
+ }
57386
57502
  function shouldUseClientFallbackRoot(primaryRoot, fallbackRoot, indexPath) {
57387
57503
  if (!fallbackRoot) {
57388
57504
  return false;
@@ -57517,6 +57633,7 @@ function createDevServer(options) {
57517
57633
  const globalWebSocketEndpoints = usesClientArray ? normalizeWebSocketEndpoints(config.ws) : [];
57518
57634
  const normalizedWebSocketEndpoints = [...normalizedClients.flatMap((client) => client.ws), ...globalWebSocketEndpoints];
57519
57635
  const seenWebSocketPaths = /* @__PURE__ */ new Set();
57636
+ const smtpServerConfigs = collectSmtpServerConfigs(config, usesClientArray);
57520
57637
  for (const endpoint of normalizedWebSocketEndpoints) {
57521
57638
  if (endpoint.path === ELIT_INTERNAL_WS_PATH) {
57522
57639
  throw new Error(`WebSocket path "${ELIT_INTERNAL_WS_PATH}" is reserved for Elit internals`);
@@ -57526,6 +57643,21 @@ function createDevServer(options) {
57526
57643
  }
57527
57644
  seenWebSocketPaths.add(endpoint.path);
57528
57645
  }
57646
+ assertUniqueSmtpServerBindings(smtpServerConfigs);
57647
+ const smtpServers = smtpServerConfigs.map((smtpConfig) => {
57648
+ const smtpServer = createSmtpServer(smtpConfig);
57649
+ const smtpLabel = createSmtpServerLabel(smtpServer.config);
57650
+ smtpServer.server.on("error", (error) => {
57651
+ console.error(`[SMTP] ${smtpLabel} error:`, error);
57652
+ });
57653
+ if (config.logging) {
57654
+ smtpServer.server.server.once("listening", () => {
57655
+ console.log(`[SMTP] ${smtpLabel} listening on ${formatSmtpServerAddress(smtpServer.address(), smtpServer.config)}`);
57656
+ });
57657
+ }
57658
+ smtpServer.listen();
57659
+ return smtpServer;
57660
+ });
57529
57661
  const globalProxyHandler = config.proxy ? createProxyHandler(config.proxy) : null;
57530
57662
  const server = createServer(async (req, res) => {
57531
57663
  const originalUrl = req.url || "/";
@@ -58066,6 +58198,15 @@ ${elitImportMap}`;
58066
58198
  if (config.logging) console.log("\n[Server] Shutting down...");
58067
58199
  transformCache.clear();
58068
58200
  if (watcher) await watcher.close();
58201
+ if (smtpServers.length > 0) {
58202
+ await Promise.all(smtpServers.map(async (smtpServer) => {
58203
+ try {
58204
+ await smtpServer.close();
58205
+ } catch (error) {
58206
+ console.error(`[SMTP] ${createSmtpServerLabel(smtpServer.config)} close error:`, error);
58207
+ }
58208
+ }));
58209
+ }
58069
58210
  if (webSocketServers.length > 0) {
58070
58211
  webSocketServers.forEach((wsServer) => wsServer.close());
58071
58212
  wsClients.clear();
@@ -58082,6 +58223,7 @@ ${elitImportMap}`;
58082
58223
  return {
58083
58224
  server,
58084
58225
  wss,
58226
+ smtpServers,
58085
58227
  url: primaryUrl,
58086
58228
  state: stateManager,
58087
58229
  close
package/dist/server.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import './http.js';
2
2
  import './ws.js';
3
- export { E as ElitRequest, c as ElitResponse, H as HttpMethod, M as Middleware, S as ServerRouteContext, d as ServerRouteHandler, e as ServerRouter, f as SharedState, g as SharedStateOptions, h as StateChangeHandler, i as StateManager, j as bodyLimit, k as cacheControl, l as clearImportMapCache, m as compress, n as cors, o as createDevServer, p as createElitImportMap, q as createProxyHandler, r as errorHandler, s as html, t as json, u as logger, v as rateLimit, w as resolveWorkspaceElitImportBasePath, x as security, y as status, z as text } from './server-CcBFc2F5.js';
3
+ export { E as ElitRequest, c as ElitResponse, H as HttpMethod, M as Middleware, S as ServerRouteContext, d as ServerRouteHandler, e as ServerRouter, f as SharedState, g as SharedStateOptions, h as StateChangeHandler, i as StateManager, j as bodyLimit, k as cacheControl, l as clearImportMapCache, m as compress, n as cors, o as createDevServer, p as createElitImportMap, q as createProxyHandler, r as errorHandler, s as html, t as json, u as logger, v as rateLimit, w as resolveWorkspaceElitImportBasePath, x as security, y as status, z as text } from './server-uMQvZAll.js';
4
4
  import 'node:events';
5
5
  import 'events';
6
6
  import 'http';
7
7
  import 'ws';
8
+ import './smtp-server.js';
9
+ import 'net';
10
+ import 'smtp-server';