@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,263 @@
1
+ // /**
2
+ // * Hyperswitch-Style Routing Integration Example
3
+ // */
4
+
5
+ // import { ConnectorEngine, ConnectorPlugin, AbstractConnectorPlugin, RoutingConfig } from "./src";
6
+
7
+ // // ===== PAYMENT PLUGINS =====
8
+ // class StripePlugin extends AbstractConnectorPlugin<{
9
+ // createPayment: {
10
+ // input: { amount: number; currency: string; payment_method: string };
11
+ // output: { payment_id: string; status: 'succeeded' | 'pending' };
12
+ // };
13
+ // }> {
14
+ // getName() { return 'stripe'; }
15
+ // getVersion() { return '1.0.0'; }
16
+
17
+ // operations = {
18
+ // createPayment: async (input, config) => {
19
+ // console.log(`Stripe payment: $${input.amount/100} ${input.currency} via ${config.region}`);
20
+ // return { payment_id: `pi_${Date.now()}`, status: 'succeeded' as const };
21
+ // }
22
+ // };
23
+ // }
24
+
25
+ // class PayPalPlugin extends AbstractConnectorPlugin<{
26
+ // createPayment: {
27
+ // input: { amount: number; currency: string; payment_method: string };
28
+ // output: { payment_id: string; status: 'succeeded' | 'pending' };
29
+ // };
30
+ // }> {
31
+ // getName() { return 'paypal'; }
32
+ // getVersion() { return '1.0.0'; }
33
+
34
+ // operations = {
35
+ // createPayment: async (input, config) => {
36
+ // console.log(`PayPal payment: $${input.amount/100} ${input.currency} via ${config.region}`);
37
+ // return { payment_id: `pp_${Date.now()}`, status: 'succeeded' as const };
38
+ // }
39
+ // };
40
+ // }
41
+
42
+ // // ===== ENGINE WITH HYPERSWITCH ROUTING =====
43
+ // const engine = ConnectorEngine({
44
+ // 'stripe-us': new StripePlugin(),
45
+ // 'stripe-eu': new StripePlugin(),
46
+ // 'paypal-us': new PayPalPlugin(),
47
+ // 'paypal-eu': new PayPalPlugin()
48
+ // }, {
49
+ // payments: {
50
+ // connectors: ['stripe-us', 'stripe-eu', 'paypal-us', 'paypal-eu'],
51
+ // operations: ['createPayment'],
52
+ // options: { behavior: 'execute_all' } // Will be overridden by routing config
53
+ // }
54
+ // }, {
55
+ // // Connector configs from DB
56
+ // configLoader: async (connectorId: string) => {
57
+ // const configs = {
58
+ // 'stripe-us': { region: 'US', secretKey: 'sk_us_xxx' },
59
+ // 'stripe-eu': { region: 'EU', secretKey: 'sk_eu_yyy' },
60
+ // 'paypal-us': { region: 'US', clientId: 'pp_us_xxx' },
61
+ // 'paypal-eu': { region: 'EU', clientId: 'pp_eu_yyy' }
62
+ // };
63
+ // return configs[connectorId as keyof typeof configs];
64
+ // },
65
+
66
+ // // Hyperswitch-style routing config from DB
67
+ // routingConfigLoader: async (groupId: string) => {
68
+ // const routingConfigs: Record<string, RoutingConfig> = {
69
+ // payments: {
70
+ // profile_id: 'payment_profile_1',
71
+ // name: 'Smart Payment Routing',
72
+ // algorithm: {
73
+ // type: 'advanced',
74
+ // data: [
75
+ // {
76
+ // name: 'EU_Payments',
77
+ // description: 'Route EU payments to EU connectors',
78
+ // conditions: {
79
+ // currency: ['EUR', 'GBP'],
80
+ // country: ['DE', 'FR', 'GB', 'IT', 'ES']
81
+ // },
82
+ // connectors: [
83
+ // { connector: 'stripe-eu', priority: 100, weight: 70 },
84
+ // { connector: 'paypal-eu', priority: 90, weight: 30 }
85
+ // ],
86
+ // enabled: true,
87
+ // created_at: '2024-01-01T00:00:00Z',
88
+ // modified_at: '2024-01-01T00:00:00Z'
89
+ // },
90
+ // {
91
+ // name: 'US_High_Value',
92
+ // description: 'High value US payments via Stripe',
93
+ // conditions: {
94
+ // currency: ['USD'],
95
+ // country: ['US'],
96
+ // amount: { min: 10000 } // $100+
97
+ // },
98
+ // connectors: [
99
+ // { connector: 'stripe-us', priority: 100 }
100
+ // ],
101
+ // enabled: true,
102
+ // created_at: '2024-01-01T00:00:00Z',
103
+ // modified_at: '2024-01-01T00:00:00Z'
104
+ // },
105
+ // {
106
+ // name: 'US_Default',
107
+ // description: 'Default US payment routing',
108
+ // conditions: {
109
+ // currency: ['USD'],
110
+ // country: ['US']
111
+ // },
112
+ // connectors: [
113
+ // { connector: 'stripe-us', priority: 100, weight: 60 },
114
+ // { connector: 'paypal-us', priority: 90, weight: 40 }
115
+ // ],
116
+ // enabled: true,
117
+ // created_at: '2024-01-01T00:00:00Z',
118
+ // modified_at: '2024-01-01T00:00:00Z'
119
+ // }
120
+ // ]
121
+ // },
122
+ // fallback_routing: {
123
+ // enabled: true,
124
+ // connectors: ['paypal-us', 'paypal-eu']
125
+ // },
126
+ // circuit_breaker: {
127
+ // failure_threshold: 5,
128
+ // recovery_time_seconds: 300,
129
+ // max_retries: 3
130
+ // },
131
+ // created_at: '2024-01-01T00:00:00Z',
132
+ // modified_at: '2024-01-01T00:00:00Z',
133
+ // version: 1
134
+ // }
135
+ // };
136
+
137
+ // return routingConfigs[groupId];
138
+ // }
139
+ // });
140
+
141
+ // // ===== USAGE EXAMPLES =====
142
+
143
+ // async function demonstrateHyperswitchRouting() {
144
+ // console.log('=== Hyperswitch-Style Routing Demo ===\n');
145
+
146
+ // // 1. EU Payment - Should route to stripe-eu
147
+ // console.log('1. EU Payment (EUR 50):');
148
+ // const euPayment = engine.executePaymentsCreatePayment(
149
+ // {
150
+ // amount: 5000,
151
+ // currency: 'EUR',
152
+ // payment_method: 'card'
153
+ // },
154
+ // {
155
+ // // Payment context for routing decisions
156
+ // currency: 'EUR',
157
+ // country: 'DE',
158
+ // amount: 5000,
159
+ // payment_method: 'card'
160
+ // } as PaymentContext
161
+ // );
162
+
163
+ // const euResult = await euPayment.run({
164
+ // input: { amount: 5000, currency: 'EUR', payment_method: 'card' }
165
+ // });
166
+ // console.log('EU Result:', euResult);
167
+
168
+ // // 2. US High Value - Should route to stripe-us
169
+ // console.log('\n2. US High Value Payment (USD 150):');
170
+ // const highValuePayment = engine.executePaymentsCreatePayment(
171
+ // {
172
+ // amount: 15000,
173
+ // currency: 'USD',
174
+ // payment_method: 'card'
175
+ // },
176
+ // {
177
+ // currency: 'USD',
178
+ // country: 'US',
179
+ // amount: 15000,
180
+ // payment_method: 'card'
181
+ // } as PaymentContext
182
+ // );
183
+
184
+ // const highValueResult = await highValuePayment.run({
185
+ // input: { amount: 15000, currency: 'USD', payment_method: 'card' }
186
+ // });
187
+ // console.log('High Value Result:', highValueResult);
188
+
189
+ // // 3. US Default - Should use weighted routing between stripe-us and paypal-us
190
+ // console.log('\n3. US Default Payment (USD 25):');
191
+ // const defaultPayment = engine.executePaymentsCreatePayment(
192
+ // {
193
+ // amount: 2500,
194
+ // currency: 'USD',
195
+ // payment_method: 'card'
196
+ // },
197
+ // {
198
+ // currency: 'USD',
199
+ // country: 'US',
200
+ // amount: 2500,
201
+ // payment_method: 'card'
202
+ // } as PaymentContext
203
+ // );
204
+
205
+ // const defaultResult = await defaultPayment.run({
206
+ // input: { amount: 2500, currency: 'USD', payment_method: 'card' }
207
+ // });
208
+ // console.log('Default Result:', defaultResult);
209
+
210
+ // console.log('\n=== Routing Demo Complete ===');
211
+ // }
212
+
213
+ // // ===== BUSINESS LOGIC INTEGRATION =====
214
+
215
+ // class PaymentService {
216
+ // constructor(private engine: typeof engine) {}
217
+
218
+ // async processPayment(paymentRequest: {
219
+ // amount: number;
220
+ // currency: string;
221
+ // customerId: string;
222
+ // country: string;
223
+ // paymentMethod: string;
224
+ // }) {
225
+ // // Create payment context for smart routing
226
+ // const context: PaymentContext = {
227
+ // amount: paymentRequest.amount,
228
+ // currency: paymentRequest.currency,
229
+ // country: paymentRequest.country,
230
+ // payment_method: paymentRequest.paymentMethod,
231
+ // customer_id: paymentRequest.customerId,
232
+ // metadata: {
233
+ // service: 'payment-service',
234
+ // timestamp: new Date().toISOString()
235
+ // }
236
+ // };
237
+
238
+ // // Engine automatically routes based on Hyperswitch rules
239
+ // const paymentWorkflow = this.engine.executePaymentsCreatePayment(
240
+ // {
241
+ // amount: paymentRequest.amount,
242
+ // currency: paymentRequest.currency,
243
+ // payment_method: paymentRequest.paymentMethod
244
+ // },
245
+ // context
246
+ // );
247
+
248
+ // return await paymentWorkflow.run({
249
+ // input: {
250
+ // amount: paymentRequest.amount,
251
+ // currency: paymentRequest.currency,
252
+ // payment_method: paymentRequest.paymentMethod
253
+ // }
254
+ // });
255
+ // }
256
+ // }
257
+
258
+ // // Run demo
259
+ // if (require.main === module) {
260
+ // demonstrateHyperswitchRouting().catch(console.error);
261
+ // }
262
+
263
+ // export { engine, PaymentService };
package/jest.config.js ADDED
@@ -0,0 +1,2 @@
1
+ const defineJestConfig = require("../../../define_jest_config")
2
+ module.exports = defineJestConfig()
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@etohq/connector-engine",
3
+ "version": "1.5.1-alpha.4",
4
+ "description": "ETO Framework Core Connector Engine - Universal plugin system for external integrations",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "dependencies": {
8
+ "bignumber.js": "9.1.2"
9
+ },
10
+ "devDependencies": {
11
+ "@mikro-orm/core": "6.4.3",
12
+ "@types/jest": "29.5.14",
13
+ "@types/node": "22.10.5",
14
+ "awilix": "8.0.1",
15
+ "expect-type": "0.20.0",
16
+ "rimraf": "5.0.2",
17
+ "typescript": "5.8.3",
18
+ "tsc-alias": "1.8.6",
19
+ "vite": "5.2.11",
20
+ "@etohq/framework": "1.5.1-alpha.4"
21
+ },
22
+ "peerDependencies": {
23
+ "awilix": "8.0.1",
24
+ "vite": "5.2.11",
25
+ "@etohq/framework": "1.5.1-alpha.4"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "ioredis": {
29
+ "optional": true
30
+ },
31
+ "vite": {
32
+ "optional": true
33
+ }
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./types": {
41
+ "types": "./dist/types/index.d.ts",
42
+ "default": "./dist/types/index.js"
43
+ },
44
+ "./engine": {
45
+ "types": "./dist/engine/index.d.ts",
46
+ "default": "./dist/engine/index.js"
47
+ }
48
+ },
49
+ "scripts": {
50
+ "build": "tsc",
51
+ "dev": "tsc --watch",
52
+ "clean": "rm -rf dist"
53
+ }
54
+ }