@dainprotocol/service-sdk 2.0.78 → 2.0.80
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.
- package/dist/client/api-sdk.d.ts +5 -42
- package/dist/client/api-sdk.js +130 -261
- package/dist/client/api-sdk.js.map +1 -1
- package/dist/client/client-auth.d.ts +1 -69
- package/dist/client/client-auth.js +26 -105
- package/dist/client/client-auth.js.map +1 -1
- package/dist/client/client.d.ts +25 -116
- package/dist/client/client.js +157 -758
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.js +9 -14
- package/dist/client/types.js.map +1 -1
- package/dist/extensions/telegram-oauth.d.ts +6 -2
- package/dist/extensions/telegram-oauth.js +31 -333
- package/dist/extensions/telegram-oauth.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -26
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/lib/convertToVercelTool.d.ts +11 -3
- package/dist/lib/convertToVercelTool.js +0 -1
- package/dist/lib/convertToVercelTool.js.map +1 -1
- package/dist/lib/payments/index.d.ts +14 -23
- package/dist/lib/payments/index.js +33 -47
- package/dist/lib/payments/index.js.map +1 -1
- package/dist/lib/schemaConversion.d.ts +0 -14
- package/dist/lib/schemaConversion.js +26 -56
- package/dist/lib/schemaConversion.js.map +1 -1
- package/dist/lib/schemaStructure.d.ts +1 -7
- package/dist/lib/schemaStructure.js +26 -57
- package/dist/lib/schemaStructure.js.map +1 -1
- package/dist/plugins/base.d.ts +1 -29
- package/dist/plugins/base.js +1 -33
- package/dist/plugins/base.js.map +1 -1
- package/dist/plugins/citations-plugin.d.ts +6 -81
- package/dist/plugins/citations-plugin.js +46 -161
- package/dist/plugins/citations-plugin.js.map +1 -1
- package/dist/plugins/crypto-plugin.d.ts +18 -123
- package/dist/plugins/crypto-plugin.js +41 -248
- package/dist/plugins/crypto-plugin.js.map +1 -1
- package/dist/plugins/time-plugin.d.ts +8 -90
- package/dist/plugins/time-plugin.js +24 -131
- package/dist/plugins/time-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +5 -36
- package/dist/service/auth.d.ts +1 -49
- package/dist/service/auth.js +21 -99
- package/dist/service/auth.js.map +1 -1
- package/dist/service/cloudflareService.js +5 -6
- package/dist/service/cloudflareService.js.map +1 -1
- package/dist/service/core.js +23 -54
- package/dist/service/core.js.map +1 -1
- package/dist/service/denoService.js +14 -18
- package/dist/service/denoService.js.map +1 -1
- package/dist/service/nextService.d.ts +7 -10
- package/dist/service/nextService.js +18 -65
- package/dist/service/nextService.js.map +1 -1
- package/dist/service/nodeService.d.ts +1 -1
- package/dist/service/nodeService.js +18 -30
- package/dist/service/nodeService.js.map +1 -1
- package/dist/service/processes.d.ts +34 -36
- package/dist/service/processes.js +133 -285
- package/dist/service/processes.js.map +1 -1
- package/dist/service/server.d.ts +2 -9
- package/dist/service/server.js +164 -430
- package/dist/service/server.js.map +1 -1
- package/dist/service/webhooks.d.ts +15 -172
- package/dist/service/webhooks.js +52 -184
- package/dist/service/webhooks.js.map +1 -1
- package/package.json +1 -1
|
@@ -47,26 +47,27 @@ class TelegramOAuth {
|
|
|
47
47
|
return data ? JSON.parse(data) : null;
|
|
48
48
|
}
|
|
49
49
|
async setSession(sessionId, session) {
|
|
50
|
-
// Create a clean copy of the session without circular references
|
|
51
50
|
const cleanSession = {
|
|
52
51
|
...session,
|
|
53
|
-
wsConnection: undefined,
|
|
54
|
-
telegramClient: undefined,
|
|
55
|
-
currentPromiseResolve: undefined,
|
|
52
|
+
wsConnection: undefined,
|
|
53
|
+
telegramClient: undefined,
|
|
54
|
+
currentPromiseResolve: undefined,
|
|
56
55
|
};
|
|
57
|
-
await this.redis.set(`session:${sessionId}`, JSON.stringify(cleanSession), "EX", 1800
|
|
58
|
-
);
|
|
56
|
+
await this.redis.set(`session:${sessionId}`, JSON.stringify(cleanSession), "EX", 1800);
|
|
59
57
|
}
|
|
60
58
|
async getToken(code) {
|
|
61
59
|
return await this.redis.get(`token:${code}`);
|
|
62
60
|
}
|
|
63
61
|
async setToken(code, sessionString) {
|
|
64
|
-
await this.redis.set(`token:${code}`, sessionString, "EX", 3600
|
|
65
|
-
);
|
|
62
|
+
await this.redis.set(`token:${code}`, sessionString, "EX", 3600);
|
|
66
63
|
}
|
|
67
64
|
async deleteToken(code) {
|
|
68
65
|
await this.redis.del(`token:${code}`);
|
|
69
66
|
}
|
|
67
|
+
sendError(ws, error) {
|
|
68
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
69
|
+
ws.send(JSON.stringify({ type: "error", message }));
|
|
70
|
+
}
|
|
70
71
|
setupWebSocketServer() {
|
|
71
72
|
this.wss.on("connection", async (ws, req) => {
|
|
72
73
|
const url = new URL(req.url, `ws://${req.headers.host}`);
|
|
@@ -81,22 +82,17 @@ class TelegramOAuth {
|
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
84
|
session.wsConnection = ws;
|
|
84
|
-
|
|
85
|
-
let currentSession = session;
|
|
85
|
+
const currentSession = session;
|
|
86
86
|
ws.on("message", async (message) => {
|
|
87
87
|
try {
|
|
88
88
|
const data = JSON.parse(message.toString());
|
|
89
89
|
if (data.type === "input" && currentSession.currentPromiseResolve) {
|
|
90
|
-
// Use the in-memory session instead of fetching from Redis
|
|
91
90
|
currentSession.currentPromiseResolve(data.value);
|
|
92
91
|
currentSession.currentPromiseResolve = undefined;
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
catch (error) {
|
|
96
|
-
|
|
97
|
-
type: "error",
|
|
98
|
-
message: error.message,
|
|
99
|
-
}));
|
|
95
|
+
this.sendError(ws, error);
|
|
100
96
|
}
|
|
101
97
|
});
|
|
102
98
|
try {
|
|
@@ -123,10 +119,7 @@ class TelegramOAuth {
|
|
|
123
119
|
return await this.promptUser(currentSession, "Please enter the code you received:");
|
|
124
120
|
},
|
|
125
121
|
onError: (err) => {
|
|
126
|
-
|
|
127
|
-
type: "error",
|
|
128
|
-
message: err.message,
|
|
129
|
-
}));
|
|
122
|
+
this.sendError(ws, err);
|
|
130
123
|
throw err;
|
|
131
124
|
},
|
|
132
125
|
});
|
|
@@ -135,321 +128,35 @@ class TelegramOAuth {
|
|
|
135
128
|
await this.setToken(token, sessionString);
|
|
136
129
|
currentSession.status = "completed";
|
|
137
130
|
await this.setSession(sessionId, currentSession);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
redirectUri: `${currentSession.redirectUri}?code=${token}&state=${currentSession.state}`,
|
|
141
|
-
}));
|
|
131
|
+
const redirectUri = `${currentSession.redirectUri}?code=${token}&state=${currentSession.state}`;
|
|
132
|
+
ws.send(JSON.stringify({ type: "success", redirectUri }));
|
|
142
133
|
}
|
|
143
134
|
catch (error) {
|
|
144
|
-
|
|
145
|
-
type: "error",
|
|
146
|
-
message: error.message,
|
|
147
|
-
}));
|
|
135
|
+
this.sendError(ws, error);
|
|
148
136
|
ws.close();
|
|
149
137
|
}
|
|
150
138
|
});
|
|
151
139
|
}
|
|
152
140
|
async promptUser(session, message) {
|
|
153
141
|
return new Promise((resolve) => {
|
|
154
|
-
if (session.wsConnection?.readyState
|
|
155
|
-
session.currentPromiseResolve = resolve;
|
|
156
|
-
session.wsConnection.send(JSON.stringify({
|
|
157
|
-
type: "prompt",
|
|
158
|
-
message,
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
142
|
+
if (session.wsConnection?.readyState !== ws_1.default.OPEN) {
|
|
162
143
|
resolve("");
|
|
144
|
+
return;
|
|
163
145
|
}
|
|
146
|
+
session.currentPromiseResolve = resolve;
|
|
147
|
+
session.wsConnection.send(JSON.stringify({ type: "prompt", message }));
|
|
164
148
|
});
|
|
165
149
|
}
|
|
166
150
|
connect(app, server) {
|
|
167
151
|
app.get("/addons/telegram-oauth/auth.html", (c) => {
|
|
168
|
-
return c.html(
|
|
169
|
-
<!DOCTYPE html>
|
|
170
|
-
<html>
|
|
171
|
-
<head>
|
|
172
|
-
<title>Telegram OAuth</title>
|
|
173
|
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/css/intlTelInput.css">
|
|
174
|
-
<style>
|
|
175
|
-
body {
|
|
176
|
-
background-color: #f3f4f6;
|
|
177
|
-
height: 100vh;
|
|
178
|
-
margin: 0;
|
|
179
|
-
display: flex;
|
|
180
|
-
align-items: center;
|
|
181
|
-
justify-content: center;
|
|
182
|
-
font-family: system-ui, -apple-system, sans-serif;
|
|
183
|
-
}
|
|
184
|
-
.container {
|
|
185
|
-
background-color: white;
|
|
186
|
-
padding: 2rem;
|
|
187
|
-
border-radius: 0.5rem;
|
|
188
|
-
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
|
189
|
-
width: 24rem;
|
|
190
|
-
}
|
|
191
|
-
.logo-container {
|
|
192
|
-
display: flex;
|
|
193
|
-
flex-direction: column;
|
|
194
|
-
align-items: center;
|
|
195
|
-
margin-bottom: 1.5rem;
|
|
196
|
-
}
|
|
197
|
-
.logo {
|
|
198
|
-
width: 4rem;
|
|
199
|
-
height: 4rem;
|
|
200
|
-
margin-bottom: 1rem;
|
|
201
|
-
}
|
|
202
|
-
.title {
|
|
203
|
-
font-size: 1.5rem;
|
|
204
|
-
font-weight: bold;
|
|
205
|
-
color: #1f2937;
|
|
206
|
-
margin-bottom: 0.5rem;
|
|
207
|
-
}
|
|
208
|
-
.subtitle {
|
|
209
|
-
font-size: 1rem;
|
|
210
|
-
color: #6b7280;
|
|
211
|
-
text-align: center;
|
|
212
|
-
margin-bottom: 1.5rem;
|
|
213
|
-
}
|
|
214
|
-
.input {
|
|
215
|
-
width: 100%;
|
|
216
|
-
padding: 0.75rem 1rem;
|
|
217
|
-
border: 1px solid #e5e7eb;
|
|
218
|
-
border-radius: 0.5rem;
|
|
219
|
-
margin-bottom: 1rem;
|
|
220
|
-
box-sizing: border-box;
|
|
221
|
-
font-size: 1rem;
|
|
222
|
-
}
|
|
223
|
-
.button {
|
|
224
|
-
width: 100%;
|
|
225
|
-
padding: 0.75rem 1rem;
|
|
226
|
-
background-color: #3b82f6;
|
|
227
|
-
color: white;
|
|
228
|
-
border: none;
|
|
229
|
-
border-radius: 0.5rem;
|
|
230
|
-
cursor: pointer;
|
|
231
|
-
transition: background-color 150ms;
|
|
232
|
-
font-size: 1rem;
|
|
233
|
-
font-weight: 500;
|
|
234
|
-
}
|
|
235
|
-
.button:hover {
|
|
236
|
-
background-color: #2563eb;
|
|
237
|
-
}
|
|
238
|
-
.status {
|
|
239
|
-
margin-top: 1rem;
|
|
240
|
-
text-align: center;
|
|
241
|
-
font-size: 0.875rem;
|
|
242
|
-
color: #4b5563;
|
|
243
|
-
}
|
|
244
|
-
.step {
|
|
245
|
-
display: none;
|
|
246
|
-
}
|
|
247
|
-
.step.active {
|
|
248
|
-
display: block;
|
|
249
|
-
}
|
|
250
|
-
.error {
|
|
251
|
-
color: #dc2626;
|
|
252
|
-
margin-top: 0.5rem;
|
|
253
|
-
text-align: center;
|
|
254
|
-
font-size: 0.875rem;
|
|
255
|
-
}
|
|
256
|
-
.loading {
|
|
257
|
-
display: inline-block;
|
|
258
|
-
width: 1rem;
|
|
259
|
-
height: 1rem;
|
|
260
|
-
border: 2px solid #e5e7eb;
|
|
261
|
-
border-radius: 50%;
|
|
262
|
-
border-top-color: #3b82f6;
|
|
263
|
-
animation: spin 1s linear infinite;
|
|
264
|
-
margin-right: 0.5rem;
|
|
265
|
-
}
|
|
266
|
-
@keyframes spin {
|
|
267
|
-
to { transform: rotate(360deg); }
|
|
268
|
-
}
|
|
269
|
-
.iti {
|
|
270
|
-
width: 100%;
|
|
271
|
-
margin-bottom: 1rem;
|
|
272
|
-
}
|
|
273
|
-
.iti__flag {
|
|
274
|
-
background-image: url("https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/img/flags.png");
|
|
275
|
-
}
|
|
276
|
-
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
|
|
277
|
-
.iti__flag {
|
|
278
|
-
background-image: url("https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/img/flags@2x.png");
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
</style>
|
|
282
|
-
</head>
|
|
283
|
-
<body>
|
|
284
|
-
<div class="container">
|
|
285
|
-
<div class="logo-container">
|
|
286
|
-
<img src="https://telegram.org/img/t_logo.svg" alt="Telegram Logo" class="logo">
|
|
287
|
-
<h2 class="title">Telegram Authentication</h2>
|
|
288
|
-
</div>
|
|
289
|
-
|
|
290
|
-
<div id="connecting-step" class="step active">
|
|
291
|
-
<p class="subtitle">Connecting to Telegram...</p>
|
|
292
|
-
<div class="status">
|
|
293
|
-
<span class="loading"></span>
|
|
294
|
-
Establishing secure connection
|
|
295
|
-
</div>
|
|
296
|
-
</div>
|
|
297
|
-
|
|
298
|
-
<div id="phone-step" class="step">
|
|
299
|
-
<p class="subtitle">Enter your phone number to continue</p>
|
|
300
|
-
<input type="tel" id="phone-input" class="input" placeholder="Enter phone number">
|
|
301
|
-
<button id="phone-submit" class="button">Continue</button>
|
|
302
|
-
<div id="phone-error" class="error"></div>
|
|
303
|
-
</div>
|
|
304
|
-
|
|
305
|
-
<div id="code-step" class="step">
|
|
306
|
-
<p class="subtitle">Enter the code sent to your device</p>
|
|
307
|
-
<input type="text" id="code-input" class="input" placeholder="Enter code">
|
|
308
|
-
<button id="code-submit" class="button">Verify Code</button>
|
|
309
|
-
<div id="code-error" class="error"></div>
|
|
310
|
-
</div>
|
|
311
|
-
|
|
312
|
-
<div id="password-step" class="step">
|
|
313
|
-
<p class="subtitle">Enter your 2FA password</p>
|
|
314
|
-
<input type="password" id="password-input" class="input" placeholder="Enter password">
|
|
315
|
-
<button id="password-submit" class="button">Sign In</button>
|
|
316
|
-
<div id="password-error" class="error"></div>
|
|
317
|
-
</div>
|
|
318
|
-
|
|
319
|
-
<div id="success-step" class="step">
|
|
320
|
-
<p class="subtitle">Authentication successful!</p>
|
|
321
|
-
<div class="status">Redirecting you...</div>
|
|
322
|
-
</div>
|
|
323
|
-
</div>
|
|
324
|
-
|
|
325
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/intlTelInput.min.js"></script>
|
|
326
|
-
<script>
|
|
327
|
-
const sessionId = new URLSearchParams(window.location.search).get('session');
|
|
328
|
-
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
329
|
-
const wsPath = window.location.pathname.replace('/auth.html', '/ws');
|
|
330
|
-
const wsUrl = wsProtocol + '//' + window.location.host + wsPath + '?session=' + sessionId;
|
|
331
|
-
console.log('Connecting to WebSocket:', wsUrl);
|
|
332
|
-
const ws = new WebSocket(wsUrl);
|
|
333
|
-
|
|
334
|
-
ws.onerror = (error) => {
|
|
335
|
-
console.error('WebSocket error:', error);
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
ws.onopen = () => {
|
|
339
|
-
console.log('WebSocket connected');
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
const steps = ['connecting-step', 'phone-step', 'code-step', 'password-step', 'success-step'];
|
|
343
|
-
let currentInput = null;
|
|
344
|
-
let currentSubmit = null;
|
|
345
|
-
let currentError = null;
|
|
346
|
-
|
|
347
|
-
function showStep(stepId) {
|
|
348
|
-
steps.forEach(step => {
|
|
349
|
-
document.getElementById(step).classList.remove('active');
|
|
350
|
-
});
|
|
351
|
-
document.getElementById(stepId).classList.add('active');
|
|
352
|
-
|
|
353
|
-
// Set current input and submit elements
|
|
354
|
-
currentInput = document.getElementById(stepId.replace('-step', '-input'));
|
|
355
|
-
currentSubmit = document.getElementById(stepId.replace('-step', '-submit'));
|
|
356
|
-
currentError = document.getElementById(stepId.replace('-step', '-error'));
|
|
357
|
-
|
|
358
|
-
if (currentInput) {
|
|
359
|
-
currentInput.focus();
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function handleSubmit() {
|
|
364
|
-
if (currentInput && ws) {
|
|
365
|
-
let inputValue = currentInput.value.trim();
|
|
366
|
-
|
|
367
|
-
// If this is the phone input, format it properly
|
|
368
|
-
if (currentInput.id === 'phone-input') {
|
|
369
|
-
if (!iti.isValidNumber()) {
|
|
370
|
-
currentError.textContent = 'Please enter a valid phone number';
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
inputValue = iti.getNumber(); // This will return the full number with country code
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (inputValue) {
|
|
377
|
-
currentError.textContent = '';
|
|
378
|
-
ws.send(JSON.stringify({ type: 'input', value: inputValue }));
|
|
379
|
-
currentInput.value = '';
|
|
380
|
-
currentSubmit.disabled = true;
|
|
381
|
-
currentSubmit.innerHTML = '<span class="loading"></span>Processing...';
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
ws.onmessage = (event) => {
|
|
387
|
-
const data = JSON.parse(event.data);
|
|
388
|
-
console.log('Received:', data);
|
|
389
|
-
|
|
390
|
-
if (data.type === 'error') {
|
|
391
|
-
if (currentError) {
|
|
392
|
-
currentError.textContent = data.message;
|
|
393
|
-
currentSubmit.disabled = false;
|
|
394
|
-
currentSubmit.textContent = currentSubmit.originalText || 'Submit';
|
|
395
|
-
}
|
|
396
|
-
} else if (data.type === 'success') {
|
|
397
|
-
showStep('success-step');
|
|
398
|
-
setTimeout(() => {
|
|
399
|
-
window.location.href = data.redirectUri;
|
|
400
|
-
}, 1500);
|
|
401
|
-
} else if (data.type === 'prompt') {
|
|
402
|
-
if (data.message.includes('phone')) {
|
|
403
|
-
showStep('phone-step');
|
|
404
|
-
} else if (data.message.includes('code')) {
|
|
405
|
-
showStep('code-step');
|
|
406
|
-
} else if (data.message.includes('password')) {
|
|
407
|
-
showStep('password-step');
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
// Add event listeners for all submit buttons
|
|
413
|
-
steps.forEach(stepId => {
|
|
414
|
-
const submitBtn = document.getElementById(stepId.replace('-step', '-submit'));
|
|
415
|
-
const input = document.getElementById(stepId.replace('-step', '-input'));
|
|
416
|
-
|
|
417
|
-
if (submitBtn && input) {
|
|
418
|
-
submitBtn.originalText = submitBtn.textContent;
|
|
419
|
-
|
|
420
|
-
submitBtn.addEventListener('click', handleSubmit);
|
|
421
|
-
input.addEventListener('keypress', (e) => {
|
|
422
|
-
if (e.key === 'Enter') handleSubmit();
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
// Initialize the phone input
|
|
428
|
-
const phoneInput = document.getElementById('phone-input');
|
|
429
|
-
const iti = window.intlTelInput(phoneInput, {
|
|
430
|
-
utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js",
|
|
431
|
-
separateDialCode: true,
|
|
432
|
-
initialCountry: "auto",
|
|
433
|
-
geoIpLookup: function(callback) {
|
|
434
|
-
fetch("https://ipapi.co/json")
|
|
435
|
-
.then(res => res.json())
|
|
436
|
-
.then(data => callback(data.country_code))
|
|
437
|
-
.catch(() => callback("us"));
|
|
438
|
-
},
|
|
439
|
-
});
|
|
440
|
-
</script>
|
|
441
|
-
</body>
|
|
442
|
-
</html>
|
|
443
|
-
`);
|
|
152
|
+
return c.html("<!DOCTYPE html><html><head><title>Telegram OAuth</title><link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/css/intlTelInput.css\"><style>body{background-color:#f3f4f6;height:100vh;margin:0;display:flex;align-items:center;justify-content:center;font-family:system-ui,-apple-system,sans-serif}.container{background-color:white;padding:2rem;border-radius:0.5rem;box-shadow:0 4px 6px -1px rgba(0,0,0,0.1);width:24rem}.logo-container{display:flex;flex-direction:column;align-items:center;margin-bottom:1.5rem}.logo{width:4rem;height:4rem;margin-bottom:1rem}.title{font-size:1.5rem;font-weight:bold;color:#1f2937;margin-bottom:0.5rem}.subtitle{font-size:1rem;color:#6b7280;text-align:center;margin-bottom:1.5rem}.input{width:100%;padding:0.75rem 1rem;border:1px solid #e5e7eb;border-radius:0.5rem;margin-bottom:1rem;box-sizing:border-box;font-size:1rem}.button{width:100%;padding:0.75rem 1rem;background-color:#3b82f6;color:white;border:none;border-radius:0.5rem;cursor:pointer;transition:background-color 150ms;font-size:1rem;font-weight:500}.button:hover{background-color:#2563eb}.status{margin-top:1rem;text-align:center;font-size:0.875rem;color:#4b5563}.step{display:none}.step.active{display:block}.error{color:#dc2626;margin-top:0.5rem;text-align:center;font-size:0.875rem}.loading{display:inline-block;width:1rem;height:1rem;border:2px solid #e5e7eb;border-radius:50%;border-top-color:#3b82f6;animation:spin 1s linear infinite;margin-right:0.5rem}@keyframes spin{to{transform:rotate(360deg)}}.iti{width:100%;margin-bottom:1rem}.iti__flag{background-image:url(\"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/img/flags.png\")}@media (-webkit-min-device-pixel-ratio:2),(min-resolution:192dpi){.iti__flag{background-image:url(\"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/img/flags@2x.png\")}}</style></head><body><div class=\"container\"><div class=\"logo-container\"><img src=\"https://telegram.org/img/t_logo.svg\" alt=\"Telegram Logo\" class=\"logo\"><h2 class=\"title\">Telegram Authentication</h2></div><div id=\"connecting-step\" class=\"step active\"><p class=\"subtitle\">Connecting to Telegram...</p><div class=\"status\"><span class=\"loading\"></span>Establishing secure connection</div></div><div id=\"phone-step\" class=\"step\"><p class=\"subtitle\">Enter your phone number to continue</p><input type=\"tel\" id=\"phone-input\" class=\"input\" placeholder=\"Enter phone number\"><button id=\"phone-submit\" class=\"button\">Continue</button><div id=\"phone-error\" class=\"error\"></div></div><div id=\"code-step\" class=\"step\"><p class=\"subtitle\">Enter the code sent to your device</p><input type=\"text\" id=\"code-input\" class=\"input\" placeholder=\"Enter code\"><button id=\"code-submit\" class=\"button\">Verify Code</button><div id=\"code-error\" class=\"error\"></div></div><div id=\"password-step\" class=\"step\"><p class=\"subtitle\">Enter your 2FA password</p><input type=\"password\" id=\"password-input\" class=\"input\" placeholder=\"Enter password\"><button id=\"password-submit\" class=\"button\">Sign In</button><div id=\"password-error\" class=\"error\"></div></div><div id=\"success-step\" class=\"step\"><p class=\"subtitle\">Authentication successful!</p><div class=\"status\">Redirecting you...</div></div></div><script src=\"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/intlTelInput.min.js\"></script><script>const sessionId=new URLSearchParams(window.location.search).get('session');const wsProtocol=window.location.protocol==='https:'?'wss:':'ws:';const wsPath=window.location.pathname.replace('/auth.html','/ws');const wsUrl=wsProtocol+'//'+window.location.host+wsPath+'?session='+sessionId;console.log('Connecting to WebSocket:',wsUrl);const ws=new WebSocket(wsUrl);ws.onerror=(error)=>{console.error('WebSocket error:',error)};ws.onopen=()=>{console.log('WebSocket connected')};const steps=['connecting-step','phone-step','code-step','password-step','success-step'];let currentInput=null;let currentSubmit=null;let currentError=null;function showStep(stepId){steps.forEach(step=>{document.getElementById(step).classList.remove('active')});document.getElementById(stepId).classList.add('active');currentInput=document.getElementById(stepId.replace('-step','-input'));currentSubmit=document.getElementById(stepId.replace('-step','-submit'));currentError=document.getElementById(stepId.replace('-step','-error'));if(currentInput){currentInput.focus()}}function handleSubmit(){if(currentInput&&ws){let inputValue=currentInput.value.trim();if(currentInput.id==='phone-input'){if(!iti.isValidNumber()){currentError.textContent='Please enter a valid phone number';return}inputValue=iti.getNumber()}if(inputValue){currentError.textContent='';ws.send(JSON.stringify({type:'input',value:inputValue}));currentInput.value='';currentSubmit.disabled=true;currentSubmit.innerHTML='<span class=\"loading\"></span>Processing...'}}}ws.onmessage=(event)=>{const data=JSON.parse(event.data);console.log('Received:',data);if(data.type==='error'){if(currentError){currentError.textContent=data.message;currentSubmit.disabled=false;currentSubmit.textContent=currentSubmit.originalText||'Submit'}}else if(data.type==='success'){showStep('success-step');setTimeout(()=>{window.location.href=data.redirectUri},1500)}else if(data.type==='prompt'){if(data.message.includes('phone')){showStep('phone-step')}else if(data.message.includes('code')){showStep('code-step')}else if(data.message.includes('password')){showStep('password-step')}}};steps.forEach(stepId=>{const submitBtn=document.getElementById(stepId.replace('-step','-submit'));const input=document.getElementById(stepId.replace('-step','-input'));if(submitBtn&&input){submitBtn.originalText=submitBtn.textContent;submitBtn.addEventListener('click',handleSubmit);input.addEventListener('keypress',(e)=>{if(e.key==='Enter')handleSubmit()})}});const phoneInput=document.getElementById('phone-input');const iti=window.intlTelInput(phoneInput,{utilsScript:\"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js\",separateDialCode:true,initialCountry:\"auto\",geoIpLookup:function(callback){fetch(\"https://ipapi.co/json\").then(res=>res.json()).then(data=>callback(data.country_code)).catch(()=>callback(\"us\"))}});</script></body></html>");
|
|
444
153
|
});
|
|
445
154
|
app.get("/addons/telegram-oauth/oauth/authorize", async (c) => {
|
|
446
155
|
const { client_id, redirect_uri, state } = c.req.query();
|
|
447
156
|
if (!client_id || !redirect_uri) {
|
|
448
157
|
return c.json({ error: "Missing required parameters" }, 400);
|
|
449
158
|
}
|
|
450
|
-
|
|
451
|
-
const isValidClient = await this.validateClient(client_id);
|
|
452
|
-
if (!isValidClient) {
|
|
159
|
+
if (!await this.validateClient(client_id)) {
|
|
453
160
|
return c.json({ error: "Invalid client_id" }, 401);
|
|
454
161
|
}
|
|
455
162
|
const sessionId = crypto.randomBytes(16).toString("hex");
|
|
@@ -463,7 +170,7 @@ class TelegramOAuth {
|
|
|
463
170
|
expiresAt: new Date(Date.now() + 30 * 60 * 1000),
|
|
464
171
|
};
|
|
465
172
|
await this.setSession(sessionId, session);
|
|
466
|
-
return c.redirect(this.baseUrl
|
|
173
|
+
return c.redirect(`${this.baseUrl}/addons/telegram-oauth/auth.html?session=${sessionId}`);
|
|
467
174
|
});
|
|
468
175
|
app.post("/addons/telegram-oauth/oauth/token", async (c) => {
|
|
469
176
|
const body = await c.req.parseBody();
|
|
@@ -474,9 +181,7 @@ class TelegramOAuth {
|
|
|
474
181
|
if (grant_type !== "authorization_code") {
|
|
475
182
|
return c.json({ error: "Invalid grant type" }, 400);
|
|
476
183
|
}
|
|
477
|
-
|
|
478
|
-
const isValidClient = await this.validateClient(client_id, client_secret);
|
|
479
|
-
if (!isValidClient) {
|
|
184
|
+
if (!await this.validateClient(client_id, client_secret)) {
|
|
480
185
|
return c.json({ error: "Invalid client credentials" }, 401);
|
|
481
186
|
}
|
|
482
187
|
const sessionString = await this.getToken(code);
|
|
@@ -488,27 +193,20 @@ class TelegramOAuth {
|
|
|
488
193
|
access_token: sessionString,
|
|
489
194
|
token_type: "Bearer",
|
|
490
195
|
expires_in: 3600,
|
|
491
|
-
scope: "",
|
|
492
|
-
refresh_token: null
|
|
196
|
+
scope: "",
|
|
197
|
+
refresh_token: null,
|
|
493
198
|
});
|
|
494
199
|
});
|
|
495
|
-
app.get("/addons/telegram-oauth/ws", (c) =>
|
|
496
|
-
// This route won't actually handle the WebSocket connection
|
|
497
|
-
// It's just here to ensure the path exists
|
|
498
|
-
return c.body(null);
|
|
499
|
-
});
|
|
500
|
-
// Setup WebSocket upgrade handling
|
|
200
|
+
app.get("/addons/telegram-oauth/ws", (c) => c.body(null));
|
|
501
201
|
server.on("upgrade", (req, socket, head) => {
|
|
502
202
|
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
503
|
-
|
|
504
|
-
if (url.pathname.endsWith('/addons/telegram-oauth/ws')) {
|
|
203
|
+
if (url.pathname.endsWith("/addons/telegram-oauth/ws")) {
|
|
505
204
|
this.wss.handleUpgrade(req, socket, head, (ws) => {
|
|
506
205
|
this.wss.emit("connection", ws, req);
|
|
507
206
|
});
|
|
508
207
|
}
|
|
509
208
|
});
|
|
510
209
|
}
|
|
511
|
-
// Get client credentials - useful for applications
|
|
512
210
|
getClientCredentials() {
|
|
513
211
|
return {
|
|
514
212
|
clientId: TelegramOAuth.generateClientId(this.config.apiId, this.config.apiHash),
|
|
@@ -516,13 +214,13 @@ class TelegramOAuth {
|
|
|
516
214
|
};
|
|
517
215
|
}
|
|
518
216
|
getOAuth2ProviderConfig(options) {
|
|
519
|
-
const
|
|
217
|
+
const { clientId, clientSecret } = this.getClientCredentials();
|
|
520
218
|
return {
|
|
521
|
-
clientId
|
|
522
|
-
clientSecret
|
|
219
|
+
clientId,
|
|
220
|
+
clientSecret,
|
|
523
221
|
authorizationUrl: `${this.baseUrl}/addons/telegram-oauth/oauth/authorize`,
|
|
524
222
|
tokenUrl: `${this.baseUrl}/addons/telegram-oauth/oauth/token`,
|
|
525
|
-
scopes: [],
|
|
223
|
+
scopes: [],
|
|
526
224
|
reason: options?.reason || "Required to access your Telegram account",
|
|
527
225
|
requiredTools: options?.requiredTools || [],
|
|
528
226
|
onSuccess: options?.onSuccess,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegram-oauth.js","sourceRoot":"","sources":["../../src/extensions/telegram-oauth.ts"],"names":[],"mappings":";;;;AAEA,uCAA0C;AAC1C,gDAAkD;AAClD,uDAAiC;AACjC,oDAA2B;
|
|
1
|
+
{"version":3,"file":"telegram-oauth.js","sourceRoot":"","sources":["../../src/extensions/telegram-oauth.ts"],"names":[],"mappings":";;;;AAEA,uCAA0C;AAC1C,gDAAkD;AAClD,uDAAiC;AACjC,oDAA2B;AAmC3B,MAAa,aAAa;IAChB,MAAM,CAAsB;IAC5B,GAAG,CAAmB;IACtB,KAAK,CAAQ;IACb,OAAO,CAAS;IAExB,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,GAAG,GAAG,IAAI,YAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC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,aAAa,IAAI,EAAE;YAC3C,SAAS,EAAE,OAAO,EAAE,SAAS;SAC9B,CAAC;IACJ,CAAC;CACF;AA1SD,sCA0SC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export * from './service';
|
|
2
2
|
export * as DAINServiceClient from "./client";
|
|
3
|
-
export { createTool, createService, createToolbox, CoreUtils, createWebhookTriggerRegistry, createSimpleTrigger, createTypedTrigger, WebhookTriggerRegistry, type WebhookTrigger, type WebhookTriggerDefinition, type WebhookProcessResult, forwardTriggerToAutomationCore, type TriggerForwardingConfig, type TriggerForwardResult, ActionableToolBaseSchema, ActionSchema, MetadataSchema, extendActionableSchema, buildActionableTool, validateActionableSchema, type ActionableToolInput, type Action, type AutomationMetadata, } from './service';
|
|
4
3
|
export * as DAINPlugins from "./plugins";
|
|
4
|
+
export { type BlockchainNetwork, type WalletInfo, type UnsignedTransaction, type TransactionSignatureRequest, type CryptoPluginConfig, type CryptoPluginInput, type CryptoPluginOutput, CryptoPlugin, type DainPlugin, type PluginData, BaseDainPlugin, TimePlugin, CitationsPlugin, } from "./plugins";
|
|
5
5
|
export * as DAINServicePayments from "./lib/payments";
|
|
6
6
|
export { jsonToZod, zodToJson, getZodTypeName, type SerializedSchema, } from "./lib/schemaConversion";
|
|
7
|
-
export { ToolInterfaceType, KnowledgeSearchInterface, TOOL_INTERFACES, CitationSchema, ContentSchema, type ToolInterface, type InterfaceInput, type InterfaceOutput, } from "./interfaces";
|
|
7
|
+
export { ToolInterfaceType, KnowledgeSearchInterface, TOOL_INTERFACES, CitationSchema, ContentSchema, type ToolInterface, type InterfaceInput, type InterfaceOutput, type Citation, type Content, } from "./interfaces";
|
|
8
8
|
export { createToolWithInterface } from "./service/core";
|
|
9
9
|
export { OAuth2Client, StorageAdapter, StoredToken, OAuth2Token, TokenQuery, SaveTokenInput, UpdateTokenInput, AuthorizationState, UserProfile, OAuth2Config, AutoRefreshOptions, InMemoryStorageAdapter } from "@dainprotocol/oauth2-token-manager";
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryStorageAdapter = exports.OAuth2Client = exports.createToolWithInterface = exports.ContentSchema = exports.CitationSchema = exports.TOOL_INTERFACES = exports.KnowledgeSearchInterface = exports.ToolInterfaceType = exports.getZodTypeName = exports.zodToJson = exports.jsonToZod = exports.DAINServicePayments = exports.
|
|
3
|
+
exports.InMemoryStorageAdapter = exports.OAuth2Client = exports.createToolWithInterface = exports.ContentSchema = exports.CitationSchema = exports.TOOL_INTERFACES = exports.KnowledgeSearchInterface = exports.ToolInterfaceType = exports.getZodTypeName = exports.zodToJson = exports.jsonToZod = exports.DAINServicePayments = exports.CitationsPlugin = exports.TimePlugin = exports.BaseDainPlugin = exports.CryptoPlugin = exports.DAINPlugins = exports.DAINServiceClient = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
// Core service exports (all types, functions, and utilities)
|
|
5
6
|
tslib_1.__exportStar(require("./service"), exports);
|
|
6
7
|
exports.DAINServiceClient = tslib_1.__importStar(require("./client"));
|
|
7
|
-
//
|
|
8
|
-
var service_1 = require("./service");
|
|
9
|
-
Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return service_1.createTool; } });
|
|
10
|
-
Object.defineProperty(exports, "createService", { enumerable: true, get: function () { return service_1.createService; } });
|
|
11
|
-
Object.defineProperty(exports, "createToolbox", { enumerable: true, get: function () { return service_1.createToolbox; } });
|
|
12
|
-
Object.defineProperty(exports, "CoreUtils", { enumerable: true, get: function () { return service_1.CoreUtils; } });
|
|
13
|
-
// Webhook triggers
|
|
14
|
-
Object.defineProperty(exports, "createWebhookTriggerRegistry", { enumerable: true, get: function () { return service_1.createWebhookTriggerRegistry; } });
|
|
15
|
-
Object.defineProperty(exports, "createSimpleTrigger", { enumerable: true, get: function () { return service_1.createSimpleTrigger; } });
|
|
16
|
-
Object.defineProperty(exports, "createTypedTrigger", { enumerable: true, get: function () { return service_1.createTypedTrigger; } });
|
|
17
|
-
Object.defineProperty(exports, "WebhookTriggerRegistry", { enumerable: true, get: function () { return service_1.WebhookTriggerRegistry; } });
|
|
18
|
-
// Trigger forwarding
|
|
19
|
-
Object.defineProperty(exports, "forwardTriggerToAutomationCore", { enumerable: true, get: function () { return service_1.forwardTriggerToAutomationCore; } });
|
|
20
|
-
// Actionable tools (standardized schema for tools with supportsUserActions)
|
|
21
|
-
Object.defineProperty(exports, "ActionableToolBaseSchema", { enumerable: true, get: function () { return service_1.ActionableToolBaseSchema; } });
|
|
22
|
-
Object.defineProperty(exports, "ActionSchema", { enumerable: true, get: function () { return service_1.ActionSchema; } });
|
|
23
|
-
Object.defineProperty(exports, "MetadataSchema", { enumerable: true, get: function () { return service_1.MetadataSchema; } });
|
|
24
|
-
Object.defineProperty(exports, "extendActionableSchema", { enumerable: true, get: function () { return service_1.extendActionableSchema; } });
|
|
25
|
-
Object.defineProperty(exports, "buildActionableTool", { enumerable: true, get: function () { return service_1.buildActionableTool; } });
|
|
26
|
-
Object.defineProperty(exports, "validateActionableSchema", { enumerable: true, get: function () { return service_1.validateActionableSchema; } });
|
|
27
|
-
// Export plugins for easy access
|
|
8
|
+
// Plugins namespace and commonly-used direct exports
|
|
28
9
|
exports.DAINPlugins = tslib_1.__importStar(require("./plugins"));
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
var plugins_1 = require("./plugins");
|
|
11
|
+
Object.defineProperty(exports, "CryptoPlugin", { enumerable: true, get: function () { return plugins_1.CryptoPlugin; } });
|
|
12
|
+
Object.defineProperty(exports, "BaseDainPlugin", { enumerable: true, get: function () { return plugins_1.BaseDainPlugin; } });
|
|
13
|
+
// Time plugin
|
|
14
|
+
Object.defineProperty(exports, "TimePlugin", { enumerable: true, get: function () { return plugins_1.TimePlugin; } });
|
|
15
|
+
// Citations plugin
|
|
16
|
+
Object.defineProperty(exports, "CitationsPlugin", { enumerable: true, get: function () { return plugins_1.CitationsPlugin; } });
|
|
17
|
+
// Payments namespace
|
|
32
18
|
exports.DAINServicePayments = tslib_1.__importStar(require("./lib/payments"));
|
|
33
19
|
// Export schema conversion utilities
|
|
34
20
|
var schemaConversion_1 = require("./lib/schemaConversion");
|
|
35
21
|
Object.defineProperty(exports, "jsonToZod", { enumerable: true, get: function () { return schemaConversion_1.jsonToZod; } });
|
|
36
22
|
Object.defineProperty(exports, "zodToJson", { enumerable: true, get: function () { return schemaConversion_1.zodToJson; } });
|
|
37
23
|
Object.defineProperty(exports, "getZodTypeName", { enumerable: true, get: function () { return schemaConversion_1.getZodTypeName; } });
|
|
38
|
-
// Export tool interfaces
|
|
24
|
+
// Export tool interfaces and schemas
|
|
39
25
|
var interfaces_1 = require("./interfaces");
|
|
40
26
|
Object.defineProperty(exports, "ToolInterfaceType", { enumerable: true, get: function () { return interfaces_1.ToolInterfaceType; } });
|
|
41
27
|
Object.defineProperty(exports, "KnowledgeSearchInterface", { enumerable: true, get: function () { return interfaces_1.KnowledgeSearchInterface; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,oDAA0B;AAC1B,sEAA8C;AAE9C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,6DAA6D;AAC7D,oDAA0B;AAC1B,sEAA8C;AAE9C,qDAAqD;AACrD,iEAAyC;AACzC,qCAkBmB;AATjB,uGAAA,YAAY,OAAA;AAIZ,yGAAA,cAAc,OAAA;AACd,cAAc;AACd,qGAAA,UAAU,OAAA;AACV,mBAAmB;AACnB,0GAAA,eAAe,OAAA;AAGjB,qBAAqB;AACrB,8EAAsD;AAEtD,qCAAqC;AACrC,2DAKgC;AAJ9B,6GAAA,SAAS,OAAA;AACT,6GAAA,SAAS,OAAA;AACT,kHAAA,cAAc,OAAA;AAIhB,qCAAqC;AACrC,2CAWsB;AAVpB,+GAAA,iBAAiB,OAAA;AACjB,sHAAA,wBAAwB,OAAA;AACxB,6GAAA,eAAe,OAAA;AACf,4GAAA,cAAc,OAAA;AACd,2GAAA,aAAa,OAAA;AAQf,iCAAiC;AACjC,uCAAyD;AAAhD,+GAAA,uBAAuB,OAAA;AAEhC,6DAA6D;AAC7D,2EAa4C;AAZ1C,oHAAA,YAAY,OAAA;AAWZ,8HAAA,sBAAsB,OAAA"}
|
|
@@ -58,3 +58,5 @@ export declare const TOOL_INTERFACES: {
|
|
|
58
58
|
};
|
|
59
59
|
export type InterfaceInput<T extends ToolInterfaceType> = z.infer<typeof TOOL_INTERFACES[T]['input']>;
|
|
60
60
|
export type InterfaceOutput<T extends ToolInterfaceType> = z.infer<typeof TOOL_INTERFACES[T]['output']>;
|
|
61
|
+
export type Citation = z.infer<typeof CitationSchema>;
|
|
62
|
+
export type Content = z.infer<typeof ContentSchema>;
|