feat: add digital employee management sync endpoint
This commit is contained in:
@@ -16,6 +16,7 @@ interface DigitalEmployeeSyncConfig {
|
||||
enabled: boolean;
|
||||
endpoint: string | null;
|
||||
clientKey: string | null;
|
||||
authToken: string | null;
|
||||
batchSize: number;
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ export async function flushDigitalEmployeeSyncOutbox(): Promise<DigitalEmployeeS
|
||||
if (syncing) return getDigitalEmployeeSyncStatus();
|
||||
|
||||
const config = resolveSyncConfig();
|
||||
if (!config.enabled || !config.endpoint || !config.clientKey) {
|
||||
if (!config.enabled || !config.endpoint || !config.clientKey || !config.authToken) {
|
||||
lastSyncError = null;
|
||||
return getDigitalEmployeeSyncStatus();
|
||||
}
|
||||
@@ -167,6 +168,7 @@ function resolveSyncConfig(): DigitalEmployeeSyncConfig {
|
||||
enabled: !disabled,
|
||||
endpoint,
|
||||
clientKey: readClientKey(serverHost),
|
||||
authToken: readAuthToken(serverHost),
|
||||
batchSize,
|
||||
};
|
||||
}
|
||||
@@ -190,6 +192,21 @@ function readClientKey(serverHost: string | null): string | null {
|
||||
return typeof globalKey === "string" && globalKey.trim() ? globalKey : null;
|
||||
}
|
||||
|
||||
function readAuthToken(serverHost: string | null): string | null {
|
||||
const oneShotToken = readSetting("auth.token");
|
||||
if (typeof oneShotToken === "string" && oneShotToken.trim()) {
|
||||
return oneShotToken;
|
||||
}
|
||||
if (serverHost) {
|
||||
const domain = serverHost.replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
||||
const domainToken = readSetting(`auth.tokens.${domain}`);
|
||||
if (typeof domainToken === "string" && domainToken.trim()) {
|
||||
return domainToken;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function readPendingOutbox(limit: number): OutboxRow[] {
|
||||
const db = getDb();
|
||||
if (!db) return [];
|
||||
@@ -217,7 +234,7 @@ async function postOutbox(
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${config.clientKey}`,
|
||||
Authorization: `Bearer ${config.authToken}`,
|
||||
"X-Qiming-Client-Key": config.clientKey!,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user