/** * WordPress API client — customer-api /wordpress/* endpoints. * * Methods: * - connect(input) POST /wordpress/connect * - disconnect(tenantId) POST /wordpress/disconnect * - triggerSync(tenantId) POST /wordpress/products/sync * - getStatus(tenantId) GET /wordpress/products/status?tenantId= * * All requests use the shared ApiClient (JWT auth). Types are inferred from * @archer/api-interface to keep the wire contract in one place. * * (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) */ import { WORDPRESS_CONNECT, WORDPRESS_DISCONNECT, WORDPRESS_SYNC_TRIGGER, WORDPRESS_SYNC_STATUS, } from '@archer/api-interface/endpoints/customer-api'; import type { WordpressConnectRequest, WordpressConnectResponse, WordpressSyncStatusResponse, } from '@archer/api-interface'; import { ApiClient, apiClient } from '../../ApiClient'; export interface WordpressTriggerSyncResponse { readonly queued: boolean; } export interface WordpressDisconnectResponse { readonly disconnected: boolean; } export class WordpressApi { constructor(private client: ApiClient) {} /** * Persist a WordPress sync binding for a tenant. Idempotent — repeats * overwrite the existing encrypted sync secret server-side. */ async connect(input: WordpressConnectRequest): Promise { return this.client.post(WORDPRESS_CONNECT.path, input); } /** * Soft-disconnect the binding. The row is preserved with deleted_at set. */ async disconnect(tenantId: string): Promise { return this.client.post(WORDPRESS_DISCONNECT.path, { tenantId }); } /** * Enqueue a full-catalog sync job. Returns 202. sync-worker picks it up * and pulls products from the WP plugin via /wp-json/twwim/v1/products. */ async triggerSync(tenantId: string): Promise { return this.client.post(WORDPRESS_SYNC_TRIGGER.path, { tenantId, }); } /** * Poll the current sync status for a tenant. Polled every ~2s by the * WordpressSyncCard while a sync job is in flight. */ async getStatus(tenantId: string): Promise { const qs = new URLSearchParams({ tenantId }).toString(); return this.client.get( `${WORDPRESS_SYNC_STATUS.path}?${qs}`, ); } } export const wordpressApi = new WordpressApi(apiClient);