//#region src/sync/salesforce-client.ts
/**
* Run a SOQL query and return ALL records, following Salesforce's
* `nextRecordsUrl` so large orgs are imported completely (no LIMIT cap).
*/
async function soqlQueryAll(instanceUrl, token, soql) {
	let url = `${instanceUrl}/services/data/v58.0/query?q=${soql}`;
	const all = [];
	while (url) {
		const res = await fetch(url, { headers: {
			Authorization: `Bearer ${token}`,
			Accept: "application/json"
		} });
		if (!res.ok) throw new Error(`Salesforce API error: ${res.status} ${res.statusText}`);
		const data = await res.json();
		all.push(...data.records);
		url = data.nextRecordsUrl ? `${instanceUrl}${data.nextRecordsUrl}` : null;
	}
	return all;
}
async function fetchSalesforceContacts(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,Name,Email,Account.Website+FROM+Contact");
}
async function fetchSalesforceTasks(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,Subject,Description,ActivityDate,Type,WhoId+FROM+Task");
}
async function fetchSalesforceOpportunities(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,Name,StageName,Amount,CloseDate,Probability,Account.Name,Account.Website+FROM+Opportunity");
}
async function fetchSalesforceLeads(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,Name,Company,Email,Title,Phone,Status,Website+FROM+Lead");
}
async function fetchSalesforceEvents(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,Subject,Description,ActivityDate,StartDateTime,WhoId,WhatId+FROM+Event");
}
async function fetchSalesforceCases(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,CaseNumber,Subject,Description,Status,Priority,Account.Name,AccountId,ContactId,CreatedDate,ClosedDate+FROM+Case");
}
async function fetchSalesforceLineItems(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,OpportunityId,Quantity,UnitPrice,TotalPrice,Description,Product2.Name+FROM+OpportunityLineItem");
}
async function fetchSalesforceNotes(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,Title,Body,ParentId,CreatedDate+FROM+Note");
}
async function fetchSalesforceCampaignMembers(instanceUrl, token) {
	return soqlQueryAll(instanceUrl, token, "SELECT+Id,CampaignId,Campaign.Name,ContactId,LeadId,Status,CreatedDate+FROM+CampaignMember");
}
//#endregion
export { fetchSalesforceCampaignMembers, fetchSalesforceCases, fetchSalesforceContacts, fetchSalesforceEvents, fetchSalesforceLeads, fetchSalesforceLineItems, fetchSalesforceNotes, fetchSalesforceOpportunities, fetchSalesforceTasks };

//# sourceMappingURL=salesforce-client-rhZFa_p5.js.map