@procore/ai-translations 0.5.0 → 0.6.1
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/README.internal.md +257 -0
- package/README.md +158 -1
- package/dist/legacy/index.d.mts +103 -1
- package/dist/legacy/index.d.ts +103 -1
- package/dist/legacy/index.js +322 -69
- package/dist/legacy/index.mjs +311 -64
- package/dist/modern/index.d.mts +103 -1
- package/dist/modern/index.d.ts +103 -1
- package/dist/modern/index.js +322 -69
- package/dist/modern/index.mjs +311 -64
- package/package.json +1 -1
package/dist/modern/index.d.mts
CHANGED
|
@@ -2,6 +2,35 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
|
+
/** Shape of an analytic event passed to the MFE's `onTrackAnalyticsEvent` callback. */
|
|
6
|
+
interface AnalyticEvent {
|
|
7
|
+
key: string;
|
|
8
|
+
properties: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/** Function provided by the MFE that sends the event to the analytics destination. */
|
|
11
|
+
type AIAnalyticsTracker = (event: AnalyticEvent) => void;
|
|
12
|
+
/** Feature scope: `'project'` for project-level tools, `'company'` for company-level tools. */
|
|
13
|
+
type Scope = 'project' | 'company';
|
|
14
|
+
/**
|
|
15
|
+
* Parts needed to build an event key following the pattern:
|
|
16
|
+
* `ux.web.feature.{scope}.{tool}.{object}.{action}`
|
|
17
|
+
*/
|
|
18
|
+
interface EventKeyParts {
|
|
19
|
+
scope: Scope;
|
|
20
|
+
tool: string;
|
|
21
|
+
object: string;
|
|
22
|
+
action: string;
|
|
23
|
+
}
|
|
24
|
+
/** Standard properties included in every AI analytics event. */
|
|
25
|
+
interface AIAnalyticsEventProperties {
|
|
26
|
+
user_locale: string;
|
|
27
|
+
project_locale?: string;
|
|
28
|
+
company_locale?: string;
|
|
29
|
+
tool: string;
|
|
30
|
+
page: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
5
34
|
interface TranslationProgress {
|
|
6
35
|
/**
|
|
7
36
|
* Progress percentage (0-100)
|
|
@@ -39,12 +68,22 @@ interface ModelDownloadProgress {
|
|
|
39
68
|
interface AITranslationContextValue {
|
|
40
69
|
ait: (text: string) => Promise<string>;
|
|
41
70
|
locale: string;
|
|
71
|
+
/** Company-level locale from environment metadata (e.g. `"de-DE"`). */
|
|
72
|
+
companyLocale?: string;
|
|
73
|
+
/** Project-level locale from environment metadata (e.g. `"fr-CA"`). */
|
|
74
|
+
projectLocale?: string;
|
|
42
75
|
renderVersion?: number;
|
|
43
76
|
/** Batch-translation progress; `null` while the queue is idle. */
|
|
44
77
|
translationProgress: TranslationProgress | null;
|
|
45
78
|
/** Chrome AI model download progress; `null` until a download begins. */
|
|
46
79
|
modelDownloadProgress: ModelDownloadProgress | null;
|
|
47
80
|
tool: string;
|
|
81
|
+
/** Called by `useAIAnalytics` with a fully assembled event. The MFE is responsible for sending it. */
|
|
82
|
+
onTrackAnalyticsEvent?: AIAnalyticsTracker;
|
|
83
|
+
/** Page context used to build the event key object segment (e.g. `'view'`, `'list_column_description'`). */
|
|
84
|
+
page?: string;
|
|
85
|
+
/** Feature scope: `'project'` or `'company'`. */
|
|
86
|
+
scope?: Scope;
|
|
48
87
|
}
|
|
49
88
|
|
|
50
89
|
interface ConfigurationResponse {
|
|
@@ -117,6 +156,59 @@ declare function useConfig(toolName: string, options?: UseConfigOptions): _tanst
|
|
|
117
156
|
*/
|
|
118
157
|
declare function useAITranslation(): AITranslationContextValue;
|
|
119
158
|
|
|
159
|
+
/** Button type identifiers for the event key `object` segment. */
|
|
160
|
+
declare const BUTTON_TYPE: {
|
|
161
|
+
readonly TRANSLATE: "translate";
|
|
162
|
+
readonly HIGHLIGHT: "highlight";
|
|
163
|
+
};
|
|
164
|
+
type ButtonType = (typeof BUTTON_TYPE)[keyof typeof BUTTON_TYPE];
|
|
165
|
+
/** Action identifiers for the event key `action` segment. */
|
|
166
|
+
declare const ACTION: {
|
|
167
|
+
readonly CLICKED: "clicked";
|
|
168
|
+
};
|
|
169
|
+
type Action = (typeof ACTION)[keyof typeof ACTION];
|
|
170
|
+
/**
|
|
171
|
+
* Builds the `object` segment: `{pageContext}_{buttonType}_button`
|
|
172
|
+
* e.g. `buildObject('view', 'translate')` → `'view_translate_button'`
|
|
173
|
+
*/
|
|
174
|
+
declare function buildObject(pageContext: string, buttonType: ButtonType): string;
|
|
175
|
+
/**
|
|
176
|
+
* Builds a fully-qualified event key:
|
|
177
|
+
* `ux.web.feature.{scope}.{tool}.{object}.{action}`
|
|
178
|
+
*/
|
|
179
|
+
declare function buildEventKey(parts: EventKeyParts): string;
|
|
180
|
+
interface BuildAnalyticEventParams {
|
|
181
|
+
scope: Scope;
|
|
182
|
+
tool: string;
|
|
183
|
+
/** Prefix for the object segment, matches the Provider `page` prop (e.g. `'view'`). */
|
|
184
|
+
pageContext: string;
|
|
185
|
+
buttonType: ButtonType;
|
|
186
|
+
baseProperties: AIAnalyticsEventProperties;
|
|
187
|
+
/** Defaults to `'clicked'` if omitted. */
|
|
188
|
+
action?: Action;
|
|
189
|
+
additionalProperties?: Record<string, unknown>;
|
|
190
|
+
}
|
|
191
|
+
/** Assembles a complete `AnalyticEvent` (key + merged properties) ready for `onTrackAnalyticsEvent`. */
|
|
192
|
+
declare function buildAnalyticEvent(params: BuildAnalyticEventParams): AnalyticEvent;
|
|
193
|
+
|
|
194
|
+
interface UseAIAnalyticsReturn {
|
|
195
|
+
/** Fires `ux.web.feature.{scope}.{tool}.{page}_translate_button.clicked`. */
|
|
196
|
+
trackTranslateButtonClicked: (additionalProperties?: Record<string, unknown>) => void;
|
|
197
|
+
/** Fires `ux.web.feature.{scope}.{tool}.{page}_highlight_button.clicked`. */
|
|
198
|
+
trackHighlightButtonClicked: (additionalProperties?: Record<string, unknown>) => void;
|
|
199
|
+
/** Generic tracking for custom button types or actions. */
|
|
200
|
+
trackCustomEvent: (buttonType: ButtonType | string, action?: Action | string, additionalProperties?: Record<string, unknown>) => void;
|
|
201
|
+
/** `true` when `onTrackAnalyticsEvent` was provided to `AITranslationProvider`. */
|
|
202
|
+
isTrackingEnabled: boolean;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns analytics tracking helpers pre-wired to the Provider context.
|
|
206
|
+
* All functions no-op if `onTrackAnalyticsEvent` was not supplied.
|
|
207
|
+
*
|
|
208
|
+
* @throws if called outside of an `AITranslationProvider`.
|
|
209
|
+
*/
|
|
210
|
+
declare function useAIAnalytics(): UseAIAnalyticsReturn;
|
|
211
|
+
|
|
120
212
|
interface AITranslationProviderProps {
|
|
121
213
|
children: ReactNode;
|
|
122
214
|
locale: string;
|
|
@@ -125,6 +217,16 @@ interface AITranslationProviderProps {
|
|
|
125
217
|
userId: number;
|
|
126
218
|
projectId: number;
|
|
127
219
|
enableAIT?: boolean;
|
|
220
|
+
/** Company-level locale from environment metadata (e.g. `"de-DE"`). Passed through to context for downstream consumers such as Amplitude. */
|
|
221
|
+
companyLocale?: string;
|
|
222
|
+
/** Project-level locale from environment metadata (e.g. `"fr-CA"`). Passed through to context for downstream consumers such as Amplitude. */
|
|
223
|
+
projectLocale?: string;
|
|
224
|
+
/** Called by `useAIAnalytics` with a pre-assembled event. The MFE sends it to the analytics API. */
|
|
225
|
+
onTrackAnalyticsEvent?: AIAnalyticsTracker;
|
|
226
|
+
/** Page context for the event key object segment (e.g. `'view'`, `'list_column_description'`). */
|
|
227
|
+
page?: string;
|
|
228
|
+
/** Feature scope: `'project'` or `'company'`. */
|
|
229
|
+
scope?: Scope;
|
|
128
230
|
}
|
|
129
231
|
declare function AITranslationProvider(props: AITranslationProviderProps): react_jsx_runtime.JSX.Element;
|
|
130
232
|
|
|
@@ -177,4 +279,4 @@ declare global {
|
|
|
177
279
|
var _BACKEND_AI_TRANSLATION_IN_PROGRESS_: boolean;
|
|
178
280
|
}
|
|
179
281
|
|
|
180
|
-
export { AITranslateText, type AITranslateTextProps, AITranslationProvider, AI_TRANSLATION_FEATURE_FLAG_KEY, type TranslatedIconProps, type UseConfigOptions, getAITranslationLDId, useAITranslation, useConfig };
|
|
282
|
+
export { ACTION, type AIAnalyticsEventProperties, type AIAnalyticsTracker, AITranslateText, type AITranslateTextProps, AITranslationProvider, AI_TRANSLATION_FEATURE_FLAG_KEY, type Action, type AnalyticEvent, BUTTON_TYPE, type BuildAnalyticEventParams, type ButtonType, type EventKeyParts, type Scope, type TranslatedIconProps, type UseAIAnalyticsReturn, type UseConfigOptions, buildAnalyticEvent, buildEventKey, buildObject, getAITranslationLDId, useAIAnalytics, useAITranslation, useConfig };
|
package/dist/modern/index.d.ts
CHANGED
|
@@ -2,6 +2,35 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
|
+
/** Shape of an analytic event passed to the MFE's `onTrackAnalyticsEvent` callback. */
|
|
6
|
+
interface AnalyticEvent {
|
|
7
|
+
key: string;
|
|
8
|
+
properties: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/** Function provided by the MFE that sends the event to the analytics destination. */
|
|
11
|
+
type AIAnalyticsTracker = (event: AnalyticEvent) => void;
|
|
12
|
+
/** Feature scope: `'project'` for project-level tools, `'company'` for company-level tools. */
|
|
13
|
+
type Scope = 'project' | 'company';
|
|
14
|
+
/**
|
|
15
|
+
* Parts needed to build an event key following the pattern:
|
|
16
|
+
* `ux.web.feature.{scope}.{tool}.{object}.{action}`
|
|
17
|
+
*/
|
|
18
|
+
interface EventKeyParts {
|
|
19
|
+
scope: Scope;
|
|
20
|
+
tool: string;
|
|
21
|
+
object: string;
|
|
22
|
+
action: string;
|
|
23
|
+
}
|
|
24
|
+
/** Standard properties included in every AI analytics event. */
|
|
25
|
+
interface AIAnalyticsEventProperties {
|
|
26
|
+
user_locale: string;
|
|
27
|
+
project_locale?: string;
|
|
28
|
+
company_locale?: string;
|
|
29
|
+
tool: string;
|
|
30
|
+
page: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
5
34
|
interface TranslationProgress {
|
|
6
35
|
/**
|
|
7
36
|
* Progress percentage (0-100)
|
|
@@ -39,12 +68,22 @@ interface ModelDownloadProgress {
|
|
|
39
68
|
interface AITranslationContextValue {
|
|
40
69
|
ait: (text: string) => Promise<string>;
|
|
41
70
|
locale: string;
|
|
71
|
+
/** Company-level locale from environment metadata (e.g. `"de-DE"`). */
|
|
72
|
+
companyLocale?: string;
|
|
73
|
+
/** Project-level locale from environment metadata (e.g. `"fr-CA"`). */
|
|
74
|
+
projectLocale?: string;
|
|
42
75
|
renderVersion?: number;
|
|
43
76
|
/** Batch-translation progress; `null` while the queue is idle. */
|
|
44
77
|
translationProgress: TranslationProgress | null;
|
|
45
78
|
/** Chrome AI model download progress; `null` until a download begins. */
|
|
46
79
|
modelDownloadProgress: ModelDownloadProgress | null;
|
|
47
80
|
tool: string;
|
|
81
|
+
/** Called by `useAIAnalytics` with a fully assembled event. The MFE is responsible for sending it. */
|
|
82
|
+
onTrackAnalyticsEvent?: AIAnalyticsTracker;
|
|
83
|
+
/** Page context used to build the event key object segment (e.g. `'view'`, `'list_column_description'`). */
|
|
84
|
+
page?: string;
|
|
85
|
+
/** Feature scope: `'project'` or `'company'`. */
|
|
86
|
+
scope?: Scope;
|
|
48
87
|
}
|
|
49
88
|
|
|
50
89
|
interface ConfigurationResponse {
|
|
@@ -117,6 +156,59 @@ declare function useConfig(toolName: string, options?: UseConfigOptions): _tanst
|
|
|
117
156
|
*/
|
|
118
157
|
declare function useAITranslation(): AITranslationContextValue;
|
|
119
158
|
|
|
159
|
+
/** Button type identifiers for the event key `object` segment. */
|
|
160
|
+
declare const BUTTON_TYPE: {
|
|
161
|
+
readonly TRANSLATE: "translate";
|
|
162
|
+
readonly HIGHLIGHT: "highlight";
|
|
163
|
+
};
|
|
164
|
+
type ButtonType = (typeof BUTTON_TYPE)[keyof typeof BUTTON_TYPE];
|
|
165
|
+
/** Action identifiers for the event key `action` segment. */
|
|
166
|
+
declare const ACTION: {
|
|
167
|
+
readonly CLICKED: "clicked";
|
|
168
|
+
};
|
|
169
|
+
type Action = (typeof ACTION)[keyof typeof ACTION];
|
|
170
|
+
/**
|
|
171
|
+
* Builds the `object` segment: `{pageContext}_{buttonType}_button`
|
|
172
|
+
* e.g. `buildObject('view', 'translate')` → `'view_translate_button'`
|
|
173
|
+
*/
|
|
174
|
+
declare function buildObject(pageContext: string, buttonType: ButtonType): string;
|
|
175
|
+
/**
|
|
176
|
+
* Builds a fully-qualified event key:
|
|
177
|
+
* `ux.web.feature.{scope}.{tool}.{object}.{action}`
|
|
178
|
+
*/
|
|
179
|
+
declare function buildEventKey(parts: EventKeyParts): string;
|
|
180
|
+
interface BuildAnalyticEventParams {
|
|
181
|
+
scope: Scope;
|
|
182
|
+
tool: string;
|
|
183
|
+
/** Prefix for the object segment, matches the Provider `page` prop (e.g. `'view'`). */
|
|
184
|
+
pageContext: string;
|
|
185
|
+
buttonType: ButtonType;
|
|
186
|
+
baseProperties: AIAnalyticsEventProperties;
|
|
187
|
+
/** Defaults to `'clicked'` if omitted. */
|
|
188
|
+
action?: Action;
|
|
189
|
+
additionalProperties?: Record<string, unknown>;
|
|
190
|
+
}
|
|
191
|
+
/** Assembles a complete `AnalyticEvent` (key + merged properties) ready for `onTrackAnalyticsEvent`. */
|
|
192
|
+
declare function buildAnalyticEvent(params: BuildAnalyticEventParams): AnalyticEvent;
|
|
193
|
+
|
|
194
|
+
interface UseAIAnalyticsReturn {
|
|
195
|
+
/** Fires `ux.web.feature.{scope}.{tool}.{page}_translate_button.clicked`. */
|
|
196
|
+
trackTranslateButtonClicked: (additionalProperties?: Record<string, unknown>) => void;
|
|
197
|
+
/** Fires `ux.web.feature.{scope}.{tool}.{page}_highlight_button.clicked`. */
|
|
198
|
+
trackHighlightButtonClicked: (additionalProperties?: Record<string, unknown>) => void;
|
|
199
|
+
/** Generic tracking for custom button types or actions. */
|
|
200
|
+
trackCustomEvent: (buttonType: ButtonType | string, action?: Action | string, additionalProperties?: Record<string, unknown>) => void;
|
|
201
|
+
/** `true` when `onTrackAnalyticsEvent` was provided to `AITranslationProvider`. */
|
|
202
|
+
isTrackingEnabled: boolean;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns analytics tracking helpers pre-wired to the Provider context.
|
|
206
|
+
* All functions no-op if `onTrackAnalyticsEvent` was not supplied.
|
|
207
|
+
*
|
|
208
|
+
* @throws if called outside of an `AITranslationProvider`.
|
|
209
|
+
*/
|
|
210
|
+
declare function useAIAnalytics(): UseAIAnalyticsReturn;
|
|
211
|
+
|
|
120
212
|
interface AITranslationProviderProps {
|
|
121
213
|
children: ReactNode;
|
|
122
214
|
locale: string;
|
|
@@ -125,6 +217,16 @@ interface AITranslationProviderProps {
|
|
|
125
217
|
userId: number;
|
|
126
218
|
projectId: number;
|
|
127
219
|
enableAIT?: boolean;
|
|
220
|
+
/** Company-level locale from environment metadata (e.g. `"de-DE"`). Passed through to context for downstream consumers such as Amplitude. */
|
|
221
|
+
companyLocale?: string;
|
|
222
|
+
/** Project-level locale from environment metadata (e.g. `"fr-CA"`). Passed through to context for downstream consumers such as Amplitude. */
|
|
223
|
+
projectLocale?: string;
|
|
224
|
+
/** Called by `useAIAnalytics` with a pre-assembled event. The MFE sends it to the analytics API. */
|
|
225
|
+
onTrackAnalyticsEvent?: AIAnalyticsTracker;
|
|
226
|
+
/** Page context for the event key object segment (e.g. `'view'`, `'list_column_description'`). */
|
|
227
|
+
page?: string;
|
|
228
|
+
/** Feature scope: `'project'` or `'company'`. */
|
|
229
|
+
scope?: Scope;
|
|
128
230
|
}
|
|
129
231
|
declare function AITranslationProvider(props: AITranslationProviderProps): react_jsx_runtime.JSX.Element;
|
|
130
232
|
|
|
@@ -177,4 +279,4 @@ declare global {
|
|
|
177
279
|
var _BACKEND_AI_TRANSLATION_IN_PROGRESS_: boolean;
|
|
178
280
|
}
|
|
179
281
|
|
|
180
|
-
export { AITranslateText, type AITranslateTextProps, AITranslationProvider, AI_TRANSLATION_FEATURE_FLAG_KEY, type TranslatedIconProps, type UseConfigOptions, getAITranslationLDId, useAITranslation, useConfig };
|
|
282
|
+
export { ACTION, type AIAnalyticsEventProperties, type AIAnalyticsTracker, AITranslateText, type AITranslateTextProps, AITranslationProvider, AI_TRANSLATION_FEATURE_FLAG_KEY, type Action, type AnalyticEvent, BUTTON_TYPE, type BuildAnalyticEventParams, type ButtonType, type EventKeyParts, type Scope, type TranslatedIconProps, type UseAIAnalyticsReturn, type UseConfigOptions, buildAnalyticEvent, buildEventKey, buildObject, getAITranslationLDId, useAIAnalytics, useAITranslation, useConfig };
|