@etohq/connector-engine 1.5.1-alpha.4

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 (77) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE +21 -0
  4. package/README.md +253 -0
  5. package/dist/engine/clean-connector-engine.d.ts +81 -0
  6. package/dist/engine/clean-connector-engine.d.ts.map +1 -0
  7. package/dist/engine/clean-connector-engine.js +350 -0
  8. package/dist/engine/clean-connector-engine.js.map +1 -0
  9. package/dist/engine/connector-engine-impl.d.ts +73 -0
  10. package/dist/engine/connector-engine-impl.d.ts.map +1 -0
  11. package/dist/engine/connector-engine-impl.js +332 -0
  12. package/dist/engine/connector-engine-impl.js.map +1 -0
  13. package/dist/engine/connector-engine.d.ts +54 -0
  14. package/dist/engine/connector-engine.d.ts.map +1 -0
  15. package/dist/engine/connector-engine.js +694 -0
  16. package/dist/engine/connector-engine.js.map +1 -0
  17. package/dist/engine/index.d.ts +7 -0
  18. package/dist/engine/index.d.ts.map +1 -0
  19. package/dist/engine/index.js +10 -0
  20. package/dist/engine/index.js.map +1 -0
  21. package/dist/engine/routing-engine.d.ts +26 -0
  22. package/dist/engine/routing-engine.d.ts.map +1 -0
  23. package/dist/engine/routing-engine.js +329 -0
  24. package/dist/engine/routing-engine.js.map +1 -0
  25. package/dist/examples/booking-connector-example.d.ts +7 -0
  26. package/dist/examples/booking-connector-example.d.ts.map +1 -0
  27. package/dist/examples/booking-connector-example.js +221 -0
  28. package/dist/examples/booking-connector-example.js.map +1 -0
  29. package/dist/examples/dynamic-methods-example.d.ts +7 -0
  30. package/dist/examples/dynamic-methods-example.d.ts.map +1 -0
  31. package/dist/examples/dynamic-methods-example.js +163 -0
  32. package/dist/examples/dynamic-methods-example.js.map +1 -0
  33. package/dist/index.d.ts +9 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +14 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/types/base-plugin.d.ts +170 -0
  38. package/dist/types/base-plugin.d.ts.map +1 -0
  39. package/dist/types/base-plugin.js +68 -0
  40. package/dist/types/base-plugin.js.map +1 -0
  41. package/dist/types/connector-plugin.d.ts +22 -0
  42. package/dist/types/connector-plugin.d.ts.map +1 -0
  43. package/dist/types/connector-plugin.js +11 -0
  44. package/dist/types/connector-plugin.js.map +1 -0
  45. package/dist/types/engine.d.ts +223 -0
  46. package/dist/types/engine.d.ts.map +1 -0
  47. package/dist/types/engine.js +7 -0
  48. package/dist/types/engine.js.map +1 -0
  49. package/dist/types/index.d.ts +5 -0
  50. package/dist/types/index.d.ts.map +1 -0
  51. package/dist/types/index.js +9 -0
  52. package/dist/types/index.js.map +1 -0
  53. package/dist/types/operation-groups.d.ts +78 -0
  54. package/dist/types/operation-groups.d.ts.map +1 -0
  55. package/dist/types/operation-groups.js +60 -0
  56. package/dist/types/operation-groups.js.map +1 -0
  57. package/dist/types/routing-config.d.ts +116 -0
  58. package/dist/types/routing-config.d.ts.map +1 -0
  59. package/dist/types/routing-config.js +6 -0
  60. package/dist/types/routing-config.js.map +1 -0
  61. package/dist/utils/create-connector-engine.d.ts +31 -0
  62. package/dist/utils/create-connector-engine.d.ts.map +1 -0
  63. package/dist/utils/create-connector-engine.js +30 -0
  64. package/dist/utils/create-connector-engine.js.map +1 -0
  65. package/examples/booking-example.ts +168 -0
  66. package/examples/booking-test.ts +231 -0
  67. package/hyperswitch-example.ts +263 -0
  68. package/jest.config.js +2 -0
  69. package/package.json +54 -0
  70. package/src/engine/clean-connector-engine.ts +726 -0
  71. package/src/engine/index.ts +13 -0
  72. package/src/engine/routing-engine.ts +394 -0
  73. package/src/index.ts +32 -0
  74. package/src/types/connector-plugin.ts +34 -0
  75. package/src/types/index.ts +5 -0
  76. package/src/types/routing-config.ts +196 -0
  77. package/tsconfig.json +3 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing-config.d.ts","sourceRoot":"","sources":["../../src/types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M,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAGjH,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAGnE,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CACtF"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Generic Routing Configuration (Not Payment-Specific)
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=routing-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing-config.js","sourceRoot":"","sources":["../../src/types/routing-config.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,31 @@
1
+ import type { OperationGroupsConfig } from "../types/operation-groups";
2
+ import type { BaseConnectorPlugin } from "../types/base-plugin";
3
+ /**
4
+ * Helper function to create connector engine instances
5
+ * Wraps the ETO ConnectorEngine factory function for easier usage
6
+ */
7
+ export interface PluginConfiguration {
8
+ [domainName: string]: BaseConnectorPlugin;
9
+ }
10
+ /**
11
+ * Create a connector engine with plugins and operation groups
12
+ *
13
+ * @param plugins - Configuration object mapping domain names to plugin instances
14
+ * @param operationGroups - Optional operation groups configuration
15
+ * @returns Configured connector engine instance
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const engine = createConnectorEngine({
20
+ * meeting: new MeetingPlugin(),
21
+ * google: new GoogleCalendarPlugin()
22
+ * }, {
23
+ * resource: {
24
+ * domains: ['meeting'],
25
+ * operations: ['checkAvailability', 'reserveResource']
26
+ * }
27
+ * });
28
+ * ```
29
+ */
30
+ export declare function createConnectorEngine(plugins: PluginConfiguration, operationGroups?: OperationGroupsConfig): void;
31
+ //# sourceMappingURL=create-connector-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-connector-engine.d.ts","sourceRoot":"","sources":["../../src/utils/create-connector-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE;;;GAGG;AAEH,MAAM,WAAW,mBAAmB;IAClC,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,mBAAmB,EAC5B,eAAe,CAAC,EAAE,qBAAqB,QAMxC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConnectorEngine = createConnectorEngine;
4
+ const connector_engine_1 = require("../engine/connector-engine");
5
+ /**
6
+ * Create a connector engine with plugins and operation groups
7
+ *
8
+ * @param plugins - Configuration object mapping domain names to plugin instances
9
+ * @param operationGroups - Optional operation groups configuration
10
+ * @returns Configured connector engine instance
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const engine = createConnectorEngine({
15
+ * meeting: new MeetingPlugin(),
16
+ * google: new GoogleCalendarPlugin()
17
+ * }, {
18
+ * resource: {
19
+ * domains: ['meeting'],
20
+ * operations: ['checkAvailability', 'reserveResource']
21
+ * }
22
+ * });
23
+ * ```
24
+ */
25
+ function createConnectorEngine(plugins, operationGroups) {
26
+ // ConnectorEngine is a factory function, not a class constructor
27
+ const engine = (0, connector_engine_1.ConnectorEngine)(plugins, operationGroups);
28
+ return engine;
29
+ }
30
+ //# sourceMappingURL=create-connector-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-connector-engine.js","sourceRoot":"","sources":["../../src/utils/create-connector-engine.ts"],"names":[],"mappings":";;AAiCA,sDAQC;AAzCD,iEAA6D;AAa7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,qBAAqB,CACnC,OAA4B,EAC5B,eAAuC;IAEvC,iEAAiE;IACjE,MAAM,MAAM,GAAG,IAAA,kCAAe,EAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAEzD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * @fileoverview Booking Example Configuration
3
+ * @description Example showing simplified connector types with optional domain
4
+ */
5
+
6
+ import { ConnectorEngine } from "../src";
7
+
8
+ // ===== OPERATION TYPE DEFINITIONS =====
9
+
10
+ interface MeetingsAvailabilityOperation {
11
+ resourceType: string;
12
+ timeSlot: { start: Date; end: Date };
13
+ eventTypeId: string;
14
+ requirements?: { capacity?: number; location?: string };
15
+ }
16
+
17
+ interface MeetingsReservationOperation {
18
+ resourceType: string;
19
+ bookingData: {
20
+ title: string;
21
+ start_time: Date;
22
+ end_time: Date;
23
+ attendees: Array<{ email: string; name: string }>;
24
+ eventTypeId: string;
25
+ location?: string;
26
+ };
27
+ }
28
+
29
+ interface LogisticsAvailabilityOperation {
30
+ resourceType: string;
31
+ timeSlot: { start: Date; end: Date };
32
+ vehicleType: string;
33
+ route?: { pickup: string; delivery: string };
34
+ requirements?: { capacity?: number; specialEquipment?: string[] };
35
+ }
36
+
37
+ interface LogisticsReservationOperation {
38
+ resourceType: string;
39
+ deliveryData: {
40
+ vehicleId: string;
41
+ pickup: { address: string; timeWindow: { start: Date; end: Date } };
42
+ delivery: { address: string; timeWindow: { start: Date; end: Date } };
43
+ cargo: { weight: number; dimensions: { length: number; width: number; height: number } };
44
+ specialInstructions?: string;
45
+ };
46
+ }
47
+
48
+ // ===== SIMPLIFIED CONNECTOR TYPES CONFIGURATION =====
49
+
50
+ const bookingConnectorTypes = {
51
+ // Meetings domain
52
+ meetings: {
53
+ checkAvailability: {} as MeetingsAvailabilityOperation,
54
+ reserveResource: {} as MeetingsReservationOperation
55
+ },
56
+
57
+ // Logistics domain
58
+ logistics: {
59
+ checkAvailability: {} as LogisticsAvailabilityOperation,
60
+ reserveResource: {} as LogisticsReservationOperation
61
+ }
62
+ } as const;
63
+
64
+ // ===== OPERATION GROUPS CONFIGURATION =====
65
+
66
+ const bookingOperationGroups = {
67
+ // Universal resource operations - domain optional, defaults to first domain
68
+ resource: {
69
+ domains: ['meetings', 'logistics'],
70
+ operations: ['checkAvailability', 'reserveResource'],
71
+ options: {
72
+ behavior: 'route_by_domain' as const,
73
+ priority: 1,
74
+ timeout: 30000,
75
+ retries: 2
76
+ }
77
+ },
78
+
79
+ // Internal operations - execute all domains
80
+ internal: {
81
+ domains: ['meetings', 'logistics'],
82
+ operations: ['checkAvailability'],
83
+ options: {
84
+ behavior: 'execute_all' as const,
85
+ connectorId: 'internal-system',
86
+ priority: 2,
87
+ timeout: 15000,
88
+ retries: 1
89
+ }
90
+ },
91
+
92
+ // External operations - first success
93
+ external: {
94
+ domains: ['meetings'],
95
+ operations: ['reserveResource'],
96
+ options: {
97
+ behavior: 'first_success' as const,
98
+ priority: 3,
99
+ timeout: 45000,
100
+ retries: 3
101
+ }
102
+ }
103
+ } as const;
104
+
105
+ // ===== CREATE CONNECTOR ENGINE =====
106
+
107
+ export const bookingConnectorEngine = ConnectorEngine(
108
+ bookingConnectorTypes,
109
+ bookingOperationGroups
110
+ );
111
+
112
+ // ===== UPDATED USAGE EXAMPLES =====
113
+
114
+ export async function exampleUsage() {
115
+
116
+ // โœ… Resource operations - domain optional
117
+ const meetingAvailability = await bookingConnectorEngine.executeResourceCheckAvailability({
118
+ // โœ… No domain - uses group default (first domain: 'meetings')
119
+ resourceType: 'conference_room',
120
+ timeSlot: { start: new Date(), end: new Date() },
121
+ eventTypeId: 'team-meeting',
122
+ requirements: { capacity: 10 }
123
+ });
124
+
125
+ // โœ… Resource operations - domain override
126
+ const logisticsAvailability = await bookingConnectorEngine.executeResourceCheckAvailability({
127
+ domain: 'logistics', // โœ… Override to logistics domain
128
+ resourceType: 'delivery_vehicle',
129
+ timeSlot: { start: new Date(), end: new Date() },
130
+ vehicleType: 'truck',
131
+ requirements: { capacity: 1000 }
132
+ });
133
+
134
+ // โœ… Internal operations - execute all domains
135
+ const internalAvailability = await bookingConnectorEngine.executeInternalCheckAvailability({
136
+ // โœ… No domain - executes all configured domains
137
+ resourceType: 'any',
138
+ timeSlot: { start: new Date(), end: new Date() },
139
+ eventTypeId: 'internal-check', // Required by meetings
140
+ vehicleType: 'any' // Required by logistics
141
+ });
142
+
143
+ // โœ… External operations - first success
144
+ const externalReservation = await bookingConnectorEngine.executeExternalReserveResource({
145
+ // โœ… No domain - uses first success behavior on meetings domain
146
+ resourceType: 'conference_room',
147
+ bookingData: {
148
+ title: 'Important Meeting',
149
+ start_time: new Date(),
150
+ end_time: new Date(),
151
+ attendees: [{ email: 'user@example.com', name: 'User' }],
152
+ eventTypeId: 'external-meeting'
153
+ }
154
+ });
155
+
156
+ return {
157
+ meetingAvailability,
158
+ logisticsAvailability,
159
+ internalAvailability,
160
+ externalReservation
161
+ };
162
+ }
163
+
164
+ // ===== EXPORT TYPES FOR EXTERNAL USE =====
165
+
166
+ export type BookingConnectorEngine = typeof bookingConnectorEngine;
167
+ export type BookingConnectorTypes = typeof bookingConnectorTypes;
168
+ export type BookingOperationGroups = typeof bookingOperationGroups;
@@ -0,0 +1,231 @@
1
+ /**
2
+ * @fileoverview Booking Operation Groups Test
3
+ * @description Test file for simplified connector types with optional domain
4
+ */
5
+
6
+ import { bookingConnectorEngine, exampleUsage } from './booking-example';
7
+
8
+ // ===== TYPE SAFETY TESTS =====
9
+
10
+ // โœ… Test 1: Resource operations with optional domain
11
+ async function testResourceOperations() {
12
+ console.log('๐Ÿงช Testing Resource Operations...');
13
+
14
+ try {
15
+ // Default domain routing (no domain specified)
16
+ const defaultResult = await bookingConnectorEngine.executeResourceCheckAvailability({
17
+ // โœ… No domain - uses group default ('meetings')
18
+ resourceType: 'conference_room',
19
+ timeSlot: { start: new Date('2024-01-15T10:00:00Z'), end: new Date('2024-01-15T11:00:00Z') },
20
+ eventTypeId: 'team-meeting'
21
+ });
22
+ console.log('โœ… Default domain routing (meetings):', defaultResult);
23
+
24
+ // Explicit domain override
25
+ const logisticsResult = await bookingConnectorEngine.executeResourceCheckAvailability({
26
+ domain: 'logistics', // โœ… Optional override
27
+ resourceType: 'delivery_truck',
28
+ timeSlot: { start: new Date('2024-01-15T09:00:00Z'), end: new Date('2024-01-15T17:00:00Z') },
29
+ vehicleType: 'medium_truck',
30
+ route: { pickup: '123 Warehouse St', delivery: '456 Customer Ave' }
31
+ });
32
+ console.log('โœ… Explicit domain override (logistics):', logisticsResult);
33
+
34
+ } catch (error) {
35
+ console.error('โŒ Resource operations test failed:', error);
36
+ }
37
+ }
38
+
39
+ // โœ… Test 2: Internal operations (execute all domains)
40
+ async function testInternalOperations() {
41
+ console.log('๐Ÿงช Testing Internal Operations...');
42
+
43
+ try {
44
+ const internalResult = await bookingConnectorEngine.executeInternalCheckAvailability({
45
+ // โœ… No domain - executes all configured domains
46
+ resourceType: 'any_resource',
47
+ timeSlot: { start: new Date('2024-01-15T14:00:00Z'), end: new Date('2024-01-15T15:00:00Z') },
48
+ eventTypeId: 'internal-check', // Required by meetings domain
49
+ vehicleType: 'any_vehicle' // Required by logistics domain
50
+ });
51
+ console.log('โœ… Internal operations (all domains):', internalResult);
52
+
53
+ } catch (error) {
54
+ console.error('โŒ Internal operations test failed:', error);
55
+ }
56
+ }
57
+
58
+ // โœ… Test 3: External operations (first success)
59
+ async function testExternalOperations() {
60
+ console.log('๐Ÿงช Testing External Operations...');
61
+
62
+ try {
63
+ const externalResult = await bookingConnectorEngine.executeExternalReserveResource({
64
+ // โœ… No domain - uses first success on meetings domain
65
+ resourceType: 'meeting_room',
66
+ bookingData: {
67
+ title: 'Client Presentation',
68
+ start_time: new Date('2024-01-15T16:00:00Z'),
69
+ end_time: new Date('2024-01-15T17:00:00Z'),
70
+ attendees: [
71
+ { email: 'client@example.com', name: 'Client Representative' },
72
+ { email: 'sales@company.com', name: 'Sales Manager' }
73
+ ],
74
+ eventTypeId: 'client-meeting',
75
+ location: 'Conference Room A'
76
+ }
77
+ });
78
+ console.log('โœ… External operations (first success):', externalResult);
79
+
80
+ } catch (error) {
81
+ console.error('โŒ External operations test failed:', error);
82
+ }
83
+ }
84
+
85
+ // โœ… Test 4: Domain validation
86
+ async function testDomainValidation() {
87
+ console.log('๐Ÿงช Testing Domain Validation...');
88
+
89
+ try {
90
+ // Valid domain override
91
+ const validResult = await bookingConnectorEngine.executeResourceCheckAvailability({
92
+ domain: 'meetings', // โœ… Valid domain for resource group
93
+ resourceType: 'conference_room',
94
+ timeSlot: { start: new Date(), end: new Date() },
95
+ eventTypeId: 'test-meeting'
96
+ });
97
+ console.log('โœ… Valid domain override:', validResult);
98
+
99
+ // Invalid domain should throw error
100
+ try {
101
+ await bookingConnectorEngine.executeResourceCheckAvailability({
102
+ domain: 'invalid_domain' as any, // โŒ Invalid domain
103
+ resourceType: 'conference_room',
104
+ timeSlot: { start: new Date(), end: new Date() },
105
+ eventTypeId: 'test-meeting'
106
+ });
107
+ console.error('โŒ Should have thrown error for invalid domain');
108
+ } catch (error) {
109
+ console.log('โœ… Correctly rejected invalid domain:', error.message);
110
+ }
111
+
112
+ } catch (error) {
113
+ console.error('โŒ Domain validation test failed:', error);
114
+ }
115
+ }
116
+
117
+ // ===== TYPE SAFETY VALIDATION =====
118
+
119
+ function validateTypeSafety() {
120
+ console.log('๐Ÿงช Validating Type Safety...');
121
+
122
+ // These should cause TypeScript errors if uncommented:
123
+
124
+ /*
125
+ // โŒ Invalid domain type
126
+ bookingConnectorEngine.executeResourceCheckAvailability({
127
+ domain: 'invalid_domain', // TypeScript error: not in 'meetings' | 'logistics'
128
+ resourceType: 'room',
129
+ timeSlot: { start: new Date(), end: new Date() },
130
+ eventTypeId: 'test'
131
+ });
132
+
133
+ // โŒ Missing required field for meetings domain
134
+ bookingConnectorEngine.executeResourceCheckAvailability({
135
+ resourceType: 'room',
136
+ timeSlot: { start: new Date(), end: new Date() }
137
+ // Missing eventTypeId - TypeScript error
138
+ });
139
+
140
+ // โŒ Wrong field for logistics domain
141
+ bookingConnectorEngine.executeResourceCheckAvailability({
142
+ domain: 'logistics',
143
+ resourceType: 'truck',
144
+ timeSlot: { start: new Date(), end: new Date() },
145
+ eventTypeId: 'test' // Wrong field - should be vehicleType
146
+ });
147
+ */
148
+
149
+ console.log('โœ… Type safety validation passed (no TypeScript errors)');
150
+ }
151
+
152
+ // ===== PERFORMANCE TESTS =====
153
+
154
+ async function testPerformance() {
155
+ console.log('๐Ÿงช Testing Performance...');
156
+
157
+ const startTime = Date.now();
158
+
159
+ try {
160
+ // Execute multiple operations in parallel
161
+ const results = await Promise.all([
162
+ bookingConnectorEngine.executeResourceCheckAvailability({
163
+ resourceType: 'room_1',
164
+ timeSlot: { start: new Date(), end: new Date() },
165
+ eventTypeId: 'perf-test'
166
+ }),
167
+ bookingConnectorEngine.executeResourceCheckAvailability({
168
+ domain: 'logistics',
169
+ resourceType: 'truck_1',
170
+ timeSlot: { start: new Date(), end: new Date() },
171
+ vehicleType: 'small_truck'
172
+ }),
173
+ bookingConnectorEngine.executeInternalCheckAvailability({
174
+ resourceType: 'any',
175
+ timeSlot: { start: new Date(), end: new Date() },
176
+ eventTypeId: 'perf-test',
177
+ vehicleType: 'any'
178
+ })
179
+ ]);
180
+
181
+ const executionTime = Date.now() - startTime;
182
+ console.log(`โœ… Performance test completed in ${executionTime}ms`);
183
+ console.log(`โœ… Executed ${results.length} operations in parallel`);
184
+
185
+ } catch (error) {
186
+ console.error('โŒ Performance test failed:', error);
187
+ }
188
+ }
189
+
190
+ // ===== RUN ALL TESTS =====
191
+
192
+ export async function runAllTests() {
193
+ console.log('๐Ÿš€ Starting Connector Engine Operation Groups Tests...\n');
194
+
195
+ // Validate type safety first
196
+ validateTypeSafety();
197
+ console.log('');
198
+
199
+ // Run functional tests
200
+ await testResourceOperations();
201
+ console.log('');
202
+
203
+ await testInternalOperations();
204
+ console.log('');
205
+
206
+ await testExternalOperations();
207
+ console.log('');
208
+
209
+ await testDomainValidation();
210
+ console.log('');
211
+
212
+ await testPerformance();
213
+ console.log('');
214
+
215
+ // Run example usage
216
+ console.log('๐Ÿงช Testing Example Usage...');
217
+ try {
218
+ const exampleResults = await exampleUsage();
219
+ console.log('โœ… Example usage completed successfully');
220
+ console.log('Results summary:', Object.keys(exampleResults));
221
+ } catch (error) {
222
+ console.error('โŒ Example usage failed:', error);
223
+ }
224
+
225
+ console.log('\n๐ŸŽ‰ All tests completed!');
226
+ }
227
+
228
+ // Run tests if this file is executed directly
229
+ if (require.main === module) {
230
+ runAllTests().catch(console.error);
231
+ }