35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
// R-P5 (P5) — reference integration adapter (the only adapter shipped in v1).
|
|
//
|
|
// Demonstrates the IntegrationAdapter contract end-to-end (validate / health /
|
|
// sync) without any external provider. Concrete adapters (Gmail/AirCall/Mollie)
|
|
// follow this shape in their module phases. Registers itself on import (the
|
|
// registry barrel imports this for its side effect).
|
|
|
|
import { registerIntegrationAdapter, type AdapterResult, type AdapterSyncOutcome, type IntegrationAdapter } from "@hivegrid/foundation";
|
|
|
|
type SampleCreds = { baseUrl: string; apiKey: string };
|
|
|
|
const ACTIVE: AdapterResult = { ok: true, health: "active", messageKey: "integrations.health.active" };
|
|
|
|
function validate(creds: SampleCreds): Promise<AdapterResult> {
|
|
if (!creds.baseUrl || !creds.apiKey) {
|
|
return Promise.resolve({ ok: false, health: "broken", messageKey: "integrations.health.missingCredentials" });
|
|
}
|
|
return Promise.resolve(ACTIVE);
|
|
}
|
|
|
|
export const sampleDataSyncAdapter: IntegrationAdapter<SampleCreds> = registerIntegrationAdapter<SampleCreds>({
|
|
key: "sample-data-sync",
|
|
connectionType: "rest_api",
|
|
validateConnection: validate,
|
|
healthCheck: validate,
|
|
sync: (): Promise<AdapterSyncOutcome> =>
|
|
Promise.resolve({
|
|
items: [
|
|
{ entityType: "contact", externalId: "ext-1", operation: "created", status: "synced" },
|
|
{ entityType: "contact", externalId: "ext-2", operation: "updated", status: "synced" },
|
|
],
|
|
summaryKey: "integrations.sync.summary.ok",
|
|
}),
|
|
});
|