@easyling/sanity-connector 0.0.2-rc.1 → 0.0.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +28 -0
- package/dist-types/actions/bulkTranslate.d.ts +6 -0
- package/dist-types/actions/manageDNTFields.d.ts +11 -0
- package/dist-types/actions/translateDocument.d.ts +6 -0
- package/dist-types/components/RadioWithDefault.d.ts +16 -0
- package/dist-types/components/auth/AuthNavbar.d.ts +17 -0
- package/dist-types/components/auth/AuthStatus.d.ts +26 -0
- package/dist-types/components/auth/AuthStatusWrapper.d.ts +14 -0
- package/dist-types/components/auth/MigrationPrompt.d.ts +19 -0
- package/dist-types/components/auth/MigrationPromptWrapper.d.ts +13 -0
- package/dist-types/components/auth/OAuthCallback.d.ts +19 -0
- package/dist-types/components/auth/index.d.ts +14 -0
- package/dist-types/components/config/LocaleConfigTool.d.ts +16 -0
- package/dist-types/components/config/LocaleConfigToolWrapper.d.ts +12 -0
- package/dist-types/components/config/OAuthConfig.d.ts +25 -0
- package/dist-types/components/config/OAuthConfigWrapper.d.ts +12 -0
- package/dist-types/components/config/PasswordInput.d.ts +13 -0
- package/dist-types/components/config/index.d.ts +8 -0
- package/dist-types/components/config/localeConfigToolDefinition.d.ts +12 -0
- package/dist-types/components/config/oauthConfigToolDefinition.d.ts +12 -0
- package/dist-types/components/dialogs/ConfirmationDialog.d.ts +20 -0
- package/dist-types/components/dialogs/ErrorDialog.d.ts +20 -0
- package/dist-types/components/dialogs/LocaleSelectionDialog.d.ts +40 -0
- package/dist-types/components/dialogs/SuccessDialog.d.ts +18 -0
- package/dist-types/components/dialogs/index.d.ts +11 -0
- package/dist-types/components/dnt/DNTFieldBadge.d.ts +15 -0
- package/dist-types/components/dnt/DNTFieldComponent.d.ts +16 -0
- package/dist-types/components/dnt/DNTFieldInput.d.ts +13 -0
- package/dist-types/components/dnt/index.d.ts +6 -0
- package/dist-types/config/index.d.ts +5 -0
- package/dist-types/config/pluginConfig.d.ts +162 -0
- package/dist-types/index.d.ts +11 -0
- package/dist-types/plugin.d.ts +2 -0
- package/dist-types/services/authStateManager.d.ts +93 -0
- package/dist-types/services/contentExtractor.d.ts +94 -0
- package/dist-types/services/dialogService.d.ts +95 -0
- package/dist-types/services/dntServiceManager.d.ts +43 -0
- package/dist-types/services/dntStorageAdapter.d.ts +72 -0
- package/dist-types/services/documentCreationService.d.ts +138 -0
- package/dist-types/services/localeService.d.ts +159 -0
- package/dist-types/services/localeStorageAdapter.d.ts +41 -0
- package/dist-types/services/oauthConfigStorage.d.ts +45 -0
- package/dist-types/services/oauthService.d.ts +47 -0
- package/dist-types/services/oauthServiceManager.d.ts +188 -0
- package/dist-types/services/tokenStorage.d.ts +53 -0
- package/dist-types/services/translationService.d.ts +373 -0
- package/dist-types/services/unifiedConfigStorage.d.ts +123 -0
- package/dist-types/test-utils.d.ts +8 -0
- package/dist-types/types/dialog.d.ts +106 -0
- package/dist-types/types/dnt.d.ts +83 -0
- package/dist-types/types/index.d.ts +11 -0
- package/dist-types/types/locale.d.ts +115 -0
- package/dist-types/types/oauth.d.ts +89 -0
- package/dist-types/types/pluginConfig.d.ts +44 -0
- package/dist-types/types/translation.d.ts +121 -0
- package/dist-types/utils/htmlFormatter.d.ts +65 -0
- package/dist-types/utils/index.d.ts +14 -0
- package/dist-types/utils/logger.d.ts +104 -0
- package/dist-types/utils/oauthErrorFeedback.d.ts +75 -0
- package/dist-types/utils/oauthLogger.d.ts +175 -0
- package/dist-types/utils/validator.d.ts +66 -0
- package/package.json +3 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the Sanity Translation Plugin
|
|
3
|
+
*/
|
|
4
|
+
export { default } from './plugin';
|
|
5
|
+
export type { LocaleDefinition, LocaleConfig, TranslationRequestPayload, TranslationResponse, TranslatableField, DNTFieldPreference, DNTPreferences, DNTTypeConfig, DNTStorage } from './types';
|
|
6
|
+
export type { UnifiedPluginConfig } from './services/unifiedConfigStorage';
|
|
7
|
+
export { createPluginConfigSchema, pluginConfigSchema } from './config/pluginConfig';
|
|
8
|
+
export { DNTFieldBadge, withDNTBadge, DNTFieldInput } from './components/dnt';
|
|
9
|
+
export { DNTStorageAdapter, LegacyDNTStorageAdapter } from './services/dntStorageAdapter';
|
|
10
|
+
export { UnifiedConfigStorage } from './services/unifiedConfigStorage';
|
|
11
|
+
export { DNTServiceManager, getDNTStorage } from './services/dntServiceManager';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication State Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages the overall authentication state and provides reactive updates
|
|
5
|
+
* to UI components through an observable pattern.
|
|
6
|
+
*
|
|
7
|
+
* Requirements: 6.1, 6.2, 6.3, 6.4, 6.5
|
|
8
|
+
*/
|
|
9
|
+
import { AuthState, AuthStateData } from '../types/oauth';
|
|
10
|
+
import { TokenStorage } from './tokenStorage';
|
|
11
|
+
/**
|
|
12
|
+
* Callback function type for state change subscriptions
|
|
13
|
+
*/
|
|
14
|
+
type StateChangeCallback = (state: AuthStateData) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Authentication State Manager
|
|
17
|
+
*
|
|
18
|
+
* Provides centralized management of authentication state with reactive updates.
|
|
19
|
+
* Uses observable pattern to notify subscribers of state changes.
|
|
20
|
+
*/
|
|
21
|
+
export declare class AuthStateManager {
|
|
22
|
+
private currentState;
|
|
23
|
+
private subscribers;
|
|
24
|
+
private tokenStorage;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new Authentication State Manager
|
|
27
|
+
*
|
|
28
|
+
* Requirements: 6.1, 6.2
|
|
29
|
+
*
|
|
30
|
+
* @param tokenStorage - Token storage service for persistence
|
|
31
|
+
*/
|
|
32
|
+
constructor(tokenStorage: TokenStorage);
|
|
33
|
+
/**
|
|
34
|
+
* Validate state transition
|
|
35
|
+
*
|
|
36
|
+
* Requirements: 6.5
|
|
37
|
+
*
|
|
38
|
+
* @param fromState - Current state
|
|
39
|
+
* @param toState - Target state
|
|
40
|
+
* @returns True if transition is valid
|
|
41
|
+
*/
|
|
42
|
+
private isValidTransition;
|
|
43
|
+
/**
|
|
44
|
+
* Get current authentication state
|
|
45
|
+
*
|
|
46
|
+
* Requirements: 6.1, 6.2
|
|
47
|
+
*
|
|
48
|
+
* @returns Current authentication state data
|
|
49
|
+
*/
|
|
50
|
+
getState(): AuthStateData;
|
|
51
|
+
/**
|
|
52
|
+
* Update authentication state and notify subscribers
|
|
53
|
+
*
|
|
54
|
+
* Requirements: 6.2, 6.5
|
|
55
|
+
*
|
|
56
|
+
* @param state - New authentication state
|
|
57
|
+
* @param data - Additional state data
|
|
58
|
+
* @throws {OAuthError} If state transition is invalid
|
|
59
|
+
*/
|
|
60
|
+
setState(state: AuthState, data?: Partial<AuthStateData>): void;
|
|
61
|
+
/**
|
|
62
|
+
* Notify all subscribers of state change
|
|
63
|
+
*
|
|
64
|
+
* Requirements: 6.2
|
|
65
|
+
*/
|
|
66
|
+
private notifySubscribers;
|
|
67
|
+
/**
|
|
68
|
+
* Subscribe to state changes
|
|
69
|
+
*
|
|
70
|
+
* Requirements: 6.2
|
|
71
|
+
*
|
|
72
|
+
* @param callback - Function to call when state changes
|
|
73
|
+
* @returns Unsubscribe function
|
|
74
|
+
*/
|
|
75
|
+
subscribe(callback: StateChangeCallback): () => void;
|
|
76
|
+
/**
|
|
77
|
+
* Initialize state from stored authentication data
|
|
78
|
+
*
|
|
79
|
+
* Requirements: 6.1, 6.4
|
|
80
|
+
*
|
|
81
|
+
* @returns Promise that resolves when initialization is complete
|
|
82
|
+
*/
|
|
83
|
+
initialize(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Logout and clear all authentication data
|
|
86
|
+
*
|
|
87
|
+
* Requirements: 6.3, 6.4
|
|
88
|
+
*
|
|
89
|
+
* @returns Promise that resolves when logout is complete
|
|
90
|
+
*/
|
|
91
|
+
logout(): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { SanityDocument } from 'sanity';
|
|
2
|
+
export interface DocumentContent {
|
|
3
|
+
documentId: string;
|
|
4
|
+
title: string;
|
|
5
|
+
htmlContent: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ExtendedDocumentContent extends DocumentContent {
|
|
8
|
+
slug?: string;
|
|
9
|
+
/** Fields can be either flat values or TranslatableField objects with value and dnt properties */
|
|
10
|
+
fields?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface ExtractedContent {
|
|
13
|
+
documentId: string;
|
|
14
|
+
documentType: string;
|
|
15
|
+
title: string;
|
|
16
|
+
htmlContent: string;
|
|
17
|
+
extractedAt: Date;
|
|
18
|
+
}
|
|
19
|
+
export declare class ContentExtractor {
|
|
20
|
+
/**
|
|
21
|
+
* Infer the Sanity field type from a value
|
|
22
|
+
*
|
|
23
|
+
* @param value - The field value to inspect
|
|
24
|
+
* @returns The inferred Sanity type string
|
|
25
|
+
*/
|
|
26
|
+
private inferSanityType;
|
|
27
|
+
/**
|
|
28
|
+
* Extract content from a single Sanity document and convert to HTML
|
|
29
|
+
*/
|
|
30
|
+
extractDocumentContent(document: SanityDocument): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Convert Sanity document content to HTML format
|
|
33
|
+
*/
|
|
34
|
+
convertToHtml(content: any): string;
|
|
35
|
+
/**
|
|
36
|
+
* Extract structured content with separated body, title, slug, and fields
|
|
37
|
+
* Also applies DNT preferences if available
|
|
38
|
+
*/
|
|
39
|
+
extractStructuredContent(document: SanityDocument): Promise<ExtendedDocumentContent>;
|
|
40
|
+
/**
|
|
41
|
+
* Apply DNT preferences to extracted fields based on document type
|
|
42
|
+
* Now uses document-type-based configuration that applies to all documents of the same type
|
|
43
|
+
*/
|
|
44
|
+
private applyDNTPreferences;
|
|
45
|
+
/**
|
|
46
|
+
* Extract content from multiple documents for bulk operations
|
|
47
|
+
*/
|
|
48
|
+
extractBulkContent(documents: SanityDocument[]): Promise<DocumentContent[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Extract structured content from multiple documents
|
|
51
|
+
*/
|
|
52
|
+
extractBulkStructuredContent(documents: SanityDocument[]): Promise<ExtendedDocumentContent[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Process individual fields based on their type
|
|
55
|
+
*/
|
|
56
|
+
private processField;
|
|
57
|
+
/**
|
|
58
|
+
* Process array fields (like portable text blocks)
|
|
59
|
+
*/
|
|
60
|
+
private processArray;
|
|
61
|
+
/**
|
|
62
|
+
* Process portable text blocks and convert to HTML
|
|
63
|
+
*/
|
|
64
|
+
private processPortableTextBlock;
|
|
65
|
+
/**
|
|
66
|
+
* Extract content from portable text block children
|
|
67
|
+
*/
|
|
68
|
+
private processPortableTextBlockContent;
|
|
69
|
+
/**
|
|
70
|
+
* Process object fields
|
|
71
|
+
*/
|
|
72
|
+
private processObject;
|
|
73
|
+
/**
|
|
74
|
+
* Wrap content in HTML with field name as class
|
|
75
|
+
*/
|
|
76
|
+
private wrapInHtml;
|
|
77
|
+
/**
|
|
78
|
+
* Separate main content from metadata fields
|
|
79
|
+
* All fields are immediately wrapped in TranslatableField format with type information
|
|
80
|
+
*/
|
|
81
|
+
private separateContentAndFields;
|
|
82
|
+
/**
|
|
83
|
+
* Extract slug from document
|
|
84
|
+
*/
|
|
85
|
+
private extractSlug;
|
|
86
|
+
/**
|
|
87
|
+
* Extract title from document
|
|
88
|
+
*/
|
|
89
|
+
private extractTitle;
|
|
90
|
+
/**
|
|
91
|
+
* Escape HTML special characters
|
|
92
|
+
*/
|
|
93
|
+
private escapeHtml;
|
|
94
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dialog management service with React state management
|
|
3
|
+
* Requirements: 3.1, 3.2, 3.5, 3.6, 3.7
|
|
4
|
+
*
|
|
5
|
+
* Centralized dialog management with queue support for multiple simultaneous dialogs
|
|
6
|
+
*/
|
|
7
|
+
import React, { ReactNode } from 'react';
|
|
8
|
+
import type { DialogManager, ConfirmationDialogOptions, SuccessDialogOptions, ErrorDialogOptions, LocaleSelectionDialogOptions, LocaleSelectionResult } from '../types/dialog';
|
|
9
|
+
/**
|
|
10
|
+
* Dialog types for queue management
|
|
11
|
+
*/
|
|
12
|
+
type DialogType = 'confirmation' | 'success' | 'error' | 'localeSelection';
|
|
13
|
+
/**
|
|
14
|
+
* Dialog options union type
|
|
15
|
+
*/
|
|
16
|
+
type DialogOptions = ConfirmationDialogOptions | SuccessDialogOptions | ErrorDialogOptions | LocaleSelectionDialogOptions;
|
|
17
|
+
/**
|
|
18
|
+
* Dialog queue item structure
|
|
19
|
+
*/
|
|
20
|
+
interface DialogQueueItem {
|
|
21
|
+
id: string;
|
|
22
|
+
type: DialogType;
|
|
23
|
+
options: DialogOptions;
|
|
24
|
+
resolve?: (value: unknown) => void;
|
|
25
|
+
reject?: (error: Error) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Dialog context state
|
|
29
|
+
*/
|
|
30
|
+
interface DialogContextState {
|
|
31
|
+
currentDialog: DialogQueueItem | null;
|
|
32
|
+
dialogQueue: DialogQueueItem[];
|
|
33
|
+
showConfirmation: (options: ConfirmationDialogOptions) => Promise<boolean>;
|
|
34
|
+
showLocaleSelection: (options: LocaleSelectionDialogOptions) => Promise<LocaleSelectionResult>;
|
|
35
|
+
showSuccess: (options: SuccessDialogOptions) => void;
|
|
36
|
+
showError: (options: ErrorDialogOptions) => Promise<boolean>;
|
|
37
|
+
closeAll: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hook to access dialog service from React components
|
|
41
|
+
*/
|
|
42
|
+
export declare const useDialogService: () => DialogContextState;
|
|
43
|
+
/**
|
|
44
|
+
* Dialog Provider Props
|
|
45
|
+
*/
|
|
46
|
+
interface DialogProviderProps {
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Dialog Provider Component
|
|
51
|
+
* Manages dialog state and queue for the entire application
|
|
52
|
+
*/
|
|
53
|
+
export declare const DialogProvider: React.FC<DialogProviderProps>;
|
|
54
|
+
/**
|
|
55
|
+
* Singleton DialogService class for non-React contexts
|
|
56
|
+
* Note: This requires the DialogProvider to be mounted in the React tree
|
|
57
|
+
*/
|
|
58
|
+
export declare class DialogService implements DialogManager {
|
|
59
|
+
private static instance;
|
|
60
|
+
private contextRef;
|
|
61
|
+
private constructor();
|
|
62
|
+
/**
|
|
63
|
+
* Get singleton instance
|
|
64
|
+
*/
|
|
65
|
+
static getInstance(): DialogService;
|
|
66
|
+
/**
|
|
67
|
+
* Set the context reference (called by DialogProvider)
|
|
68
|
+
*/
|
|
69
|
+
setContext(context: DialogContextState): void;
|
|
70
|
+
/**
|
|
71
|
+
* Show a confirmation dialog
|
|
72
|
+
*/
|
|
73
|
+
showConfirmation(options: ConfirmationDialogOptions): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Show a locale selection dialog
|
|
76
|
+
*/
|
|
77
|
+
showLocaleSelection(options: LocaleSelectionDialogOptions): Promise<LocaleSelectionResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Show a success notification
|
|
80
|
+
*/
|
|
81
|
+
showSuccess(options: SuccessDialogOptions): void;
|
|
82
|
+
/**
|
|
83
|
+
* Show an error dialog
|
|
84
|
+
*/
|
|
85
|
+
showError(options: ErrorDialogOptions): Promise<boolean>;
|
|
86
|
+
/**
|
|
87
|
+
* Close all open dialogs
|
|
88
|
+
*/
|
|
89
|
+
closeAll(): void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Export singleton instance for convenience
|
|
93
|
+
*/
|
|
94
|
+
export declare const dialogService: DialogService;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DNT Service Manager
|
|
3
|
+
*
|
|
4
|
+
* Provides singleton access to DNTStorageAdapter with proper initialization.
|
|
5
|
+
* Similar to OAuthServiceManager pattern.
|
|
6
|
+
*/
|
|
7
|
+
import { SanityClient } from 'sanity';
|
|
8
|
+
import { DNTStorageAdapter } from './dntStorageAdapter';
|
|
9
|
+
/**
|
|
10
|
+
* Singleton manager for DNT storage services
|
|
11
|
+
*/
|
|
12
|
+
export declare class DNTServiceManager {
|
|
13
|
+
private static instance;
|
|
14
|
+
private dntStorage;
|
|
15
|
+
private client;
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Get or create the singleton instance
|
|
19
|
+
*/
|
|
20
|
+
static getInstance(client?: SanityClient): DNTServiceManager;
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the service with a Sanity client
|
|
23
|
+
*/
|
|
24
|
+
initialize(client: SanityClient): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get the DNT storage adapter
|
|
27
|
+
* Throws if not initialized
|
|
28
|
+
*/
|
|
29
|
+
getDNTStorage(): DNTStorageAdapter;
|
|
30
|
+
/**
|
|
31
|
+
* Check if the service is initialized
|
|
32
|
+
*/
|
|
33
|
+
isInitialized(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Reset the singleton instance (useful for testing)
|
|
36
|
+
*/
|
|
37
|
+
static reset(): void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convenience function to get DNT storage adapter
|
|
41
|
+
* Throws if service is not initialized
|
|
42
|
+
*/
|
|
43
|
+
export declare function getDNTStorage(): DNTStorageAdapter;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DNT (Do Not Translate) preferences storage adapter
|
|
3
|
+
*
|
|
4
|
+
* Now uses document-type-based storage in the unified configuration.
|
|
5
|
+
* When you mark a field as DNT for any document of a type (e.g., 'product'),
|
|
6
|
+
* it applies to ALL documents of that type.
|
|
7
|
+
*
|
|
8
|
+
* This replaces the old per-document localStorage approach with centralized
|
|
9
|
+
* configuration stored in Sanity.
|
|
10
|
+
*/
|
|
11
|
+
import { DNTPreferences, DNTStorage } from '../types/dnt';
|
|
12
|
+
import { UnifiedConfigStorage } from './unifiedConfigStorage';
|
|
13
|
+
/**
|
|
14
|
+
* DNT Storage Adapter using unified configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare class DNTStorageAdapter implements DNTStorage {
|
|
17
|
+
private configStorage;
|
|
18
|
+
constructor(configStorage: UnifiedConfigStorage);
|
|
19
|
+
/**
|
|
20
|
+
* Get DNT field configuration for a document type
|
|
21
|
+
*/
|
|
22
|
+
getFieldsForType(documentType: string): Promise<Record<string, boolean>>;
|
|
23
|
+
/**
|
|
24
|
+
* Set DNT status for a specific field in a document type
|
|
25
|
+
*/
|
|
26
|
+
setFieldDNT(documentType: string, fieldPath: string, dnt: boolean): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Toggle DNT status for a field in a document type
|
|
29
|
+
*/
|
|
30
|
+
toggleFieldDNT(documentType: string, fieldPath: string): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Get DNT status for a specific field in a document type
|
|
33
|
+
*/
|
|
34
|
+
getFieldDNT(documentType: string, fieldPath: string): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Clear all DNT fields for a document type
|
|
37
|
+
*/
|
|
38
|
+
clearFieldsForType(documentType: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Get all DNT configurations (all document types)
|
|
41
|
+
*/
|
|
42
|
+
getAllDNTFields(): Promise<Record<string, Record<string, boolean>>>;
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use getFieldsForType instead. This method now uses document type, not document ID.
|
|
45
|
+
* Get DNT preferences - now based on document type, not individual document ID
|
|
46
|
+
*/
|
|
47
|
+
getPreferences(documentId: string): Promise<DNTPreferences | null>;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use setFieldDNT instead
|
|
50
|
+
*/
|
|
51
|
+
savePreferences(preferences: DNTPreferences): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use clearFieldsForType instead
|
|
54
|
+
*/
|
|
55
|
+
clearPreferences(documentId: string): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Legacy DNT Storage Adapter using localStorage (deprecated)
|
|
59
|
+
* Kept for migration purposes only
|
|
60
|
+
* @deprecated Use DNTStorageAdapter with UnifiedConfigStorage instead
|
|
61
|
+
*/
|
|
62
|
+
export declare class LegacyDNTStorageAdapter {
|
|
63
|
+
private static readonly STORAGE_KEY_PREFIX;
|
|
64
|
+
private getStorageKey;
|
|
65
|
+
getPreferences(documentId: string): Promise<DNTPreferences | null>;
|
|
66
|
+
savePreferences(preferences: DNTPreferences): Promise<void>;
|
|
67
|
+
clearPreferences(documentId: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Migrate legacy localStorage preferences to unified configuration
|
|
70
|
+
*/
|
|
71
|
+
migrateToUnified(configStorage: UnifiedConfigStorage, documentId: string, documentType: string): Promise<void>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { SanityDocument, SanityClient } from 'sanity';
|
|
2
|
+
import { TranslationResponse } from './translationService';
|
|
3
|
+
/**
|
|
4
|
+
* Options for document creation from translation
|
|
5
|
+
*/
|
|
6
|
+
export interface DocumentCreationOptions {
|
|
7
|
+
/** Target language code for the translated document */
|
|
8
|
+
targetLanguage?: string;
|
|
9
|
+
/** Source language code of the original document */
|
|
10
|
+
sourceLanguage?: string;
|
|
11
|
+
/** Whether to create the document as a variant of the original */
|
|
12
|
+
createAsVariant?: boolean;
|
|
13
|
+
/** ID of the parent document when creating as a variant */
|
|
14
|
+
parentDocumentId?: string;
|
|
15
|
+
/** Creation mode: 'draft' creates a draft document, 'published' creates a published document */
|
|
16
|
+
creationMode?: 'draft' | 'published';
|
|
17
|
+
}
|
|
18
|
+
export interface DocumentCreationResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
documentId?: string;
|
|
21
|
+
document?: SanityDocument;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface BulkDocumentCreationResult {
|
|
25
|
+
totalDocuments: number;
|
|
26
|
+
successfulCreations: number;
|
|
27
|
+
failedCreations: number;
|
|
28
|
+
results: DocumentCreationResult[];
|
|
29
|
+
errors: string[];
|
|
30
|
+
rollbackInfo?: RollbackInfo;
|
|
31
|
+
}
|
|
32
|
+
export interface RollbackInfo {
|
|
33
|
+
canRollback: boolean;
|
|
34
|
+
createdDocumentIds: string[];
|
|
35
|
+
rollbackInstructions: string[];
|
|
36
|
+
}
|
|
37
|
+
export declare class DocumentCreationService {
|
|
38
|
+
private client;
|
|
39
|
+
private defaultCreationMode;
|
|
40
|
+
constructor(client: SanityClient, defaultCreationMode?: 'draft' | 'published');
|
|
41
|
+
/**
|
|
42
|
+
* Set the default document creation mode
|
|
43
|
+
* @param mode - The creation mode to use by default ('draft' or 'published')
|
|
44
|
+
*/
|
|
45
|
+
setDefaultCreationMode(mode: 'draft' | 'published'): void;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new Sanity document from translation response
|
|
48
|
+
* Requirements: 1.1, 1.2, 2.1, 3.2, 3.4
|
|
49
|
+
*/
|
|
50
|
+
createDocumentFromTranslation(originalDocument: SanityDocument, translationResponse: TranslationResponse, options?: DocumentCreationOptions): Promise<DocumentCreationResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Validate inputs for document creation
|
|
53
|
+
* Requirements: 4.3, 4.4
|
|
54
|
+
*/
|
|
55
|
+
private validateInputsForDocumentCreation;
|
|
56
|
+
/**
|
|
57
|
+
* Validate business rules for document creation
|
|
58
|
+
* Requirements: 4.3, 4.4
|
|
59
|
+
*/
|
|
60
|
+
private validateBusinessRules;
|
|
61
|
+
/**
|
|
62
|
+
* Check if document has meaningful content
|
|
63
|
+
*/
|
|
64
|
+
private documentHasContent;
|
|
65
|
+
/**
|
|
66
|
+
* Format error messages with additional context
|
|
67
|
+
* Requirements: 4.3, 4.4
|
|
68
|
+
*/
|
|
69
|
+
private formatErrorMessage;
|
|
70
|
+
/**
|
|
71
|
+
* Create multiple documents from bulk translation responses
|
|
72
|
+
* Requirements: 2.1, 3.2, 3.4
|
|
73
|
+
*/
|
|
74
|
+
createBulkDocumentsFromTranslations(originalDocuments: SanityDocument[], translationResponses: TranslationResponse[], options?: DocumentCreationOptions): Promise<BulkDocumentCreationResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Validate bulk translation responses before document creation
|
|
77
|
+
* Requirements: 4.3, 4.4
|
|
78
|
+
*/
|
|
79
|
+
private validateBulkTranslationResponses;
|
|
80
|
+
/**
|
|
81
|
+
* Validate translation response before document creation
|
|
82
|
+
* Requirements: 4.3, 4.4
|
|
83
|
+
*/
|
|
84
|
+
private validateTranslationResponseForCreation;
|
|
85
|
+
/**
|
|
86
|
+
* Create rollback plan for failed bulk operations
|
|
87
|
+
* Requirements: 4.3, 4.4
|
|
88
|
+
*/
|
|
89
|
+
createRollbackPlan(createdDocumentIds: string[]): RollbackInfo;
|
|
90
|
+
/**
|
|
91
|
+
* Merge translated content back into original document structure
|
|
92
|
+
* Requirements: 1.2, 3.2, 3.4
|
|
93
|
+
*/
|
|
94
|
+
private mergeTranslatedContent;
|
|
95
|
+
/**
|
|
96
|
+
* Process a translated field value and convert it to the appropriate format
|
|
97
|
+
* based on the original document's structure
|
|
98
|
+
*/
|
|
99
|
+
private processTranslatedField;
|
|
100
|
+
/**
|
|
101
|
+
* Convert HTML content back to Sanity portable text format
|
|
102
|
+
* Requirements: 3.2, 3.4
|
|
103
|
+
*/
|
|
104
|
+
private convertHtmlToPortableText;
|
|
105
|
+
/**
|
|
106
|
+
* Parse inline content and handle formatting
|
|
107
|
+
*/
|
|
108
|
+
private parseInlineContent;
|
|
109
|
+
/**
|
|
110
|
+
* Get block style from HTML tag name
|
|
111
|
+
*/
|
|
112
|
+
private getBlockStyle;
|
|
113
|
+
/**
|
|
114
|
+
* Check if content appears to be HTML
|
|
115
|
+
*/
|
|
116
|
+
private isHtmlContent;
|
|
117
|
+
/**
|
|
118
|
+
* Generate a new document ID based on original ID and target language
|
|
119
|
+
*/
|
|
120
|
+
private generateNewDocumentId;
|
|
121
|
+
/**
|
|
122
|
+
* Generate a unique key for portable text blocks
|
|
123
|
+
*/
|
|
124
|
+
private generateBlockKey;
|
|
125
|
+
/**
|
|
126
|
+
* Generate a unique key for spans
|
|
127
|
+
*/
|
|
128
|
+
private generateSpanKey;
|
|
129
|
+
/**
|
|
130
|
+
* Validate document structure before creation
|
|
131
|
+
* Requirements: 3.4
|
|
132
|
+
*/
|
|
133
|
+
private validateDocumentStructure;
|
|
134
|
+
/**
|
|
135
|
+
* Validate portable text array structure
|
|
136
|
+
*/
|
|
137
|
+
private validatePortableTextArray;
|
|
138
|
+
}
|