| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { Injectable, inject } from '@angular/core';
- import { Observable } from 'rxjs';
- import { RUNTIME_CONFIG } from '../../app/core/config/runtime-config';
- import { CloudApiService } from '../../app/core/services/cloud-api.service';
- export type DataCenterJobStatus = 'pending' | 'processing' | 'completed' | 'partial' | 'failed' | 'cancelled';
- export type DataCenterSyncScope = 'product' | 'reviews';
- export type DataCenterJobEventLevel = 'info' | 'warning' | 'error';
- export interface DataCenterSource {
- id: string;
- workspaceId: string;
- platform: string;
- kind: string;
- status: string;
- lastCheckedAt: string | null;
- credentialStorage: 'environment' | 'external_secret';
- }
- export interface DataCenterImportBatch {
- id: string;
- workspaceId: string;
- platform: string;
- sourceKind: string;
- sourceFile: string | null;
- status: string;
- totalRows: number;
- successRows: number;
- failedRows: number;
- createdAt: string;
- completedAt: string | null;
- }
- export interface DataCenterSyncJob {
- id: string;
- workspaceId: string;
- platform: string;
- status: DataCenterJobStatus;
- scopes: DataCenterSyncScope[];
- productIds: string[];
- progress: number;
- attempts: number;
- maxAttempts: number;
- errorSummary: string | null;
- requestedAt: string;
- startedAt: string | null;
- completedAt: string | null;
- }
- export interface DataCenterJobEvent {
- id: string;
- level: DataCenterJobEventLevel;
- type: string;
- message: string;
- details: Record<string, unknown>;
- createdAt: string;
- }
- export interface DataCenterPage<T> {
- items: T[];
- nextCursor: string | null;
- }
- @Injectable({ providedIn: 'root' })
- export class DataCenterService {
- private readonly cloud = inject(CloudApiService);
- dataSources(workspaceId: string): Observable<{ items: DataCenterSource[] }> {
- return this.cloud.run({ action: 'data-source.list', workspaceId });
- }
- imports(workspaceId: string, limit = 50, cursor = ''): Observable<DataCenterPage<DataCenterImportBatch>> {
- return this.cloud.run({ action: 'import.list', workspaceId, payload: { limit, ...(cursor ? { cursor } : {}) } });
- }
- jobs(workspaceId: string, status: DataCenterJobStatus | '' = '', limit = 50, cursor = ''): Observable<DataCenterPage<DataCenterSyncJob>> {
- return this.cloud.run({ action: 'sync.jobs.list', workspaceId, platform: RUNTIME_CONFIG.domesticPlatform, payload: { limit, ...(status ? { status } : {}), ...(cursor ? { cursor } : {}) } });
- }
- jobEvents(workspaceId: string, jobId: string): Observable<{ items: DataCenterJobEvent[] }> {
- return this.cloud.run({ action: 'sync.job.events', workspaceId, platform: RUNTIME_CONFIG.domesticPlatform, payload: { jobId } });
- }
- enqueueSync(workspaceId: string, productIds: string[], scopes: DataCenterSyncScope[]): Observable<{ job: DataCenterSyncJob }> {
- return this.cloud.run({ action: 'sync.enqueue', workspaceId, platform: RUNTIME_CONFIG.domesticPlatform, payload: { productIds, scopes } });
- }
- retryJob(jobId: string): Observable<{ job: DataCenterSyncJob }> {
- return this.cloud.run({ action: 'sync.job.retry', payload: { jobId } });
- }
- cancelJob(jobId: string): Observable<{ job: DataCenterSyncJob }> {
- return this.cloud.run({ action: 'sync.job.cancel', payload: { jobId } });
- }
- }
|