@push.rocks/smartproxy 16.0.4 → 18.0.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.
Files changed (49) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/common/port80-adapter.js +29 -3
  3. package/dist_ts/core/utils/shared-security-manager.js +3 -3
  4. package/dist_ts/forwarding/config/forwarding-types.d.ts +3 -29
  5. package/dist_ts/forwarding/config/forwarding-types.js +3 -36
  6. package/dist_ts/forwarding/config/index.d.ts +3 -2
  7. package/dist_ts/forwarding/config/index.js +4 -3
  8. package/dist_ts/forwarding/factory/forwarding-factory.js +9 -3
  9. package/dist_ts/forwarding/handlers/base-handler.d.ts +8 -1
  10. package/dist_ts/forwarding/handlers/base-handler.js +29 -4
  11. package/dist_ts/forwarding/handlers/http-handler.js +8 -4
  12. package/dist_ts/forwarding/index.d.ts +3 -8
  13. package/dist_ts/forwarding/index.js +4 -13
  14. package/dist_ts/proxies/smart-proxy/models/index.d.ts +0 -1
  15. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +2 -11
  16. package/dist_ts/proxies/smart-proxy/models/interfaces.js +1 -12
  17. package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +22 -71
  18. package/dist_ts/proxies/smart-proxy/models/route-types.js +2 -1
  19. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +0 -3
  20. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +7 -12
  21. package/dist_ts/proxies/smart-proxy/route-manager.js +6 -7
  22. package/dist_ts/proxies/smart-proxy/security-manager.d.ts +7 -8
  23. package/dist_ts/proxies/smart-proxy/security-manager.js +8 -9
  24. package/dist_ts/proxies/smart-proxy/smart-proxy.js +2 -3
  25. package/dist_ts/proxies/smart-proxy/utils/index.d.ts +0 -2
  26. package/dist_ts/proxies/smart-proxy/utils/index.js +3 -6
  27. package/dist_ts/proxies/smart-proxy/utils/route-patterns.d.ts +48 -0
  28. package/dist_ts/proxies/smart-proxy/utils/route-patterns.js +106 -2
  29. package/package.json +1 -1
  30. package/readme.plan.md +122 -79
  31. package/ts/00_commitinfo_data.ts +1 -1
  32. package/ts/common/port80-adapter.ts +26 -2
  33. package/ts/core/utils/shared-security-manager.ts +2 -2
  34. package/ts/forwarding/config/forwarding-types.ts +12 -70
  35. package/ts/forwarding/config/index.ts +19 -2
  36. package/ts/forwarding/factory/forwarding-factory.ts +7 -2
  37. package/ts/forwarding/handlers/base-handler.ts +29 -3
  38. package/ts/forwarding/handlers/http-handler.ts +8 -3
  39. package/ts/forwarding/index.ts +17 -17
  40. package/ts/proxies/smart-proxy/models/index.ts +0 -3
  41. package/ts/proxies/smart-proxy/models/interfaces.ts +3 -19
  42. package/ts/proxies/smart-proxy/models/route-types.ts +32 -85
  43. package/ts/proxies/smart-proxy/route-connection-handler.ts +4 -14
  44. package/ts/proxies/smart-proxy/route-manager.ts +7 -12
  45. package/ts/proxies/smart-proxy/security-manager.ts +7 -8
  46. package/ts/proxies/smart-proxy/smart-proxy.ts +2 -4
  47. package/ts/proxies/smart-proxy/utils/index.ts +2 -5
  48. package/ts/proxies/smart-proxy/utils/route-patterns.ts +146 -2
  49. package/ts/proxies/smart-proxy/utils/route-migration-utils.ts +0 -165
@@ -63,16 +63,15 @@ export class SecurityManager {
63
63
  }
64
64
 
65
65
  /**
66
- * Check if an IP is authorized using forwarding security rules
66
+ * Check if an IP is authorized using security rules
67
67
  *
68
68
  * This method is used to determine if an IP is allowed to connect, based on security
69
- * rules configured in the forwarding configuration. The allowed and blocked IPs are
70
- * typically derived from domain.forwarding.security.allowedIps and blockedIps through
71
- * DomainConfigManager.getEffectiveIPRules().
69
+ * rules configured in the route configuration. The allowed and blocked IPs are
70
+ * typically derived from route.security.ipAllowList and ipBlockList.
72
71
  *
73
72
  * @param ip - The IP address to check
74
- * @param allowedIPs - Array of allowed IP patterns from forwarding.security.allowedIps
75
- * @param blockedIPs - Array of blocked IP patterns from forwarding.security.blockedIps
73
+ * @param allowedIPs - Array of allowed IP patterns from security.ipAllowList
74
+ * @param blockedIPs - Array of blocked IP patterns from security.ipBlockList
76
75
  * @returns true if IP is authorized, false if blocked
77
76
  */
78
77
  public isIPAuthorized(ip: string, allowedIPs: string[], blockedIPs: string[] = []): boolean {
@@ -94,10 +93,10 @@ export class SecurityManager {
94
93
  * Check if the IP matches any of the glob patterns from security configuration
95
94
  *
96
95
  * This method checks IP addresses against glob patterns and handles IPv4/IPv6 normalization.
97
- * It's used to implement IP filtering based on the forwarding.security configuration.
96
+ * It's used to implement IP filtering based on the route.security configuration.
98
97
  *
99
98
  * @param ip - The IP address to check
100
- * @param patterns - Array of glob patterns from forwarding.security.allowedIps or blockedIps
99
+ * @param patterns - Array of glob patterns from security.ipAllowList or ipBlockList
101
100
  * @returns true if IP matches any pattern, false otherwise
102
101
  */
103
102
  private isGlobIPMatch(ip: string, patterns: string[]): boolean {
@@ -19,10 +19,8 @@ import { createPort80HandlerOptions } from '../../common/port80-adapter.js';
19
19
 
20
20
  // Import types and utilities
21
21
  import type {
22
- ISmartProxyOptions,
23
- IRoutedSmartProxyOptions
22
+ ISmartProxyOptions
24
23
  } from './models/interfaces.js';
25
- import { isRoutedOptions, isLegacyOptions } from './models/interfaces.js';
26
24
  import type { IRouteConfig } from './models/route-types.js';
27
25
 
28
26
  /**
@@ -650,7 +648,7 @@ export class SmartProxy extends plugins.EventEmitter {
650
648
  const domains: string[] = [];
651
649
 
652
650
  // Get domains from routes
653
- const routes = isRoutedOptions(this.settings) ? this.settings.routes : [];
651
+ const routes = this.settings.routes || [];
654
652
 
655
653
  for (const route of routes) {
656
654
  if (!route.match.domains) continue;
@@ -5,8 +5,7 @@
5
5
  * including helpers, validators, utilities, and patterns for working with routes.
6
6
  */
7
7
 
8
- // Export route helpers for creating routes
9
- export * from './route-helpers.js';
8
+ // Route helpers have been consolidated in route-patterns.js
10
9
 
11
10
  // Export route validators for validating route configurations
12
11
  export * from './route-validators.js';
@@ -35,6 +34,4 @@ export {
35
34
  addJwtAuth
36
35
  };
37
36
 
38
- // Export migration utilities for transitioning from domain-based to route-based configs
39
- // Note: These will be removed in a future version once migration is complete
40
- export * from './route-migration-utils.js';
37
+ // Migration utilities have been removed as they are no longer needed
@@ -5,10 +5,154 @@
5
5
  * These patterns can be used as templates for creating route configurations.
6
6
  */
7
7
 
8
- import type { IRouteConfig } from '../models/route-types.js';
9
- import { createHttpRoute, createHttpsTerminateRoute, createHttpsPassthroughRoute, createCompleteHttpsServer } from './route-helpers.js';
8
+ import type { IRouteConfig, IRouteMatch, IRouteAction, IRouteTarget } from '../models/route-types.js';
10
9
  import { mergeRouteConfigs } from './route-utils.js';
11
10
 
11
+ /**
12
+ * Create a basic HTTP route configuration
13
+ */
14
+ export function createHttpRoute(
15
+ domains: string | string[],
16
+ target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
17
+ options: Partial<IRouteConfig> = {}
18
+ ): IRouteConfig {
19
+ const route: IRouteConfig = {
20
+ match: {
21
+ domains,
22
+ ports: 80
23
+ },
24
+ action: {
25
+ type: 'forward',
26
+ target: {
27
+ host: target.host,
28
+ port: target.port
29
+ }
30
+ },
31
+ name: options.name || `HTTP: ${Array.isArray(domains) ? domains.join(', ') : domains}`
32
+ };
33
+
34
+ return mergeRouteConfigs(route, options);
35
+ }
36
+
37
+ /**
38
+ * Create an HTTPS route with TLS termination
39
+ */
40
+ export function createHttpsTerminateRoute(
41
+ domains: string | string[],
42
+ target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
43
+ options: Partial<IRouteConfig> & {
44
+ certificate?: 'auto' | { key: string; cert: string };
45
+ reencrypt?: boolean;
46
+ } = {}
47
+ ): IRouteConfig {
48
+ const route: IRouteConfig = {
49
+ match: {
50
+ domains,
51
+ ports: 443
52
+ },
53
+ action: {
54
+ type: 'forward',
55
+ target: {
56
+ host: target.host,
57
+ port: target.port
58
+ },
59
+ tls: {
60
+ mode: options.reencrypt ? 'terminate-and-reencrypt' : 'terminate',
61
+ certificate: options.certificate || 'auto'
62
+ }
63
+ },
64
+ name: options.name || `HTTPS (terminate): ${Array.isArray(domains) ? domains.join(', ') : domains}`
65
+ };
66
+
67
+ return mergeRouteConfigs(route, options);
68
+ }
69
+
70
+ /**
71
+ * Create an HTTPS route with TLS passthrough
72
+ */
73
+ export function createHttpsPassthroughRoute(
74
+ domains: string | string[],
75
+ target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
76
+ options: Partial<IRouteConfig> = {}
77
+ ): IRouteConfig {
78
+ const route: IRouteConfig = {
79
+ match: {
80
+ domains,
81
+ ports: 443
82
+ },
83
+ action: {
84
+ type: 'forward',
85
+ target: {
86
+ host: target.host,
87
+ port: target.port
88
+ },
89
+ tls: {
90
+ mode: 'passthrough'
91
+ }
92
+ },
93
+ name: options.name || `HTTPS (passthrough): ${Array.isArray(domains) ? domains.join(', ') : domains}`
94
+ };
95
+
96
+ return mergeRouteConfigs(route, options);
97
+ }
98
+
99
+ /**
100
+ * Create an HTTP to HTTPS redirect route
101
+ */
102
+ export function createHttpToHttpsRedirect(
103
+ domains: string | string[],
104
+ options: Partial<IRouteConfig> & {
105
+ redirectCode?: 301 | 302 | 307 | 308;
106
+ preservePath?: boolean;
107
+ } = {}
108
+ ): IRouteConfig {
109
+ const route: IRouteConfig = {
110
+ match: {
111
+ domains,
112
+ ports: 80
113
+ },
114
+ action: {
115
+ type: 'redirect',
116
+ redirect: {
117
+ to: options.preservePath ? 'https://{domain}{path}' : 'https://{domain}',
118
+ status: options.redirectCode || 301
119
+ }
120
+ },
121
+ name: options.name || `HTTP to HTTPS redirect: ${Array.isArray(domains) ? domains.join(', ') : domains}`
122
+ };
123
+
124
+ return mergeRouteConfigs(route, options);
125
+ }
126
+
127
+ /**
128
+ * Create a complete HTTPS server with redirect from HTTP
129
+ */
130
+ export function createCompleteHttpsServer(
131
+ domains: string | string[],
132
+ target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
133
+ options: Partial<IRouteConfig> & {
134
+ certificate?: 'auto' | { key: string; cert: string };
135
+ tlsMode?: 'terminate' | 'passthrough' | 'terminate-and-reencrypt';
136
+ redirectCode?: 301 | 302 | 307 | 308;
137
+ } = {}
138
+ ): IRouteConfig[] {
139
+ // Create the TLS route based on the selected mode
140
+ const tlsRoute = options.tlsMode === 'passthrough'
141
+ ? createHttpsPassthroughRoute(domains, target, options)
142
+ : createHttpsTerminateRoute(domains, target, {
143
+ ...options,
144
+ reencrypt: options.tlsMode === 'terminate-and-reencrypt'
145
+ });
146
+
147
+ // Create the HTTP to HTTPS redirect route
148
+ const redirectRoute = createHttpToHttpsRedirect(domains, {
149
+ redirectCode: options.redirectCode,
150
+ preservePath: true
151
+ });
152
+
153
+ return [tlsRoute, redirectRoute];
154
+ }
155
+
12
156
  /**
13
157
  * Create an API Gateway route pattern
14
158
  * @param domains Domain(s) to match
@@ -1,165 +0,0 @@
1
- /**
2
- * Route Migration Utilities
3
- *
4
- * This file provides utility functions for migrating from legacy domain-based
5
- * configuration to the new route-based configuration system. These functions
6
- * are temporary and will be removed after the migration is complete.
7
- */
8
-
9
- import type { TForwardingType } from '../../../forwarding/config/forwarding-types.js';
10
- import type { IRouteConfig, IRouteMatch, IRouteAction, IRouteTarget } from '../models/route-types.js';
11
-
12
- /**
13
- * Legacy domain config interface (for migration only)
14
- * @deprecated This interface will be removed in a future version
15
- */
16
- export interface ILegacyDomainConfig {
17
- domains: string[];
18
- forwarding: {
19
- type: TForwardingType;
20
- target: {
21
- host: string | string[];
22
- port: number;
23
- };
24
- [key: string]: any;
25
- };
26
- }
27
-
28
- /**
29
- * Convert a legacy domain config to a route-based config
30
- * @param domainConfig Legacy domain configuration
31
- * @param additionalOptions Additional options to add to the route
32
- * @returns Route configuration
33
- * @deprecated This function will be removed in a future version
34
- */
35
- export function domainConfigToRouteConfig(
36
- domainConfig: ILegacyDomainConfig,
37
- additionalOptions: Partial<IRouteConfig> = {}
38
- ): IRouteConfig {
39
- // Default port based on forwarding type
40
- let defaultPort = 80;
41
- let tlsMode: 'passthrough' | 'terminate' | 'terminate-and-reencrypt' | undefined;
42
-
43
- switch (domainConfig.forwarding.type) {
44
- case 'http-only':
45
- defaultPort = 80;
46
- break;
47
- case 'https-passthrough':
48
- defaultPort = 443;
49
- tlsMode = 'passthrough';
50
- break;
51
- case 'https-terminate-to-http':
52
- defaultPort = 443;
53
- tlsMode = 'terminate';
54
- break;
55
- case 'https-terminate-to-https':
56
- defaultPort = 443;
57
- tlsMode = 'terminate-and-reencrypt';
58
- break;
59
- }
60
-
61
- // Create route match criteria
62
- const match: IRouteMatch = {
63
- ports: additionalOptions.match?.ports || defaultPort,
64
- domains: domainConfig.domains
65
- };
66
-
67
- // Create route target
68
- const target: IRouteTarget = {
69
- host: domainConfig.forwarding.target.host,
70
- port: domainConfig.forwarding.target.port
71
- };
72
-
73
- // Create route action
74
- const action: IRouteAction = {
75
- type: 'forward',
76
- target
77
- };
78
-
79
- // Add TLS configuration if needed
80
- if (tlsMode) {
81
- action.tls = {
82
- mode: tlsMode,
83
- certificate: 'auto'
84
- };
85
-
86
- // If the legacy config has custom certificates, use them
87
- if (domainConfig.forwarding.https?.customCert) {
88
- action.tls.certificate = {
89
- key: domainConfig.forwarding.https.customCert.key,
90
- cert: domainConfig.forwarding.https.customCert.cert
91
- };
92
- }
93
- }
94
-
95
- // Add security options if present
96
- if (domainConfig.forwarding.security) {
97
- action.security = domainConfig.forwarding.security;
98
- }
99
-
100
- // Create the route config
101
- const routeConfig: IRouteConfig = {
102
- match,
103
- action,
104
- // Include a name based on domains if not provided
105
- name: additionalOptions.name || `Legacy route for ${domainConfig.domains.join(', ')}`,
106
- // Include a note that this was converted from a legacy config
107
- description: additionalOptions.description || 'Converted from legacy domain configuration'
108
- };
109
-
110
- // Add optional properties if provided
111
- if (additionalOptions.priority !== undefined) {
112
- routeConfig.priority = additionalOptions.priority;
113
- }
114
-
115
- if (additionalOptions.tags) {
116
- routeConfig.tags = additionalOptions.tags;
117
- }
118
-
119
- return routeConfig;
120
- }
121
-
122
- /**
123
- * Convert an array of legacy domain configs to route configurations
124
- * @param domainConfigs Array of legacy domain configurations
125
- * @returns Array of route configurations
126
- * @deprecated This function will be removed in a future version
127
- */
128
- export function domainConfigsToRouteConfigs(
129
- domainConfigs: ILegacyDomainConfig[]
130
- ): IRouteConfig[] {
131
- return domainConfigs.map(config => domainConfigToRouteConfig(config));
132
- }
133
-
134
- /**
135
- * Extract domains from a route configuration
136
- * @param route Route configuration
137
- * @returns Array of domains
138
- */
139
- export function extractDomainsFromRoute(route: IRouteConfig): string[] {
140
- if (!route.match.domains) {
141
- return [];
142
- }
143
-
144
- return Array.isArray(route.match.domains)
145
- ? route.match.domains
146
- : [route.match.domains];
147
- }
148
-
149
- /**
150
- * Extract domains from an array of route configurations
151
- * @param routes Array of route configurations
152
- * @returns Array of unique domains
153
- */
154
- export function extractDomainsFromRoutes(routes: IRouteConfig[]): string[] {
155
- const domains = new Set<string>();
156
-
157
- for (const route of routes) {
158
- const routeDomains = extractDomainsFromRoute(route);
159
- for (const domain of routeDomains) {
160
- domains.add(domain);
161
- }
162
- }
163
-
164
- return Array.from(domains);
165
- }