refactor: use SkillClient, remove manual auth handling

Replace createEnvConfig/getAccessToken/requestApiWithAutoRefresh
with createSkillClient(). lead-dataset.ts now takes a SkillClient
instead of config+token.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ywkj 2026-03-18 07:39:19 +08:00
parent a46aaf1875
commit 76cffa9f5e
2 changed files with 8 additions and 21 deletions

View File

@ -1,5 +1,5 @@
import type { EmailDraft, ExportResult, ExportedFile, FetchResult } from './types.js'; import type { EmailDraft, ExportResult, ExportedFile, FetchResult } from './types.js';
import { createEnvConfig as createBaseEnvConfig, getAccessToken } from '@clawd/auth-runtime'; import { createSkillClient } from '@clawd/auth-runtime';
import { fetchLeadDataset } from './lead-dataset.js'; import { fetchLeadDataset } from './lead-dataset.js';
import { draftToEml, emlFilename } from './eml.js'; import { draftToEml, emlFilename } from './eml.js';
import { loadR2Config, uploadToR2 } from '@clawd/r2-upload'; import { loadR2Config, uploadToR2 } from '@clawd/r2-upload';
@ -31,16 +31,14 @@ export async function fetchLeads(
}; };
} }
const config = createBaseEnvConfig(); let client;
let accessToken: string;
try { try {
accessToken = await getAccessToken(false, config); client = createSkillClient();
} catch (err) { } catch (err) {
return failedFetch(workflowId, err instanceof Error ? err.message : 'failed to exchange token'); return failedFetch(workflowId, err instanceof Error ? err.message : 'failed to create client');
} }
const { data, error } = await fetchLeadDataset(config, accessToken, workflowId, false); const { data, error } = await fetchLeadDataset(client, workflowId);
if (!data) { if (!data) {
return failedFetch(workflowId, error); return failedFetch(workflowId, error);
} }

View File

@ -1,25 +1,14 @@
import type { LeadDatasetResponse } from './types.js'; import type { LeadDatasetResponse } from './types.js';
import { requestApiWithAutoRefresh } from '@clawd/auth-runtime'; import type { SkillClient } from '@clawd/auth-runtime';
import type { EnvConfig } from '@clawd/auth-runtime';
/** /**
* Fetch lead-dataset from a completed cold-outreach workflow. * Fetch lead-dataset from a completed cold-outreach workflow.
*/ */
export async function fetchLeadDataset( export async function fetchLeadDataset(
config: EnvConfig, client: SkillClient,
accessToken: string,
workflowId: string, workflowId: string,
dryRun: boolean,
): Promise<{ data: LeadDatasetResponse | null; error: string }> { ): Promise<{ data: LeadDatasetResponse | null; error: string }> {
const url = `${config.authBase}/ecom/cold-outreach/${workflowId}/lead-dataset`; const result = await client.get(`/ecom/cold-outreach/${workflowId}/lead-dataset`);
const result = await requestApiWithAutoRefresh(
'GET',
url,
dryRun,
config,
undefined,
accessToken,
);
if (result.status < 200 || result.status >= 300) { if (result.status < 200 || result.status >= 300) {
const msg = parseError(result.body); const msg = parseError(result.body);