@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.
Files changed (64) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.LICENSE.txt +28 -0
  4. package/dist-types/actions/bulkTranslate.d.ts +6 -0
  5. package/dist-types/actions/manageDNTFields.d.ts +11 -0
  6. package/dist-types/actions/translateDocument.d.ts +6 -0
  7. package/dist-types/components/RadioWithDefault.d.ts +16 -0
  8. package/dist-types/components/auth/AuthNavbar.d.ts +17 -0
  9. package/dist-types/components/auth/AuthStatus.d.ts +26 -0
  10. package/dist-types/components/auth/AuthStatusWrapper.d.ts +14 -0
  11. package/dist-types/components/auth/MigrationPrompt.d.ts +19 -0
  12. package/dist-types/components/auth/MigrationPromptWrapper.d.ts +13 -0
  13. package/dist-types/components/auth/OAuthCallback.d.ts +19 -0
  14. package/dist-types/components/auth/index.d.ts +14 -0
  15. package/dist-types/components/config/LocaleConfigTool.d.ts +16 -0
  16. package/dist-types/components/config/LocaleConfigToolWrapper.d.ts +12 -0
  17. package/dist-types/components/config/OAuthConfig.d.ts +25 -0
  18. package/dist-types/components/config/OAuthConfigWrapper.d.ts +12 -0
  19. package/dist-types/components/config/PasswordInput.d.ts +13 -0
  20. package/dist-types/components/config/index.d.ts +8 -0
  21. package/dist-types/components/config/localeConfigToolDefinition.d.ts +12 -0
  22. package/dist-types/components/config/oauthConfigToolDefinition.d.ts +12 -0
  23. package/dist-types/components/dialogs/ConfirmationDialog.d.ts +20 -0
  24. package/dist-types/components/dialogs/ErrorDialog.d.ts +20 -0
  25. package/dist-types/components/dialogs/LocaleSelectionDialog.d.ts +40 -0
  26. package/dist-types/components/dialogs/SuccessDialog.d.ts +18 -0
  27. package/dist-types/components/dialogs/index.d.ts +11 -0
  28. package/dist-types/components/dnt/DNTFieldBadge.d.ts +15 -0
  29. package/dist-types/components/dnt/DNTFieldComponent.d.ts +16 -0
  30. package/dist-types/components/dnt/DNTFieldInput.d.ts +13 -0
  31. package/dist-types/components/dnt/index.d.ts +6 -0
  32. package/dist-types/config/index.d.ts +5 -0
  33. package/dist-types/config/pluginConfig.d.ts +162 -0
  34. package/dist-types/index.d.ts +11 -0
  35. package/dist-types/plugin.d.ts +2 -0
  36. package/dist-types/services/authStateManager.d.ts +93 -0
  37. package/dist-types/services/contentExtractor.d.ts +94 -0
  38. package/dist-types/services/dialogService.d.ts +95 -0
  39. package/dist-types/services/dntServiceManager.d.ts +43 -0
  40. package/dist-types/services/dntStorageAdapter.d.ts +72 -0
  41. package/dist-types/services/documentCreationService.d.ts +138 -0
  42. package/dist-types/services/localeService.d.ts +159 -0
  43. package/dist-types/services/localeStorageAdapter.d.ts +41 -0
  44. package/dist-types/services/oauthConfigStorage.d.ts +45 -0
  45. package/dist-types/services/oauthService.d.ts +47 -0
  46. package/dist-types/services/oauthServiceManager.d.ts +188 -0
  47. package/dist-types/services/tokenStorage.d.ts +53 -0
  48. package/dist-types/services/translationService.d.ts +373 -0
  49. package/dist-types/services/unifiedConfigStorage.d.ts +123 -0
  50. package/dist-types/test-utils.d.ts +8 -0
  51. package/dist-types/types/dialog.d.ts +106 -0
  52. package/dist-types/types/dnt.d.ts +83 -0
  53. package/dist-types/types/index.d.ts +11 -0
  54. package/dist-types/types/locale.d.ts +115 -0
  55. package/dist-types/types/oauth.d.ts +89 -0
  56. package/dist-types/types/pluginConfig.d.ts +44 -0
  57. package/dist-types/types/translation.d.ts +121 -0
  58. package/dist-types/utils/htmlFormatter.d.ts +65 -0
  59. package/dist-types/utils/index.d.ts +14 -0
  60. package/dist-types/utils/logger.d.ts +104 -0
  61. package/dist-types/utils/oauthErrorFeedback.d.ts +75 -0
  62. package/dist-types/utils/oauthLogger.d.ts +175 -0
  63. package/dist-types/utils/validator.d.ts +66 -0
  64. package/package.json +3 -3
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Locale configuration management service
3
+ * Requirements: 1.1, 1.4, 1.5, 5.4, 5.5, 5.6
4
+ *
5
+ * Provides CRUD operations for locale configuration management with validation,
6
+ * persistence, and error handling capabilities.
7
+ */
8
+ import { LocaleConfig, LocaleDefinition, LocaleValidationResult } from '../types/locale';
9
+ /**
10
+ * Storage interface for locale configuration persistence
11
+ * This allows for different storage implementations (localStorage, Sanity config, etc.)
12
+ */
13
+ export interface LocaleStorageAdapter {
14
+ load(): Promise<LocaleConfig | null>;
15
+ save(config: LocaleConfig): Promise<void>;
16
+ }
17
+ /**
18
+ * Error types for locale service operations
19
+ */
20
+ export declare class LocaleServiceError extends Error {
21
+ code: string;
22
+ details?: unknown | undefined;
23
+ constructor(message: string, code: string, details?: unknown | undefined);
24
+ }
25
+ /**
26
+ * Service for managing locale configuration with CRUD operations
27
+ * Requirements: 1.1, 1.4, 1.5, 5.4, 5.5, 5.6
28
+ */
29
+ export declare class LocaleService {
30
+ private config;
31
+ private storageAdapter;
32
+ /**
33
+ * Creates a new LocaleService instance
34
+ *
35
+ * @param storageAdapter - Optional storage adapter for persistence
36
+ * @param initialConfig - Optional initial configuration (defaults to empty config)
37
+ */
38
+ constructor(storageAdapter?: LocaleStorageAdapter | null, initialConfig?: LocaleConfig);
39
+ /**
40
+ * Loads locale configuration from storage
41
+ * Requirements: 1.4, 5.4
42
+ *
43
+ * @returns Promise resolving to the loaded configuration
44
+ * @throws LocaleServiceError if loading fails
45
+ */
46
+ loadConfig(): Promise<LocaleConfig>;
47
+ /**
48
+ * Saves locale configuration to storage
49
+ * Requirements: 1.5, 5.5
50
+ *
51
+ * @param config - Optional configuration to save (defaults to current config)
52
+ * @returns Promise resolving when save is complete
53
+ * @throws LocaleServiceError if saving fails
54
+ */
55
+ saveConfig(config?: LocaleConfig): Promise<void>;
56
+ /**
57
+ * Gets the current locale configuration
58
+ *
59
+ * @returns Current locale configuration
60
+ */
61
+ getConfig(): LocaleConfig;
62
+ /**
63
+ * Gets all locales from the configuration
64
+ *
65
+ * @returns Array of all locale definitions
66
+ */
67
+ getAllLocales(): LocaleDefinition[];
68
+ /**
69
+ * Gets all enabled locales from the configuration
70
+ *
71
+ * @returns Array of enabled locale definitions
72
+ */
73
+ getEnabledLocales(): LocaleDefinition[];
74
+ /**
75
+ * Gets a locale by its code
76
+ *
77
+ * @param code - Locale code to find
78
+ * @returns Locale definition or undefined if not found
79
+ */
80
+ getLocaleByCode(code: string): LocaleDefinition | undefined;
81
+ /**
82
+ * Checks if a locale code exists in the configuration
83
+ *
84
+ * @param code - Locale code to check
85
+ * @returns True if the locale exists
86
+ */
87
+ hasLocale(code: string): boolean;
88
+ /**
89
+ * Adds a new locale to the configuration
90
+ * Requirements: 1.1, 1.2, 1.3
91
+ *
92
+ * @param locale - Locale definition to add
93
+ * @returns Promise resolving to validation result
94
+ * @throws LocaleServiceError if locale is invalid or already exists
95
+ */
96
+ addLocale(locale: Omit<LocaleDefinition, 'createdAt' | 'updatedAt'>): Promise<LocaleValidationResult>;
97
+ /**
98
+ * Updates an existing locale in the configuration
99
+ * Requirements: 1.6, 1.7
100
+ *
101
+ * @param code - Code of the locale to update
102
+ * @param updates - Partial locale definition with updates
103
+ * @returns Promise resolving to validation result
104
+ * @throws LocaleServiceError if locale not found or updates are invalid
105
+ */
106
+ updateLocale(code: string, updates: Partial<Omit<LocaleDefinition, 'code' | 'createdAt' | 'updatedAt'>>): Promise<LocaleValidationResult>;
107
+ /**
108
+ * Removes a locale from the configuration
109
+ * Requirements: 1.6
110
+ *
111
+ * @param code - Code of the locale to remove
112
+ * @returns Promise resolving when removal is complete
113
+ * @throws LocaleServiceError if locale not found
114
+ */
115
+ removeLocale(code: string): Promise<void>;
116
+ /**
117
+ * Sets the default locale
118
+ *
119
+ * @param code - Code of the locale to set as default
120
+ * @returns Promise resolving when update is complete
121
+ * @throws LocaleServiceError if locale not found
122
+ */
123
+ setDefaultLocale(code: string): Promise<void>;
124
+ /**
125
+ * Clears the default locale
126
+ *
127
+ * @returns Promise resolving when update is complete
128
+ */
129
+ clearDefaultLocale(): Promise<void>;
130
+ /**
131
+ * Validates the current configuration
132
+ * Requirements: 5.6
133
+ *
134
+ * @returns Validation result
135
+ */
136
+ validateCurrentConfig(): LocaleValidationResult;
137
+ /**
138
+ * Resets configuration to default state
139
+ * Requirements: 5.6
140
+ *
141
+ * @returns Promise resolving when reset is complete
142
+ */
143
+ resetToDefault(): Promise<void>;
144
+ /**
145
+ * Imports a locale configuration
146
+ * Useful for bulk import or migration scenarios
147
+ *
148
+ * @param config - Configuration to import
149
+ * @returns Promise resolving to validation result
150
+ * @throws LocaleServiceError if configuration is invalid
151
+ */
152
+ importConfig(config: LocaleConfig): Promise<LocaleValidationResult>;
153
+ /**
154
+ * Exports the current locale configuration
155
+ *
156
+ * @returns Current configuration as a plain object
157
+ */
158
+ exportConfig(): LocaleConfig;
159
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Locale Storage Adapter for Sanity Configuration
3
+ * Requirements: 5.1, 5.2, 5.3, 5.7
4
+ *
5
+ * Now delegates to UnifiedConfigStorage for centralized configuration management.
6
+ * Locale settings are stored in the EL_PluginConfiguration document alongside
7
+ * OAuth and DNT configurations.
8
+ */
9
+ import { SanityClient } from 'sanity';
10
+ import { LocaleConfig } from '../types/locale';
11
+ import { LocaleStorageAdapter } from './localeService';
12
+ /**
13
+ * Locale configuration storage adapter
14
+ * Now uses UnifiedConfigStorage for centralized management
15
+ * Requirements: 5.1, 5.2, 5.3, 5.7
16
+ */
17
+ export declare class SanityLocaleStorageAdapter implements LocaleStorageAdapter {
18
+ private unifiedStorage;
19
+ private client;
20
+ constructor(client: SanityClient);
21
+ /**
22
+ * Load locale configuration from unified storage
23
+ * Requirements: 5.2, 5.4
24
+ */
25
+ load(): Promise<LocaleConfig | null>;
26
+ /**
27
+ * Save locale configuration to unified storage
28
+ * Requirements: 5.3, 5.5
29
+ */
30
+ save(config: LocaleConfig): Promise<void>;
31
+ /**
32
+ * Load from legacy locale-specific document
33
+ * @private
34
+ */
35
+ private loadLegacy;
36
+ /**
37
+ * Delete legacy locale document after migration
38
+ * @private
39
+ */
40
+ private deleteLegacy;
41
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * OAuth Configuration Storage Adapter
3
+ * Requirements: 9.1, 9.4
4
+ *
5
+ * Now delegates to UnifiedConfigStorage for centralized configuration management.
6
+ * OAuth settings are stored in the EL_PluginConfiguration document alongside
7
+ * locale and DNT configurations.
8
+ */
9
+ import { SanityClient } from 'sanity';
10
+ import { OAuthConfig } from '../types/oauth';
11
+ /**
12
+ * OAuth configuration storage adapter
13
+ * Now uses UnifiedConfigStorage for centralized management
14
+ * Requirements: 9.1, 9.4
15
+ */
16
+ export declare class OAuthConfigStorage {
17
+ private unifiedStorage;
18
+ private client;
19
+ constructor(client: SanityClient);
20
+ /**
21
+ * Load OAuth configuration from unified storage
22
+ * Requirements: 9.1, 9.4
23
+ */
24
+ load(): Promise<OAuthConfig | null>;
25
+ /**
26
+ * Save OAuth configuration to unified storage
27
+ * Requirements: 9.1, 9.4
28
+ */
29
+ save(config: OAuthConfig): Promise<void>;
30
+ /**
31
+ * Delete OAuth configuration
32
+ * Only clears OAuth fields, preserves other configuration
33
+ */
34
+ delete(): Promise<void>;
35
+ /**
36
+ * Load from legacy OAuth-specific document
37
+ * @private
38
+ */
39
+ private loadLegacy;
40
+ /**
41
+ * Delete legacy OAuth document after migration
42
+ * @private
43
+ */
44
+ private deleteLegacy;
45
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Easyling Authentication Service
3
+ *
4
+ * Manages Easyling authentication configuration for the Sanity Translation Plugin.
5
+ * Handles validation and storage of access tokens and project IDs.
6
+ */
7
+ import { OAuthConfig } from '../types/oauth';
8
+ /**
9
+ * Easyling Authentication Service
10
+ *
11
+ * Provides methods for managing Easyling authentication configuration.
12
+ */
13
+ export declare class OAuthService {
14
+ private config;
15
+ /**
16
+ * Create a new Easyling Authentication Service instance
17
+ *
18
+ * @param config - Easyling configuration (access token and project ID)
19
+ * @throws {OAuthError} If configuration is invalid
20
+ */
21
+ constructor(config: OAuthConfig);
22
+ /**
23
+ * Validate configuration
24
+ *
25
+ * @param config - Configuration to validate
26
+ * @throws {OAuthError} If configuration is invalid
27
+ */
28
+ private validateConfig;
29
+ /**
30
+ * Get the access token
31
+ *
32
+ * @returns The configured access token
33
+ */
34
+ getAccessToken(): string;
35
+ /**
36
+ * Get the project ID
37
+ *
38
+ * @returns The configured project ID
39
+ */
40
+ getProjectId(): string;
41
+ /**
42
+ * Get the complete configuration
43
+ *
44
+ * @returns The complete OAuth configuration
45
+ */
46
+ getConfig(): OAuthConfig;
47
+ }
@@ -0,0 +1,188 @@
1
+ /**
2
+ * OAuth Service Manager
3
+ * Requirements: 6.1, 10.1, 9.2
4
+ *
5
+ * Manages singleton instances of OAuth services and handles initialization.
6
+ * Provides centralized access to OAuth services throughout the plugin.
7
+ */
8
+ import { SanityClient } from 'sanity';
9
+ import { OAuthService } from './oauthService';
10
+ import { TokenStorage } from './tokenStorage';
11
+ import { AuthStateManager } from './authStateManager';
12
+ import { TranslationService } from './translationService';
13
+ import { OAuthConfigStorage } from './oauthConfigStorage';
14
+ /**
15
+ * OAuth Service Manager
16
+ *
17
+ * Singleton manager for OAuth services. Ensures all services are properly
18
+ * initialized and provides centralized access throughout the plugin.
19
+ */
20
+ export declare class OAuthServiceManager {
21
+ private static instance;
22
+ private oauthService;
23
+ private tokenStorage;
24
+ private authStateManager;
25
+ private translationService;
26
+ private oauthConfigStorage;
27
+ private unifiedConfigStorage;
28
+ private client;
29
+ private initialized;
30
+ /**
31
+ * Private constructor to enforce singleton pattern
32
+ * Requirements: 6.1, 10.1
33
+ */
34
+ private constructor();
35
+ /**
36
+ * Get or create the singleton instance
37
+ * Requirements: 6.1, 10.1
38
+ *
39
+ * @param client - Sanity client instance
40
+ * @returns Singleton instance of OAuthServiceManager
41
+ */
42
+ static getInstance(client: SanityClient): OAuthServiceManager;
43
+ /**
44
+ * Reset the singleton instance (useful for testing)
45
+ */
46
+ static resetInstance(): void;
47
+ /**
48
+ * Initialize OAuth services
49
+ * Requirements: 6.1, 10.1
50
+ *
51
+ * Loads OAuth configuration, initializes OAuth service if configured,
52
+ * initializes authentication state from storage, and sets up translation
53
+ * service with authentication if available.
54
+ *
55
+ * @returns Promise that resolves when initialization is complete
56
+ */
57
+ initialize(): Promise<void>;
58
+ /**
59
+ * Load OAuth configuration from storage
60
+ * Requirements: 9.1, 9.4
61
+ *
62
+ * @returns OAuth configuration or null if not configured
63
+ */
64
+ private loadOAuthConfig;
65
+ /**
66
+ * Set up translation service with authentication if available
67
+ *
68
+ * Checks for valid stored authentication and configures the translation
69
+ * service to use it.
70
+ *
71
+ * Supports dual mode operation:
72
+ * - If OAuth is configured and authenticated, sets up OAuth authentication
73
+ * - If OAuth is not configured, translation service works in legacy mode
74
+ *
75
+ * IMPORTANT: This method also syncs configuration from Sanity to localStorage
76
+ * if configuration exists in Sanity but not in localStorage (migration support).
77
+ */
78
+ private setupTranslationServiceAuth;
79
+ /**
80
+ * Set up translation service endpoint and settings from configuration
81
+ *
82
+ * Loads translation endpoint, content type, and other settings from
83
+ * unified configuration with fallback to defaults.
84
+ */
85
+ private setupTranslationServiceEndpoint;
86
+ /**
87
+ * Get OAuth service instance
88
+ * Requirements: 1.1, 1.2, 1.3
89
+ *
90
+ * @returns OAuth service instance or null if not configured
91
+ */
92
+ getOAuthService(): OAuthService | null;
93
+ /**
94
+ * Get token storage instance
95
+ * Requirements: 3.3, 3.4, 3.5
96
+ *
97
+ * @returns Token storage instance
98
+ */
99
+ getTokenStorage(): TokenStorage;
100
+ /**
101
+ * Get authentication state manager instance
102
+ * Requirements: 6.1, 6.2, 6.3
103
+ *
104
+ * @returns Authentication state manager instance
105
+ */
106
+ getAuthStateManager(): AuthStateManager;
107
+ /**
108
+ * Get translation service instance
109
+ * Requirements: 4.1, 4.2, 4.3
110
+ *
111
+ * @returns Translation service instance
112
+ */
113
+ getTranslationService(): TranslationService;
114
+ /**
115
+ * Get OAuth configuration storage instance
116
+ * Requirements: 9.1, 9.4
117
+ *
118
+ * @returns OAuth configuration storage instance
119
+ */
120
+ getOAuthConfigStorage(): OAuthConfigStorage;
121
+ /**
122
+ * Check if OAuth is configured
123
+ * Requirements: 10.1, 10.3
124
+ *
125
+ * @returns True if OAuth service is initialized
126
+ */
127
+ isOAuthConfigured(): boolean;
128
+ /**
129
+ * Detect which authentication method should be used
130
+ * Requirements: 10.1, 10.3, 10.4
131
+ *
132
+ * Determines whether to use OAuth or legacy endpoint-based authentication
133
+ * based on the presence of OAuth configuration.
134
+ *
135
+ * @returns 'oauth' if OAuth is configured, 'legacy' otherwise
136
+ */
137
+ getAuthenticationMode(): 'oauth' | 'legacy';
138
+ /**
139
+ * Check if user is authenticated with OAuth
140
+ * Requirements: 10.1, 10.3
141
+ *
142
+ * @returns True if OAuth is configured and user has valid authentication
143
+ */
144
+ isOAuthAuthenticated(): Promise<boolean>;
145
+ /**
146
+ * Get authentication status information
147
+ * Requirements: 10.1, 10.3, 10.4
148
+ *
149
+ * Provides detailed information about the current authentication mode
150
+ * and status for display to users.
151
+ *
152
+ * @returns Object with authentication mode and status details
153
+ */
154
+ getAuthenticationStatus(): Promise<{
155
+ mode: 'oauth' | 'legacy';
156
+ isOAuthConfigured: boolean;
157
+ isAuthenticated: boolean;
158
+ requiresAuthentication: boolean;
159
+ }>;
160
+ /**
161
+ * Check if services are initialized
162
+ * Requirements: 6.1
163
+ *
164
+ * @returns True if initialization is complete
165
+ */
166
+ isInitialized(): boolean;
167
+ /**
168
+ * Save authentication configuration and data
169
+ *
170
+ * Stores the access token and project ID, and configures the translation service.
171
+ *
172
+ * @param accessToken - The Easyling access token
173
+ * @param projectId - The Easyling project ID
174
+ */
175
+ saveAuth(accessToken: string, projectId: string): Promise<void>;
176
+ /**
177
+ * Logout and clear authentication
178
+ */
179
+ logout(): Promise<void>;
180
+ /**
181
+ * Refresh configuration from Sanity
182
+ *
183
+ * Reloads the translation service endpoint and other settings from Sanity.
184
+ * This should be called when the configuration has been updated in Sanity
185
+ * to ensure the plugin is using the latest settings.
186
+ */
187
+ refreshConfiguration(): Promise<void>;
188
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Token Storage Service
3
+ *
4
+ * Manages secure storage and retrieval of OAuth authentication tokens
5
+ * and related data using Sanity Studio's localStorage wrapper.
6
+ *
7
+ * Requirements: 3.3, 3.4, 3.5, 6.1, 6.4, 8.4
8
+ */
9
+ import { StoredAuthData } from '../types/oauth';
10
+ /**
11
+ * Token Storage Service
12
+ *
13
+ * Provides methods for persisting, retrieving, and managing OAuth authentication data.
14
+ * Uses Sanity Studio's localStorage for persistence with JSON serialization.
15
+ */
16
+ export declare class TokenStorage {
17
+ /**
18
+ * Store authentication data securely
19
+ *
20
+ * @param data - Authentication data to store
21
+ * @throws {OAuthError} If storage operation fails
22
+ */
23
+ storeAuthData(data: StoredAuthData): Promise<void>;
24
+ /**
25
+ * Retrieve stored authentication data
26
+ *
27
+ * @returns Stored authentication data or null if not found
28
+ * @throws {OAuthError} If storage read fails or data is corrupted
29
+ */
30
+ getAuthData(): Promise<StoredAuthData | null>;
31
+ /**
32
+ * Clear all stored authentication data
33
+ *
34
+ * Requirements: 6.4
35
+ *
36
+ * @throws {OAuthError} If storage clear operation fails
37
+ */
38
+ clearAuthData(): Promise<void>;
39
+ /**
40
+ * Check if the stored token is expired
41
+ *
42
+ * For long-lived tokens, this always returns false if a token exists.
43
+ *
44
+ * @returns True if token is not found, false if token exists
45
+ */
46
+ isTokenExpired(): Promise<boolean>;
47
+ /**
48
+ * Get a valid access token if available
49
+ *
50
+ * @returns Valid access token or null if not found
51
+ */
52
+ getValidAccessToken(): Promise<string | null>;
53
+ }