@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,175 @@
1
+ /**
2
+ * OAuth Logger Utility
3
+ *
4
+ * Provides structured logging for OAuth authentication events with timestamps
5
+ * and component identification. Never logs sensitive data like tokens or secrets.
6
+ *
7
+ * Requirements: 7.1, 8.5
8
+ */
9
+ /**
10
+ * Log level enumeration
11
+ */
12
+ export declare enum LogLevel {
13
+ INFO = "info",
14
+ WARN = "warn",
15
+ ERROR = "error"
16
+ }
17
+ /**
18
+ * OAuth component identifier
19
+ */
20
+ export type OAuthComponent = 'OAuthService' | 'TokenStorage' | 'AuthStateManager' | 'OAuthCallback' | 'AuthStatus' | 'TranslationService';
21
+ /**
22
+ * OAuth log entry structure
23
+ */
24
+ export interface OAuthLogEntry {
25
+ /** ISO timestamp of the log entry */
26
+ timestamp: string;
27
+ /** Log level */
28
+ level: LogLevel;
29
+ /** Component that generated the log */
30
+ component: OAuthComponent;
31
+ /** Event name or description */
32
+ event: string;
33
+ /** Optional additional details (never contains sensitive data) */
34
+ details?: Record<string, unknown>;
35
+ }
36
+ /**
37
+ * OAuth Logger
38
+ *
39
+ * Provides structured logging methods for OAuth-related events.
40
+ * Automatically sanitizes sensitive data from log output.
41
+ */
42
+ export declare class OAuthLogger {
43
+ private component;
44
+ /**
45
+ * Create a new OAuth logger for a specific component
46
+ *
47
+ * @param component - Component identifier
48
+ */
49
+ constructor(component: OAuthComponent);
50
+ /**
51
+ * Sanitize details object to remove sensitive data
52
+ *
53
+ * @param details - Details object to sanitize
54
+ * @returns Sanitized details object
55
+ */
56
+ private sanitizeDetails;
57
+ /**
58
+ * Create a log entry
59
+ *
60
+ * @param level - Log level
61
+ * @param event - Event name
62
+ * @param details - Optional details
63
+ * @returns OAuth log entry
64
+ */
65
+ private createLogEntry;
66
+ /**
67
+ * Format log entry for console output
68
+ *
69
+ * @param entry - OAuth log entry to format
70
+ * @returns Formatted log message
71
+ */
72
+ private formatLogEntry;
73
+ /**
74
+ * Log an info-level event
75
+ *
76
+ * @param event - Event name
77
+ * @param details - Optional details
78
+ */
79
+ info(event: string, details?: Record<string, unknown>): void;
80
+ /**
81
+ * Log a warning-level event
82
+ *
83
+ * @param event - Event name
84
+ * @param details - Optional details
85
+ */
86
+ warn(event: string, details?: Record<string, unknown>): void;
87
+ /**
88
+ * Log an error-level event
89
+ *
90
+ * @param event - Event name
91
+ * @param details - Optional details
92
+ */
93
+ error(event: string, details?: Record<string, unknown>): void;
94
+ /**
95
+ * Log OAuth flow initiation
96
+ *
97
+ * @param authUrl - Authorization URL (without sensitive params)
98
+ */
99
+ logFlowInitiation(authUrl: string): void;
100
+ /**
101
+ * Log OAuth callback received
102
+ *
103
+ * @param hasCode - Whether authorization code was received
104
+ * @param hasError - Whether error was received
105
+ * @param projectId - Project ID if available
106
+ */
107
+ logCallbackReceived(hasCode: boolean, hasError: boolean, projectId?: string): void;
108
+ /**
109
+ * Log token exchange attempt
110
+ */
111
+ logTokenExchange(): void;
112
+ /**
113
+ * Log token exchange success
114
+ *
115
+ * @param expiresIn - Token expiration time in seconds
116
+ * @param hasRefreshToken - Whether refresh token was received
117
+ */
118
+ logTokenExchangeSuccess(expiresIn: number, hasRefreshToken: boolean): void;
119
+ /**
120
+ * Log token exchange failure
121
+ *
122
+ * @param error - Error message
123
+ * @param statusCode - HTTP status code if available
124
+ */
125
+ logTokenExchangeFailure(error: string, statusCode?: number): void;
126
+ /**
127
+ * Log token refresh attempt
128
+ */
129
+ logTokenRefresh(): void;
130
+ /**
131
+ * Log token refresh success
132
+ *
133
+ * @param expiresIn - New token expiration time in seconds
134
+ */
135
+ logTokenRefreshSuccess(expiresIn: number): void;
136
+ /**
137
+ * Log token refresh failure
138
+ *
139
+ * @param error - Error message
140
+ */
141
+ logTokenRefreshFailure(error: string): void;
142
+ /**
143
+ * Log authentication state change
144
+ *
145
+ * @param fromState - Previous state
146
+ * @param toState - New state
147
+ * @param projectId - Project ID if available
148
+ */
149
+ logStateChange(fromState: string, toState: string, projectId?: string): void;
150
+ /**
151
+ * Log logout event
152
+ */
153
+ logLogout(): void;
154
+ /**
155
+ * Log storage operation
156
+ *
157
+ * @param operation - Operation type (store, retrieve, clear)
158
+ * @param success - Whether operation succeeded
159
+ */
160
+ logStorageOperation(operation: 'store' | 'retrieve' | 'clear', success: boolean): void;
161
+ /**
162
+ * Sanitize URL to remove sensitive query parameters
163
+ *
164
+ * @param url - URL to sanitize
165
+ * @returns Sanitized URL string
166
+ */
167
+ private sanitizeUrl;
168
+ }
169
+ /**
170
+ * Create a logger instance for a specific component
171
+ *
172
+ * @param component - Component identifier
173
+ * @returns Logger instance
174
+ */
175
+ export declare function createOAuthLogger(component: OAuthComponent): OAuthLogger;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Validation functions for document and payload structure
3
+ * Requirements: 3.4, 4.3 - Validate document structure and provide clear error messages
4
+ */
5
+ import { DocumentContent, ExtendedDocumentContent } from '../services/contentExtractor';
6
+ import { TranslationRequestPayload } from '../services/translationService';
7
+ export interface ValidationResult {
8
+ isValid: boolean;
9
+ errors: string[];
10
+ warnings: string[];
11
+ }
12
+ export interface DocumentValidationOptions {
13
+ requireTitle?: boolean;
14
+ requireContent?: boolean;
15
+ allowEmptyFields?: boolean;
16
+ maxContentLength?: number;
17
+ }
18
+ export interface PayloadValidationOptions {
19
+ requireMetadata?: boolean;
20
+ maxPayloadSize?: number;
21
+ validateHtmlStructure?: boolean;
22
+ }
23
+ export declare class Validator {
24
+ /**
25
+ * Validate Sanity document structure
26
+ * Requirement 3.4: Validate document structure
27
+ */
28
+ static validateSanityDocument(document: any, options?: DocumentValidationOptions): ValidationResult;
29
+ /**
30
+ * Validate document content structure
31
+ * Requirement 3.4: Validate extracted content structure
32
+ */
33
+ static validateDocumentContent(content: DocumentContent): ValidationResult;
34
+ /**
35
+ * Validate extended document content structure
36
+ */
37
+ static validateExtendedDocumentContent(content: ExtendedDocumentContent): ValidationResult;
38
+ /**
39
+ * Validate translation request payload
40
+ * Requirement 3.4: Validate payload structure for JSON transmission
41
+ */
42
+ static validateTranslationPayload(payload: TranslationRequestPayload, options?: PayloadValidationOptions): ValidationResult;
43
+ /**
44
+ * Validate HTML content structure
45
+ * Requirement 3.2: Validate HTML structure preservation
46
+ */
47
+ static validateHtmlContent(html: string): ValidationResult;
48
+ /**
49
+ * Validate array of documents for bulk operations
50
+ * Requirement 2.1: Validate multiple documents for bulk processing
51
+ */
52
+ static validateDocumentArray(documents: any[], options?: DocumentValidationOptions): ValidationResult;
53
+ /**
54
+ * Validate endpoint URL
55
+ */
56
+ static validateEndpoint(endpoint: string): ValidationResult;
57
+ }
58
+ export declare const validator: {
59
+ validateSanityDocument: typeof Validator.validateSanityDocument;
60
+ validateDocumentContent: typeof Validator.validateDocumentContent;
61
+ validateExtendedDocumentContent: typeof Validator.validateExtendedDocumentContent;
62
+ validateTranslationPayload: typeof Validator.validateTranslationPayload;
63
+ validateHtmlContent: typeof Validator.validateHtmlContent;
64
+ validateDocumentArray: typeof Validator.validateDocumentArray;
65
+ validateEndpoint: typeof Validator.validateEndpoint;
66
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyling/sanity-connector",
3
- "version": "0.0.2-rc.1",
3
+ "version": "0.0.2-rc.2",
4
4
  "description": "A Sanity Studio plugin that enables document translation with support for single and bulk operations. Extracts document content as HTML and prepares translation requests for external services.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -19,8 +19,8 @@
19
19
  "LICENSE"
20
20
  ],
21
21
  "scripts": {
22
- "build": "npm run clean && tsc",
23
- "build:bundle": "npm run clean && webpack build && tsc --project tsconfig.types.json",
22
+ "build": "npm run clean && webpack build && tsc --project tsconfig.types.json",
23
+ "build:simple": "npm run clean && tsc",
24
24
  "build:watch": "tsc --watch",
25
25
  "clean": "rimraf dist dist-types",
26
26
  "dev": "npm run build:watch",