silgi 0.12.3 → 0.13.0

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,4 +1,4 @@
1
- const version = "0.12.3";
1
+ const version = "0.13.0";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -2,6 +2,7 @@ import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPres
2
2
  import { Buffer } from 'node:buffer';
3
3
  import * as consola from 'consola';
4
4
  import { ConsolaOptions } from 'consola';
5
+ import { IncomingMessage } from 'node:http';
5
6
 
6
7
  declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
7
8
 
@@ -93,6 +94,17 @@ declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedS
93
94
  */
94
95
  declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
95
96
 
97
+ declare function useRequest(event: SilgiEvents): false | (IncomingMessage & {
98
+ originalUrl?: string;
99
+ });
100
+ declare function getIpAddress(event: SilgiEvents): string | false;
101
+ /**
102
+ * Extract the client's IP address from request headers with high accuracy
103
+ * @param req - The incoming HTTP request
104
+ * @returns The client's IP address or empty string if not found
105
+ */
106
+ declare function ipAddress(req: IncomingMessage): string;
107
+
96
108
  declare function relativeWithDot(from: string, to: string): string;
97
109
  /** @since 3.9.0 */
98
110
  declare function toArray<T>(value: T | T[]): T[];
@@ -113,4 +125,4 @@ declare const MODE_RE: RegExp;
113
125
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
114
126
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
115
127
 
116
- export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
128
+ export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
@@ -2,6 +2,7 @@ import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPres
2
2
  import { Buffer } from 'node:buffer';
3
3
  import * as consola from 'consola';
4
4
  import { ConsolaOptions } from 'consola';
5
+ import { IncomingMessage } from 'node:http';
5
6
 
6
7
  declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
7
8
 
@@ -93,6 +94,17 @@ declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedS
93
94
  */
94
95
  declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
95
96
 
97
+ declare function useRequest(event: SilgiEvents): false | (IncomingMessage & {
98
+ originalUrl?: string;
99
+ });
100
+ declare function getIpAddress(event: SilgiEvents): string | false;
101
+ /**
102
+ * Extract the client's IP address from request headers with high accuracy
103
+ * @param req - The incoming HTTP request
104
+ * @returns The client's IP address or empty string if not found
105
+ */
106
+ declare function ipAddress(req: IncomingMessage): string;
107
+
96
108
  declare function relativeWithDot(from: string, to: string): string;
97
109
  /** @since 3.9.0 */
98
110
  declare function toArray<T>(value: T | T[]): T[];
@@ -113,4 +125,4 @@ declare const MODE_RE: RegExp;
113
125
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
114
126
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
115
127
 
116
- export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
128
+ export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
@@ -413,4 +413,85 @@ function normalizeTemplate(template, buildDir) {
413
413
  return template;
414
414
  }
415
415
 
416
- export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
416
+ function useRequest(event) {
417
+ const silgi = useSilgi();
418
+ if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
419
+ return event.node.req;
420
+ }
421
+ return false;
422
+ }
423
+ function getIpAddress(event) {
424
+ const silgi = useSilgi();
425
+ if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
426
+ const _ipAddress = ipAddress(event.node.req);
427
+ return _ipAddress;
428
+ }
429
+ return false;
430
+ }
431
+ function ipAddress(req) {
432
+ const headers = [
433
+ "cf-connecting-ip",
434
+ // Cloudflare
435
+ "true-client-ip",
436
+ // Akamai and Cloudflare
437
+ "x-real-ip",
438
+ // Nginx proxy/FastCGI
439
+ "x-forwarded-for",
440
+ // Standard proxy header
441
+ "x-client-ip",
442
+ // Apache
443
+ "x-forwarded",
444
+ // Alternative format
445
+ "forwarded",
446
+ // RFC 7239 compliant format
447
+ "forwarded-for",
448
+ // RFC 7239 variant
449
+ "x-appengine-user-ip",
450
+ // Google App Engine
451
+ "x-cluster-client-ip",
452
+ // GCP load balancer
453
+ "fastly-client-ip",
454
+ // Fastly CDN
455
+ "x-azure-clientip",
456
+ // Azure
457
+ "x-original-forwarded-for",
458
+ // Secondary forwarded-for header
459
+ "x-lb-forwarded-for",
460
+ // Load balancer specific
461
+ "cdn-loop"
462
+ // Used by some CDNs
463
+ ];
464
+ for (const header of headers) {
465
+ const value = req.headers[header];
466
+ if (!value)
467
+ continue;
468
+ let ip;
469
+ if (Array.isArray(value)) {
470
+ ip = value[0];
471
+ } else if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") {
472
+ ip = value.split(",")[0];
473
+ } else if (header === "forwarded") {
474
+ const match = value.match(/for=([^;]+)/);
475
+ ip = match ? match[1].trim().replace(/^\[|\]$/g, "") : "";
476
+ } else {
477
+ ip = value;
478
+ }
479
+ const cleanIp = ip.trim();
480
+ if (cleanIp && isValidIp(cleanIp)) {
481
+ return cleanIp;
482
+ }
483
+ }
484
+ const socketIp = req.socket.remoteAddress ?? "";
485
+ return socketIp && isValidIp(socketIp) ? socketIp : "";
486
+ }
487
+ function isValidIp(ip) {
488
+ if (ip === "::1" || ip === "localhost" || ip === "127.0.0.1")
489
+ return true;
490
+ if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip))
491
+ return true;
492
+ if (/^[0-9a-f:]+$/i.test(ip))
493
+ return true;
494
+ return false;
495
+ }
496
+
497
+ export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
@@ -1,4 +1,4 @@
1
- const version = "0.12.3";
1
+ const version = "0.13.0";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -1,4 +1,4 @@
1
- const version = "0.12.3";
1
+ const version = "0.13.0";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^2.0.2",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -917,7 +917,7 @@ interface StorageKeyParams<TInput = unknown> {
917
917
  interface SilgiRuntimeShareds extends SilgiRuntimeSharedExtends {
918
918
  storage: <T extends StorageValue = StorageValue>(base: StorageConfig<T>['base']) => Storage<T>;
919
919
  silgi: SilgiFunction;
920
- runtimeConfig: SilgiRuntimeOptions;
920
+ runtimeConfig: SilgiRuntimeConfig;
921
921
  }
922
922
  interface SilgiRuntimeSharedExtends {
923
923
  }
@@ -917,7 +917,7 @@ interface StorageKeyParams<TInput = unknown> {
917
917
  interface SilgiRuntimeShareds extends SilgiRuntimeSharedExtends {
918
918
  storage: <T extends StorageValue = StorageValue>(base: StorageConfig<T>['base']) => Storage<T>;
919
919
  silgi: SilgiFunction;
920
- runtimeConfig: SilgiRuntimeOptions;
920
+ runtimeConfig: SilgiRuntimeConfig;
921
921
  }
922
922
  interface SilgiRuntimeSharedExtends {
923
923
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.12.3",
4
+ "version": "0.13.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {