@eclaw/openclaw-channel 1.1.4 → 1.1.6
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.d.ts +1 -1
- package/dist/client.js +12 -6
- package/dist/gateway.js +5 -1
- package/dist/webhook-registry.js +7 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class EClawClient {
|
|
|
11
11
|
private entityId;
|
|
12
12
|
constructor(config: EClawAccountConfig);
|
|
13
13
|
/** Register callback URL with E-Claw backend */
|
|
14
|
-
registerCallback(callbackUrl: string, callbackToken: string): Promise<RegisterResponse>;
|
|
14
|
+
registerCallback(callbackUrl: string, callbackToken: string, callbackUsername?: string, callbackPassword?: string): Promise<RegisterResponse>;
|
|
15
15
|
/** Bind an entity via channel API (bypasses 6-digit code).
|
|
16
16
|
* If entityId is omitted, the backend auto-selects the first free slot.
|
|
17
17
|
*/
|
package/dist/client.js
CHANGED
|
@@ -14,15 +14,21 @@ export class EClawClient {
|
|
|
14
14
|
this.entityId = config.entityId; // undefined until assigned by bindEntity
|
|
15
15
|
}
|
|
16
16
|
/** Register callback URL with E-Claw backend */
|
|
17
|
-
async registerCallback(callbackUrl, callbackToken) {
|
|
17
|
+
async registerCallback(callbackUrl, callbackToken, callbackUsername, callbackPassword) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
const body = {
|
|
20
|
+
channel_api_key: this.apiKey,
|
|
21
|
+
callback_url: callbackUrl,
|
|
22
|
+
callback_token: callbackToken,
|
|
23
|
+
};
|
|
24
|
+
if (callbackUsername && callbackPassword) {
|
|
25
|
+
body.callback_username = callbackUsername;
|
|
26
|
+
body.callback_password = callbackPassword;
|
|
27
|
+
}
|
|
18
28
|
const res = await fetch(`${this.apiBase}/api/channel/register`, {
|
|
19
29
|
method: 'POST',
|
|
20
30
|
headers: { 'Content-Type': 'application/json' },
|
|
21
|
-
body: JSON.stringify(
|
|
22
|
-
channel_api_key: this.apiKey,
|
|
23
|
-
callback_url: callbackUrl,
|
|
24
|
-
callback_token: callbackToken,
|
|
25
|
-
}),
|
|
31
|
+
body: JSON.stringify(body),
|
|
26
32
|
});
|
|
27
33
|
const data = await res.json();
|
|
28
34
|
if (!data.success) {
|
package/dist/gateway.js
CHANGED
|
@@ -77,8 +77,12 @@ export async function startAccount(ctx) {
|
|
|
77
77
|
registerWebhookToken(callbackToken, accountId, handler);
|
|
78
78
|
console.log(`[E-Claw] Webhook registered at: ${callbackUrl}`);
|
|
79
79
|
try {
|
|
80
|
+
// Detect WEB_PASSWORD / SETUP_PASSWORD for Railway Basic Auth
|
|
81
|
+
const webPassword = process.env.WEB_PASSWORD || process.env.SETUP_PASSWORD;
|
|
82
|
+
const callbackUsername = webPassword ? 'admin' : undefined;
|
|
83
|
+
const callbackPassword = webPassword || undefined;
|
|
80
84
|
// Register callback with E-Claw backend
|
|
81
|
-
const regData = await client.registerCallback(callbackUrl, callbackToken);
|
|
85
|
+
const regData = await client.registerCallback(callbackUrl, callbackToken, callbackUsername, callbackPassword);
|
|
82
86
|
console.log(`[E-Claw] Registered with E-Claw. Device: ${regData.deviceId}, Entities: ${regData.entities.length}`);
|
|
83
87
|
// Bind entity via channel API.
|
|
84
88
|
// /api/channel/bind is idempotent for the same channel account:
|
package/dist/webhook-registry.js
CHANGED
|
@@ -21,13 +21,17 @@ export function unregisterWebhookToken(callbackToken) {
|
|
|
21
21
|
*/
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
23
|
export async function dispatchWebhook(req, res) {
|
|
24
|
+
// Support two auth modes:
|
|
25
|
+
// 1. Standard: Authorization: Bearer <token>
|
|
26
|
+
// 2. Basic Auth gateway (Railway WEB_PASSWORD): X-Callback-Token header
|
|
24
27
|
const authHeader = req.headers?.authorization;
|
|
25
|
-
|
|
28
|
+
const customToken = req.headers?.['x-callback-token'];
|
|
29
|
+
const token = authHeader?.startsWith('Bearer ') ? authHeader.slice(7) : customToken;
|
|
30
|
+
if (!token) {
|
|
26
31
|
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
27
|
-
res.end(JSON.stringify({ error: '
|
|
32
|
+
res.end(JSON.stringify({ error: 'Auth required' }));
|
|
28
33
|
return;
|
|
29
34
|
}
|
|
30
|
-
const token = authHeader.slice(7);
|
|
31
35
|
const entry = registry.get(token);
|
|
32
36
|
if (!entry) {
|
|
33
37
|
// Unknown token — likely a stale push after a server restart
|