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:
parent
a46aaf1875
commit
76cffa9f5e
12
src/index.ts
12
src/index.ts
|
|
@ -1,5 +1,5 @@
|
|||
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 { draftToEml, emlFilename } from './eml.js';
|
||||
import { loadR2Config, uploadToR2 } from '@clawd/r2-upload';
|
||||
|
|
@ -31,16 +31,14 @@ export async function fetchLeads(
|
|||
};
|
||||
}
|
||||
|
||||
const config = createBaseEnvConfig();
|
||||
|
||||
let accessToken: string;
|
||||
let client;
|
||||
try {
|
||||
accessToken = await getAccessToken(false, config);
|
||||
client = createSkillClient();
|
||||
} 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) {
|
||||
return failedFetch(workflowId, error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,14 @@
|
|||
import type { LeadDatasetResponse } from './types.js';
|
||||
import { requestApiWithAutoRefresh } from '@clawd/auth-runtime';
|
||||
import type { EnvConfig } from '@clawd/auth-runtime';
|
||||
import type { SkillClient } from '@clawd/auth-runtime';
|
||||
|
||||
/**
|
||||
* Fetch lead-dataset from a completed cold-outreach workflow.
|
||||
*/
|
||||
export async function fetchLeadDataset(
|
||||
config: EnvConfig,
|
||||
accessToken: string,
|
||||
client: SkillClient,
|
||||
workflowId: string,
|
||||
dryRun: boolean,
|
||||
): Promise<{ data: LeadDatasetResponse | null; error: string }> {
|
||||
const url = `${config.authBase}/ecom/cold-outreach/${workflowId}/lead-dataset`;
|
||||
const result = await requestApiWithAutoRefresh(
|
||||
'GET',
|
||||
url,
|
||||
dryRun,
|
||||
config,
|
||||
undefined,
|
||||
accessToken,
|
||||
);
|
||||
const result = await client.get(`/ecom/cold-outreach/${workflowId}/lead-dataset`);
|
||||
|
||||
if (result.status < 200 || result.status >= 300) {
|
||||
const msg = parseError(result.body);
|
||||
|
|
|
|||
Loading…
Reference in New Issue