@mongodb-js/compass-web 0.20.2 → 0.21.0
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/bson-transpilers.js +1 -1
- package/dist/compass-web.d.ts +1638 -0
- package/dist/index.js +87 -66
- package/dist/mongodb-js__compass-components.js +34 -34
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +47 -38
- package/dist/atlas-auth-service.d.ts +0 -5
- package/dist/atlas-auth-service.d.ts.map +0 -1
- package/dist/connection-storage.d.ts +0 -68
- package/dist/connection-storage.d.ts.map +0 -1
- package/dist/entrypoint.d.ts +0 -76
- package/dist/entrypoint.d.ts.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts +0 -36
- package/dist/logger.d.ts.map +0 -1
- package/dist/preferences.d.ts +0 -14
- package/dist/preferences.d.ts.map +0 -1
- package/dist/url-builder.d.ts +0 -4
- package/dist/url-builder.d.ts.map +0 -1
|
@@ -0,0 +1,1638 @@
|
|
|
1
|
+
import { default as React_2 } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Valid statuses for activeOrLaunchedExperimentsToStatus
|
|
5
|
+
*/
|
|
6
|
+
declare enum ActiveOrLaunchedStatus {
|
|
7
|
+
LIVE = "LIVE",
|
|
8
|
+
COOLDOWN = "COOLDOWN",
|
|
9
|
+
LAUNCHED = "LAUNCHED"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Represents additional options for ExperimentSDK.addExistingExperimentData
|
|
14
|
+
*/
|
|
15
|
+
declare type AddExistingExperimentDataOptions<LoggerTeam> = BasicFunctionOptions<LoggerTeam>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Object parameter for ExperimentSDK.addExperimentCalls, which is a dev-env-only function
|
|
19
|
+
*/
|
|
20
|
+
declare interface AddExperimentCallsProps<T extends TypeData> {
|
|
21
|
+
assignmentCalls?: Partial<Record<T['experimentName'], Promise<AsyncStatus>>>;
|
|
22
|
+
allocationPointCalls?: Partial<Record<T['allocationPointName'], Promise<AsyncStatus>>>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare type AllPreferences = UserPreferences & CliOnlyPreferences & NonUserPreferences & PermanentFeatureFlags;
|
|
26
|
+
|
|
27
|
+
declare type AnyWorkspace = WelcomeWorkspace | MyQueriesWorkspace | DataModelingWorkspace | ShellWorkspace | ServerStatsWorkspace | DatabasesWorkspace | CollectionsWorkspace | CollectionWorkspace;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Represents additional options for ExperimentSDK.assignByPoints
|
|
31
|
+
* Right now it's aliased to the "AssignOptions" interface because the same options apply for this function.
|
|
32
|
+
* However, in the future if the 2 option interfaces diverge, feel free to define this as its own
|
|
33
|
+
* distinct interface.
|
|
34
|
+
*/
|
|
35
|
+
declare type AssignByPointsOptions<LoggerTeam> = BasicAPICallingFunctionOptions<LoggerTeam> & {
|
|
36
|
+
/**
|
|
37
|
+
* Set to true to use the entity generic mmsAssignByPointsV3 api method
|
|
38
|
+
*
|
|
39
|
+
* @default undefined which will use the deprecated mmsAssignByPoints api function instead when unspecified
|
|
40
|
+
*
|
|
41
|
+
* @todo remove this property after the deprecated mmsAssignByPoints api function is removed.
|
|
42
|
+
* Once the deprecated function is removed, by default all assignByPoints requests should be using v3.
|
|
43
|
+
*/
|
|
44
|
+
useV3Assignment?: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
declare type AssignExperimentFn = (experimentName: ExperimentTestName, options?: types.AssignOptions<string>) => Promise<types.AsyncStatus | null>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Entity assignment data. Used in {@link SDKAssignment}, {@link SDKGhostAssignment}, and {@link SDKGenericAssignment}
|
|
51
|
+
*/
|
|
52
|
+
declare interface AssignmentData<ExperimentVariantName> {
|
|
53
|
+
/**
|
|
54
|
+
* Represents if the entity has been allocated into the experiment. Should ALWAYS be used
|
|
55
|
+
* to check if an entity is allocated in an experiment--just checking for the presence of the experiment name key
|
|
56
|
+
* in SDK state isn't enough.
|
|
57
|
+
*/
|
|
58
|
+
isInSample: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* If the entity is allocated, the variant name they are assigned to.
|
|
61
|
+
* Can be null if they are not allocated in the experiment.
|
|
62
|
+
*/
|
|
63
|
+
variant: ExperimentVariantName | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare type AssignmentsMap<T extends TypeData> = Partial<Record<T['experimentName'], SDKAssignment<T['experimentName'], T['experimentVariantName']>>>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Represents additional options for ExperimentSDK.assign
|
|
70
|
+
*/
|
|
71
|
+
declare type AssignOptions<LoggerTeam> = BasicAPICallingFunctionOptions<LoggerTeam> & {
|
|
72
|
+
/**
|
|
73
|
+
* Specify the entity type to use with the new entity generic mmsAssignV3 api function
|
|
74
|
+
*
|
|
75
|
+
* @default undefined which will use the deprecated mmsAssign api function instead when unspecified
|
|
76
|
+
*
|
|
77
|
+
* @todo make this property required after the deprecated mmsAssign api function is removed.
|
|
78
|
+
* Once the deprecated function is removed, by default all assign requests will require an entity type
|
|
79
|
+
*/
|
|
80
|
+
entityTypeForV3Assignment?: EntityType;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A simple object representing the status of a response from an async call
|
|
85
|
+
*/
|
|
86
|
+
declare interface AsyncStatus {
|
|
87
|
+
statusCode: StatusCode;
|
|
88
|
+
message?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Atlas metadata for clusters, refer to the backend implementation to see how
|
|
93
|
+
* the values are derived
|
|
94
|
+
*
|
|
95
|
+
* https://github.com/10gen/mms/blob/1efe59a9bb4646635d946d979e5c9f4423f95b10/server/src/main/com/xgen/svc/mms/res/view/explorer/DataExplorerConnectionInfoView.java#L223-L302
|
|
96
|
+
*/
|
|
97
|
+
export declare interface AtlasClusterMetadata {
|
|
98
|
+
/**
|
|
99
|
+
* Atlas organization id
|
|
100
|
+
*/
|
|
101
|
+
orgId: string;
|
|
102
|
+
/**
|
|
103
|
+
* Project ID that uniquely identifies an Atlas project. Legacy name is
|
|
104
|
+
* "groupId" as projects were previously identified as "groups".
|
|
105
|
+
*
|
|
106
|
+
* https://www.mongodb.com/docs/atlas/api/atlas-admin-api-ref/#project-id
|
|
107
|
+
*/
|
|
108
|
+
projectId: string;
|
|
109
|
+
/**
|
|
110
|
+
* Unique id returned with the clusterDescription
|
|
111
|
+
*/
|
|
112
|
+
clusterUniqueId: string;
|
|
113
|
+
/**
|
|
114
|
+
* Cluster name, unique inside same project
|
|
115
|
+
*/
|
|
116
|
+
clusterName: string;
|
|
117
|
+
/**
|
|
118
|
+
* Possible types of Atlas clusters.
|
|
119
|
+
*
|
|
120
|
+
* https://github.com/10gen/mms/blob/9e6bf2d81d4d85b5ac68a15bf471dcddc5922323/client/packages/types/nds/clusterDescription.ts#L12-L16
|
|
121
|
+
*/
|
|
122
|
+
clusterType: 'REPLICASET' | 'SHARDED' | 'GEOSHARDED';
|
|
123
|
+
/**
|
|
124
|
+
* Cluster states
|
|
125
|
+
*
|
|
126
|
+
* `DELETED` is never returned from backend, but can be derived by connection
|
|
127
|
+
* missing when polling connection info list
|
|
128
|
+
*/
|
|
129
|
+
clusterState: 'CREATING' | 'UPDATING' | 'PAUSED' | 'IDLE' | 'REPAIRING' | 'DELETING' | 'DELETED';
|
|
130
|
+
/**
|
|
131
|
+
* A special id and type that are only relevant in context of mms metrics
|
|
132
|
+
* features. These are deployment items props (with a special exception for
|
|
133
|
+
* serverless, where id is just name, and type is `serverless` that doesn't
|
|
134
|
+
* make sense in context of deployments), not cluster description props.
|
|
135
|
+
|
|
136
|
+
* https://github.com/10gen/mms/blob/43b0049a85196b44e465feb9b96ef942d6f2c8f4/client/js/legacy/core/models/deployment
|
|
137
|
+
*/
|
|
138
|
+
metricsId: string;
|
|
139
|
+
/**
|
|
140
|
+
* Somewhat related to the clusterType provided as part of clusterDescription,
|
|
141
|
+
* but accounting for special shared cluster types. Used for `/metrics/*`
|
|
142
|
+
* routing and automation agent jobs
|
|
143
|
+
*
|
|
144
|
+
* - `cluster`: any sharded cluster type (sharded or geo sharded /
|
|
145
|
+
* "global writes" one)
|
|
146
|
+
* - `replicaSet`: anything that is not sharded (both dedicated or "free
|
|
147
|
+
* tier" / MTM)
|
|
148
|
+
* - `serverless`: specifically for serverless clusters
|
|
149
|
+
* - `flex`: new type that replaces serverless and some shared
|
|
150
|
+
* clusters
|
|
151
|
+
*/
|
|
152
|
+
metricsType: 'replicaSet' | 'cluster' | 'serverless' | 'flex';
|
|
153
|
+
/**
|
|
154
|
+
* Atlas API base url to be used when making control plane requests for a
|
|
155
|
+
* regionalized cluster. Always `null` while compass-web is disabled for
|
|
156
|
+
* those types of clusters
|
|
157
|
+
*/
|
|
158
|
+
regionalBaseUrl: null;
|
|
159
|
+
instanceSize?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Flags indicating Atlas cluster-level control plane feature support
|
|
162
|
+
*/
|
|
163
|
+
supports: {
|
|
164
|
+
/**
|
|
165
|
+
* True if cluster is geo sharded and not self managed
|
|
166
|
+
*/
|
|
167
|
+
globalWrites: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* True for dedicated clusters
|
|
170
|
+
*/
|
|
171
|
+
rollingIndexes: boolean;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
declare type AtlasOrgPreferences = {
|
|
176
|
+
enableGenAIFeaturesAtlasOrg: boolean;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
declare type AtlasProjectPreferences = {
|
|
180
|
+
enableGenAIFeaturesAtlasProject: boolean;
|
|
181
|
+
enableGenAISampleDocumentPassingOnAtlasProject: boolean;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
declare interface BasicAPICallingFunctionOptions<LoggerTeam> extends BasicFunctionOptions<LoggerTeam> {
|
|
185
|
+
/**
|
|
186
|
+
* An API timeout value, in milliseconds
|
|
187
|
+
* (if not passed, a default value of 5 seconds is used)
|
|
188
|
+
*/
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Shared props that all functions can provide in their "options" objects
|
|
194
|
+
*/
|
|
195
|
+
declare interface BasicFunctionOptions<LoggerTeam> {
|
|
196
|
+
/**
|
|
197
|
+
* The "team" value that should be used for the logger
|
|
198
|
+
* (if not passed, the "defaultTeam" from initialization is used)
|
|
199
|
+
*/
|
|
200
|
+
team?: LoggerTeam;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A standard response object from a hook with async calls.
|
|
205
|
+
*/
|
|
206
|
+
declare interface BasicHookResponse {
|
|
207
|
+
asyncStatus: HookAsyncStatus | null;
|
|
208
|
+
error: Error | null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare type CliOnlyPreferences = {
|
|
212
|
+
exportConnections?: string;
|
|
213
|
+
importConnections?: string;
|
|
214
|
+
passphrase?: string;
|
|
215
|
+
version?: boolean;
|
|
216
|
+
versions?: boolean;
|
|
217
|
+
help?: boolean;
|
|
218
|
+
showExampleConfig?: boolean;
|
|
219
|
+
trustedConnectionString?: boolean;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
declare type CollectionSubtab = 'Documents' | 'Aggregations' | 'Schema' | 'Indexes' | 'Validation' | 'GlobalWrites';
|
|
223
|
+
|
|
224
|
+
declare type CollectionsWorkspace = {
|
|
225
|
+
type: 'Collections';
|
|
226
|
+
connectionId: string;
|
|
227
|
+
namespace: string;
|
|
228
|
+
inferredFromPrivileges?: boolean;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export declare type CollectionTabInfo = {
|
|
232
|
+
isTimeSeries: boolean;
|
|
233
|
+
isReadonly: boolean;
|
|
234
|
+
sourceName?: string | null;
|
|
235
|
+
inferredFromPrivileges: boolean;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
declare type CollectionWorkspace = {
|
|
239
|
+
tabId: string;
|
|
240
|
+
type: 'Collection';
|
|
241
|
+
connectionId: string;
|
|
242
|
+
namespace: string;
|
|
243
|
+
subTab: CollectionSubtab;
|
|
244
|
+
initialQuery?: unknown;
|
|
245
|
+
initialPipeline?: unknown[];
|
|
246
|
+
initialPipelineText?: string;
|
|
247
|
+
initialAggregation?: unknown;
|
|
248
|
+
editViewName?: string;
|
|
249
|
+
inferredFromPrivileges?: boolean;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export declare const CompassExperimentationProvider: React_2.FC<{
|
|
253
|
+
children: React_2.ReactNode;
|
|
254
|
+
useAssignment: UseAssignmentHook;
|
|
255
|
+
assignExperiment: AssignExperimentFn;
|
|
256
|
+
}>;
|
|
257
|
+
|
|
258
|
+
/** @public */
|
|
259
|
+
export declare const CompassWeb: ({ appName, orgId, projectId, darkMode, initialAutoconnectId, initialWorkspace, onActiveWorkspaceTabChange, initialPreferences, onLog, onDebug, onTrack, onOpenConnectViaModal, onFailToLoadConnections, }: CompassWebProps) => React_2.JSX.Element;
|
|
260
|
+
|
|
261
|
+
/** @public */
|
|
262
|
+
export declare type CompassWebProps = {
|
|
263
|
+
/**
|
|
264
|
+
* App name to be passed with the connection string when connection to a
|
|
265
|
+
* cluster (default: "Compass Web")
|
|
266
|
+
*/
|
|
267
|
+
appName?: string;
|
|
268
|
+
/**
|
|
269
|
+
* Atlas Cloud organization id
|
|
270
|
+
*/
|
|
271
|
+
orgId: string;
|
|
272
|
+
/**
|
|
273
|
+
* Atlas Cloud project id (sometimes called group id)
|
|
274
|
+
*/
|
|
275
|
+
projectId: string;
|
|
276
|
+
/**
|
|
277
|
+
* Whether or not darkMode should be active for the app
|
|
278
|
+
*/
|
|
279
|
+
darkMode?: boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Optional. If passed, compass-web will try to find connection info with that
|
|
282
|
+
* id in connection storage and pass it as autoconnect info to the
|
|
283
|
+
* compass-connections
|
|
284
|
+
*/
|
|
285
|
+
initialAutoconnectId?: string;
|
|
286
|
+
/**
|
|
287
|
+
* Optional. If passed, compass-web will open provided workspace right away.
|
|
288
|
+
* If workspace requires active connection, the connectionId from the
|
|
289
|
+
* workspace will be used for the autoconnect info getter. In that case
|
|
290
|
+
* connectionId from the workspace takes precedence over
|
|
291
|
+
* `initialAutoconnectId`
|
|
292
|
+
*/
|
|
293
|
+
initialWorkspace?: OpenWorkspaceOptions;
|
|
294
|
+
/**
|
|
295
|
+
* Callback prop called when current active workspace changes. Can be used to
|
|
296
|
+
* communicate current workspace back to the parent component for example to
|
|
297
|
+
* sync router with the current active workspace
|
|
298
|
+
*/
|
|
299
|
+
onActiveWorkspaceTabChange<WS extends WorkspaceTab>(ws: WS | null, collectionInfo: WS extends {
|
|
300
|
+
type: 'Collection';
|
|
301
|
+
} ? CollectionTabInfo | null : never): void;
|
|
302
|
+
/**
|
|
303
|
+
* Set of initial preferences to override default values
|
|
304
|
+
*/
|
|
305
|
+
initialPreferences?: Partial<AllPreferences>;
|
|
306
|
+
/**
|
|
307
|
+
* Callback prop called every time any code inside Compass logs something
|
|
308
|
+
*/
|
|
309
|
+
onLog?: LogFunction;
|
|
310
|
+
/**
|
|
311
|
+
* Callback prop called every time any code inside Compass prints a debug
|
|
312
|
+
* statement
|
|
313
|
+
*/
|
|
314
|
+
onDebug?: DebugFunction;
|
|
315
|
+
/**
|
|
316
|
+
* Callback prop called for every track event inside Compass
|
|
317
|
+
*/
|
|
318
|
+
onTrack?: TrackFunction;
|
|
319
|
+
/**
|
|
320
|
+
* Callback prop that will be called with atlas metadata for a certain cluster
|
|
321
|
+
* when the action is selected from the sidebar actions. Should be used to
|
|
322
|
+
* show the Atlas Cloud "Connect" modal
|
|
323
|
+
*/
|
|
324
|
+
onOpenConnectViaModal?: (atlasMetadata?: AtlasClusterMetadata) => void;
|
|
325
|
+
/**
|
|
326
|
+
* Callback prop called when connections fail to load
|
|
327
|
+
*/
|
|
328
|
+
onFailToLoadConnections: (err: Error) => void;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Options to pass into the constructor
|
|
333
|
+
*/
|
|
334
|
+
declare interface ConstructorOptions<T extends TypeData> {
|
|
335
|
+
/** The entityId(s). Required. */
|
|
336
|
+
entityIds: EntityIds;
|
|
337
|
+
/** The environment the SDK is running in. Required. */
|
|
338
|
+
environment: Environment;
|
|
339
|
+
/** Logger-related properties */
|
|
340
|
+
loggerOptions?: LoggerOptions<T['loggerTeam']>;
|
|
341
|
+
/** Tracker-related properties */
|
|
342
|
+
trackerOptions?: TrackerOptions<T['experimentViewedProps']>;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
declare type DatabasesWorkspace = {
|
|
346
|
+
type: 'Databases';
|
|
347
|
+
connectionId: string;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
declare type DataModelingWorkspace = {
|
|
351
|
+
type: 'Data Modeling';
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/** @public */
|
|
355
|
+
export declare type DebugFunction = (...args: any[]) => void;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* A set of ID values. Each ID is treated as a distinct entity for experiments.
|
|
359
|
+
* Experiment configuration dictates which entity ID it will use for allocation.
|
|
360
|
+
*/
|
|
361
|
+
declare interface EntityIds {
|
|
362
|
+
/**
|
|
363
|
+
* All values below are strings representing an entity ID.
|
|
364
|
+
* Each of these should be serializeable to an "ObjectId",
|
|
365
|
+
* which is Mongodb's default ID class for a document.
|
|
366
|
+
* @example
|
|
367
|
+
* "621509aae911cb2e37ba91ca"
|
|
368
|
+
*/
|
|
369
|
+
orgId?: string;
|
|
370
|
+
groupId?: string;
|
|
371
|
+
userId?: string;
|
|
372
|
+
hostId?: string;
|
|
373
|
+
clusterId?: string;
|
|
374
|
+
tenantId?: string;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The different Entity units for experiments
|
|
379
|
+
*/
|
|
380
|
+
declare enum EntityType {
|
|
381
|
+
USER = "USER",
|
|
382
|
+
GROUP = "GROUP",
|
|
383
|
+
ORG = "ORG",
|
|
384
|
+
HOST = "HOST",
|
|
385
|
+
CLUSTER = "CLUSTER",
|
|
386
|
+
TENANT = "TENANT"
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* The different values of "environment" in the SDK
|
|
391
|
+
* This is used for, among other things, determining the root URL for backend calls
|
|
392
|
+
*/
|
|
393
|
+
declare enum Environment {
|
|
394
|
+
LOCAL = "local",
|
|
395
|
+
E2E = "e2e",
|
|
396
|
+
DEMOBOX = "demobox",
|
|
397
|
+
DEV = "dev",
|
|
398
|
+
QA = "qa",
|
|
399
|
+
PROD = "prod"
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Object parameter for ExperimentSDK.addExistingExperimentData
|
|
404
|
+
*/
|
|
405
|
+
declare interface ExistingData<T extends TypeData> {
|
|
406
|
+
assignments?: ServerAssignments<T>;
|
|
407
|
+
experimentAttributes?: ServerExperimentAttributeMap<T>;
|
|
408
|
+
ghostAssignments?: Array<ServerGhostAssignment<T['experimentName'], T['experimentVariantName']>>;
|
|
409
|
+
activeOrLaunchedExperimentsToStatus?: Partial<Record<T['experimentName'], ActiveOrLaunchedStatus>>;
|
|
410
|
+
allocationPointsToLiveOrLaunchedExperiments?: Partial<Record<T['allocationPointName'], Array<T['experimentName']>>>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Represents the types an Experiment Attribute in an experiment configuration can be.
|
|
415
|
+
*/
|
|
416
|
+
declare type ExperimentAttributeValue = string | boolean | number;
|
|
417
|
+
|
|
418
|
+
/** Class providing MDB Experiment SDK functionality */
|
|
419
|
+
declare class ExperimentSDK<T extends TypeData> {
|
|
420
|
+
#private;
|
|
421
|
+
/**
|
|
422
|
+
* @description
|
|
423
|
+
* Create an instance of the SDK. It's highly recommended to pass in a type interface
|
|
424
|
+
* as well for stronger typing of experiment data and log properties.
|
|
425
|
+
*
|
|
426
|
+
* Intended usage:
|
|
427
|
+
* Called by the ExperimentSDKClient class in index.ts. Should never be called directly by a user.
|
|
428
|
+
*
|
|
429
|
+
* @param {ConstructorOptions} options - Required
|
|
430
|
+
*
|
|
431
|
+
* @return {ExperimentSDK} An instance of the class
|
|
432
|
+
*
|
|
433
|
+
* @throws Can throw an error if entityIds, loggerOptions, or trackerOptions are invalid.
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* const options: ConstructorOptions = {
|
|
437
|
+
* entityIds: { orgId: 'iAmAnOrgId' },
|
|
438
|
+
* environment: Environment.DEV,
|
|
439
|
+
* };
|
|
440
|
+
*
|
|
441
|
+
* enum ExperimentName {
|
|
442
|
+
* EXP_ONE = 'expOne',
|
|
443
|
+
* };
|
|
444
|
+
*
|
|
445
|
+
* enum ExperimentVariantName {
|
|
446
|
+
* EXP_VARIANT_ONE = 'expVariantOne',
|
|
447
|
+
* };
|
|
448
|
+
*
|
|
449
|
+
* enum ExperimentAttributeName {
|
|
450
|
+
* SHOW_LEFT_NAV_LINK = 'showLeftNavLink',
|
|
451
|
+
* };
|
|
452
|
+
*
|
|
453
|
+
* enum AllocationPointName {
|
|
454
|
+
* CLUSTER_CARD_PAGE = 'CLUSTER_CARD_PAGE',
|
|
455
|
+
* };
|
|
456
|
+
*
|
|
457
|
+
* enum LoggerTeam {
|
|
458
|
+
* Team1 = 'Team 1',
|
|
459
|
+
* };
|
|
460
|
+
*
|
|
461
|
+
* interface Types {
|
|
462
|
+
* experimentName: ExperimentName,
|
|
463
|
+
* experimentVariantName: ExperimentVariantName,
|
|
464
|
+
* experimentAttributeName: ExperimentAttributeName,
|
|
465
|
+
* allocationPointName: AllocationPointName,
|
|
466
|
+
* loggerTeam: LoggerTeam,
|
|
467
|
+
* }
|
|
468
|
+
*
|
|
469
|
+
* const experimentSDK = new ExperimentSDK<Types>(options);
|
|
470
|
+
*/
|
|
471
|
+
constructor(options: ConstructorOptions<T>);
|
|
472
|
+
/**
|
|
473
|
+
* @description
|
|
474
|
+
* Retrieves non-experiment-data-related properties of the SDK. Returns deep clones of the props.
|
|
475
|
+
*
|
|
476
|
+
* Intended usage:
|
|
477
|
+
* Primarily for debugging and testing purposes. Not intended to allow mutating the instance props.
|
|
478
|
+
*
|
|
479
|
+
* @return
|
|
480
|
+
* An object containing copies of selected properties of the SDK:
|
|
481
|
+
* entityIds, loggerOptions, trackerOptions, and environment
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* const res = sdk.getProperties();
|
|
485
|
+
* console.log(res);
|
|
486
|
+
* {
|
|
487
|
+
entityIds: { orgId: 'iAmAnOrgId', groupId: 'iAmAGroupId', userId: 'iAmAUserId' },
|
|
488
|
+
loggerOptions: { logger: { log: [Function: log] }, defaultTeam: LoggerTeam.Team1 },
|
|
489
|
+
trackerOptions: { tracker: { track: [Function: track] } },
|
|
490
|
+
environment: 'dev'
|
|
491
|
+
}
|
|
492
|
+
*
|
|
493
|
+
*/
|
|
494
|
+
getProperties(): Readonly<GetPropertiesResponse<T>>;
|
|
495
|
+
/**
|
|
496
|
+
* @description
|
|
497
|
+
* If the updated entityIds are different from the existing entityIds, update the existing entityIds
|
|
498
|
+
* and clear assignmentsMap,experimentAttributesMap, assignmentCalls, allocationPointCalls.
|
|
499
|
+
* If the updated entityIds are the same, then no changes are made
|
|
500
|
+
*
|
|
501
|
+
* Intended usage:
|
|
502
|
+
* Updates the existing entityIds and clears existing experiment data
|
|
503
|
+
*
|
|
504
|
+
* @return The SDK itself
|
|
505
|
+
*
|
|
506
|
+
* @throws Can throw an error if the entityIds are invalid
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* const updatedEntities = { orgId: 'iAmAnOrgId', groupId: 'iAmAGroupId', userId: 'iAmAUserId' };
|
|
510
|
+
* const res = sdk.updateEntityIds(updatedEntities);
|
|
511
|
+
* const newSdkIds = res.getProperties().entityIds;
|
|
512
|
+
* console.log(newSdkIds);
|
|
513
|
+
* { orgId: 'iAmAnOrgId', groupId: 'iAmAGroupId', userId: 'iAmAUserId' }
|
|
514
|
+
*/
|
|
515
|
+
updateEntityIds(entities: EntityIds): ExperimentSDK<T>;
|
|
516
|
+
/**
|
|
517
|
+
* @description Updates loggerOptions on the SDK
|
|
518
|
+
*
|
|
519
|
+
* Intended usage:
|
|
520
|
+
* Updates the logger options for logging within the SDK
|
|
521
|
+
*
|
|
522
|
+
* @param {LoggerOptions} loggerOptions - Required
|
|
523
|
+
*
|
|
524
|
+
* @return {SdkInstance} An instance of the class
|
|
525
|
+
*
|
|
526
|
+
* @throws Can throw an error if the loggerOptions are invalid.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* enum LoggerTeam {
|
|
530
|
+
* Team1 = 'Test Team 1',
|
|
531
|
+
* };
|
|
532
|
+
*
|
|
533
|
+
* const updatedSDK = sdk.updateLoggerOptions({
|
|
534
|
+
* logger: loggerClient, // In MMS, this will be bugsnag
|
|
535
|
+
* defaultTeam: LoggerTeam.Team1
|
|
536
|
+
* })
|
|
537
|
+
*
|
|
538
|
+
* const newSdkLoggerOptions = res.getProperties().loggerOptions;
|
|
539
|
+
* console.log(newSdkLoggerOptions);
|
|
540
|
+
* { logger: loggerClient, defaultTeam: LoggerTeam.Team1 }
|
|
541
|
+
*/
|
|
542
|
+
updateLoggerOptions(loggerOptions: LoggerOptions<T['loggerTeam']>): this;
|
|
543
|
+
/**
|
|
544
|
+
* @description
|
|
545
|
+
* Update the Tracker object that makes analytics calls
|
|
546
|
+
*
|
|
547
|
+
* Intended usage:
|
|
548
|
+
* Updates the Tracker object that makes analytics calls if it needs to be changed,
|
|
549
|
+
* or set if it was not set during initialization
|
|
550
|
+
*
|
|
551
|
+
* @param {TrackerOptions} trackerOptions - Required
|
|
552
|
+
*
|
|
553
|
+
* @return {SdkInstance} An instance of the class
|
|
554
|
+
*
|
|
555
|
+
* @throws Can throw an error if the trackerOptions are invalid.
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* const newTracker = { track: () => {}}; // In MMS, this will be Heliotrope
|
|
559
|
+
* const newTrackerOptions = { tracker: newTracker };
|
|
560
|
+
* const newSdkTrackerOptions = experimentSdk.getProperties().trackerOptions;
|
|
561
|
+
* console.log(newSdkTrackerOptions);
|
|
562
|
+
* { tracker: { track: () => {} } }
|
|
563
|
+
*/
|
|
564
|
+
updateTrackerOptions(trackerOptions: TrackerOptions<T['experimentViewedProps']>): ExperimentSDK<T>;
|
|
565
|
+
/**
|
|
566
|
+
* @description
|
|
567
|
+
* Allows passing in existing experiment data (such as assignments, experiment attributes,
|
|
568
|
+
* ghost assignments, activeOrLaunchedExperimentsToStatus, and allocationPointsToLiveOrLaunchedExperiments)
|
|
569
|
+
* to populate the SDK state.
|
|
570
|
+
*
|
|
571
|
+
* This function
|
|
572
|
+
* - Checks if existing assignments, ghost assignments, or experiment attributes for the entity are
|
|
573
|
+
* attempting to be overwritten and if so, logs a warning and prioritizes the SDK's existing data.
|
|
574
|
+
* - Takes care of transforming "string" experiment attribute values into numbers and booleans as needed.
|
|
575
|
+
* - Loads in any experiment overrides provided by the FEdEx (go/fedex; Front End Experiment Editor)
|
|
576
|
+
* experiment editor extension. This behavior is only activated when the extension is active and
|
|
577
|
+
* writing overrides to sessionStorage.
|
|
578
|
+
* - If provided, ingests the activeOrLaunchedExperimentsToStatus and allocationPointsToLiveOrLaunchedExperiments
|
|
579
|
+
* maps to the SDK state in order to prevent unnecessary network requests for experiments (eg. only make Get
|
|
580
|
+
* assignment calls for Active or Launched experiments; only make assign calls for Live or Launched).
|
|
581
|
+
*
|
|
582
|
+
* Intended usage:
|
|
583
|
+
* Useful if the client has data about the state of experiments or an entity's assignments from another
|
|
584
|
+
* data store (such as the MMS "params" call) that it would like to make the SDK aware of
|
|
585
|
+
*
|
|
586
|
+
* @param {ExistingData} existingData - Required. Object with optional assignments,
|
|
587
|
+
* experimentAttributes, ghostAssignments, activeOrLaunchedExperimentsToStatus, and
|
|
588
|
+
* allocationPointsToLiveOrLaunchedExperiments properties.
|
|
589
|
+
* @param {AddExistingExperimentDataOptions} options - Optional. Object with additional optional props,
|
|
590
|
+
* such as a "team" override for logging purposes.
|
|
591
|
+
*
|
|
592
|
+
* @return {SdkInstance} An instance of the class
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* // ex 1: passing in full existingData object
|
|
596
|
+
* const { assignments, experimentAttributes, ghostAssignments } = clientApi.fetchExistingData(); // an external api
|
|
597
|
+
* experimentSdk.addExistingExperimentData({assignments, experimentAttributes, ghostAssignments },
|
|
598
|
+
* { team: LoggerTeam.Team1 });
|
|
599
|
+
*
|
|
600
|
+
* // ex 2: passing in an assignment
|
|
601
|
+
* const existingServerAssignment = {
|
|
602
|
+
* assignmentDate: '1658340252128',
|
|
603
|
+
* entityId: '621509aae911cb2e37ba91ca',
|
|
604
|
+
* entityType: 'ORG',
|
|
605
|
+
* id: '62d8439c9ce6473793cff6ca',
|
|
606
|
+
* tag: 'activation',
|
|
607
|
+
* testId: '62bb810b61be7d017fcc2198',
|
|
608
|
+
* testName: 'expOne',
|
|
609
|
+
* testGroupId: 'variantOne,
|
|
610
|
+
* testGroupDatabaseId: '62bb810b61be7d017fcc2196',
|
|
611
|
+
* };
|
|
612
|
+
*
|
|
613
|
+
* experimentSdk.addExistingExperimentData({
|
|
614
|
+
* assignments: [existingServerAssignment]
|
|
615
|
+
* });
|
|
616
|
+
*
|
|
617
|
+
* // ex 3: passing in an experiment attribute
|
|
618
|
+
* const existingAttribute = {
|
|
619
|
+
* showLeftNavLink: 'false',
|
|
620
|
+
* };
|
|
621
|
+
*
|
|
622
|
+
* experimentSdk.addExistingExperimentData({
|
|
623
|
+
* experimentAttributes: existingAttribute,
|
|
624
|
+
* });
|
|
625
|
+
*/
|
|
626
|
+
addExistingExperimentData(existingData: Readonly<ExistingData<T>>, options?: AddExistingExperimentDataOptions<T['loggerTeam']>): ExperimentSDK<T>;
|
|
627
|
+
/**
|
|
628
|
+
* @description
|
|
629
|
+
* Allows user to pass in a function to be called with all assignments, whenever the #assignmentsMap is updated.
|
|
630
|
+
*
|
|
631
|
+
* Intended usage:
|
|
632
|
+
* Allows for pubsub access to experiment assignments. Subscribers will have access to a clone of the assignment data.
|
|
633
|
+
*
|
|
634
|
+
* @param {function} subscriberCallback - Required. Function that will be called with {@link AssignmentsMap}, whenever
|
|
635
|
+
* a new assignment occurs.
|
|
636
|
+
*
|
|
637
|
+
* @return A function that can be called to unsubscribe from #assignmentsMap updates.
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* const subscriptionCb = (assignmentsMap) => {
|
|
641
|
+
* console.log('AB test AssignmentsMap has changed', assignmentsMap)
|
|
642
|
+
* };
|
|
643
|
+
*
|
|
644
|
+
* const unsubscribe = subscribeToAssignmentsMap(subscriptionCb);
|
|
645
|
+
*
|
|
646
|
+
* await sdk.assign(ExperimentName.EXP_ONE);
|
|
647
|
+
* // subscriptionCb will execute here, displaying the console log with the updated assignmentsMap.
|
|
648
|
+
*
|
|
649
|
+
* unsubscribe();
|
|
650
|
+
*
|
|
651
|
+
* await sdk.assign(ExperimentName.EXP_TWO);
|
|
652
|
+
* // subscriptionCb will not execute here, as the subscription has been removed.
|
|
653
|
+
*
|
|
654
|
+
*/
|
|
655
|
+
subscribeToAssignmentsMap(subscriberCallback: (assignmentsMap: AssignmentsMap<T>) => void): () => void;
|
|
656
|
+
/**
|
|
657
|
+
* @description
|
|
658
|
+
* Retrieves assignment data for a particular experiment name. This function will wait for the assign
|
|
659
|
+
* and assignByPoints function to finish retrieving data and return the assignment, or a Promise that
|
|
660
|
+
* resolves with null if entity is not in the experiment. If assignment data for an experiment name has not been
|
|
661
|
+
* or is not being retrieved by the assign or assignByPoints function, this function will make a GET request to MMS
|
|
662
|
+
* backend to get the assignment.
|
|
663
|
+
* If no assignment is found, this function will return a promise that resolves with null.
|
|
664
|
+
* If activeOrLaunchedExperimentsToStatus has been initialized, skips making network requests for experiments that
|
|
665
|
+
* are not in the map (active or LAUNCHED).
|
|
666
|
+
*
|
|
667
|
+
* When waiting for allocation point calls to resolve:
|
|
668
|
+
* - If allocationPointsToLiveOrLaunchedExperiments is not initialized, waits for all allocation point calls
|
|
669
|
+
* - If allocationPointsToLiveOrLaunchedExperiments is initialized, only waits for allocation point calls
|
|
670
|
+
* that are used by this experiment (i.e., the experiment name is in the array for that allocation point)
|
|
671
|
+
*
|
|
672
|
+
* If trackIsInSample (parameter of function) is set to true and the entity is in the experiment sample,
|
|
673
|
+
* trackIsInSample() will be called, which fires an Experiment Viewed event with default props and
|
|
674
|
+
* trackIsInSampleCustomProps (part of the 'options' parameter of this function).
|
|
675
|
+
*
|
|
676
|
+
* If there is an error, this function will log a warning and return a promise that resolves with null.
|
|
677
|
+
* (It will not throw an error.)
|
|
678
|
+
*
|
|
679
|
+
* This is the ONLY function in the SDK that retrieves experiment data.
|
|
680
|
+
*
|
|
681
|
+
* Intended usage:
|
|
682
|
+
* Used to get an entity's assignment information for an experiment.
|
|
683
|
+
*
|
|
684
|
+
* @param {ExperimentName} experimentName - Required
|
|
685
|
+
* @param {boolean} trackIsInSample - Required
|
|
686
|
+
* @param {GetAssignmentOptions} options - Optional. User of this function can pass in an optional
|
|
687
|
+
* customProps object if they want the Experiment Viewed event to have custom properties and/or pass in a team
|
|
688
|
+
* if they want the logger to log for a specific team
|
|
689
|
+
*
|
|
690
|
+
* @return A Promise that resolves to either an {@link SDKAssignment} object or null (if the assignment info does not
|
|
691
|
+
* exist, because entity is not in experiment, data has not been fetched, or the pending assignment call errored out).
|
|
692
|
+
* Even if the Promise resolves to an SDKAssignment object, the entity may not be in the experiment
|
|
693
|
+
* --check {@link SDKAssignment.assignmentData.isInSample} to be sure.
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* const experimentName: ExperimentName = ExperimentName.EXP_ONE;
|
|
697
|
+
* const getAssignmentOptions: GetAssignmentOptions<Types> = {
|
|
698
|
+
trackIsInSampleCustomProps:{
|
|
699
|
+
firstProperty: 1,
|
|
700
|
+
secondProperty: '2',
|
|
701
|
+
},
|
|
702
|
+
team: 'Team 1',
|
|
703
|
+
}
|
|
704
|
+
* const res: SDKAssignment<Types['experimentName'], Types['experimentVariantName']> | null =
|
|
705
|
+
* await sdk.getAssignment(experimentName, false, getAssignmentOptions);
|
|
706
|
+
* console.log(res);
|
|
707
|
+
* {
|
|
708
|
+
assignmentData: { isInSample: true, variant: 'expVariantOne' },
|
|
709
|
+
experimentData: {
|
|
710
|
+
assignmentDate: '1658340252128',
|
|
711
|
+
entityId: '621509aae911cb2e37ba91ca',
|
|
712
|
+
entityType: 'ORG',
|
|
713
|
+
id: '62d8439c9ce6473793cff6ca',
|
|
714
|
+
tag: 'activation',
|
|
715
|
+
testId: '62bb810b61be7d017fcc2198',
|
|
716
|
+
testName: 'expOne',
|
|
717
|
+
testGroupId: 'expVariantOne',
|
|
718
|
+
testGroupDatabaseId: '62bb810b61be7d017fcc2196'
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
*
|
|
722
|
+
*/
|
|
723
|
+
getAssignment(experimentName: T['experimentName'], trackIsInSample: boolean, options?: GetAssignmentOptions<T>): Promise<SDKAssignment<T['experimentName'], T['experimentVariantName']> | null>;
|
|
724
|
+
/**
|
|
725
|
+
* @description
|
|
726
|
+
* DO NOT USE!
|
|
727
|
+
* Gets a stored assignment object for a given experiment name.
|
|
728
|
+
* This is only meant to be used by internal tools! In real world applications,
|
|
729
|
+
* you should always use the async getAssignment function, to ensure that a cache miss is
|
|
730
|
+
* never misinterpreted as a null assignment.
|
|
731
|
+
* @param {T['experimentName']} experimentName The name of the experiment
|
|
732
|
+
* @return The assignment object if it exists in the cache, or null if not
|
|
733
|
+
*/
|
|
734
|
+
unsafe_getCachedAssignment(experimentName: T['experimentName']): SDKAssignment<T['experimentName'], T['experimentVariantName']> | null;
|
|
735
|
+
/**
|
|
736
|
+
* @description
|
|
737
|
+
* Given an experiment attribute name and a fallback value, returns the value for attributeName from the
|
|
738
|
+
* local SDK state experimentAttributesMap, or the fallback value if none exists
|
|
739
|
+
*
|
|
740
|
+
* Intended usage:
|
|
741
|
+
* To retrieve experiment attributes.
|
|
742
|
+
*
|
|
743
|
+
* @param attributeName - Required. The attribute name.
|
|
744
|
+
* @param {ExperimentAttributeValue} fallbackValue - Required. The fallback value to be returned if attributeName does
|
|
745
|
+
* not exist in local SDK state experimentAttributesMap.
|
|
746
|
+
*
|
|
747
|
+
* @return An ExperimentAttributeValue for attributeName or fallbackValue if none exists.
|
|
748
|
+
*
|
|
749
|
+
* @example
|
|
750
|
+
* const attr: ExperimentAttributeValue = sdk.getExperimentAttribute(
|
|
751
|
+
* ExperimentAttributeName.SHOW_LEFT_NAV_LINK,
|
|
752
|
+
* false
|
|
753
|
+
* );
|
|
754
|
+
* console.log(attr);
|
|
755
|
+
* // true
|
|
756
|
+
*/
|
|
757
|
+
getExperimentAttribute(attributeName: T['experimentAttributeName'], fallbackValue: ExperimentAttributeValue): ExperimentAttributeValue;
|
|
758
|
+
/**
|
|
759
|
+
* @description
|
|
760
|
+
* Given an experiment name, returns a Promise that is successfully resolved if the experiment is
|
|
761
|
+
* successfully assigned, via the API if needed, for the SDK entity.
|
|
762
|
+
*
|
|
763
|
+
* If the API call has an error during assignment, this function should log the error message
|
|
764
|
+
* and return a rejected Promise with the error. In these cases, the function will "clean up" the errored API call
|
|
765
|
+
* so that the assignment can be reattempted by another "assign" call later if the user wishes.
|
|
766
|
+
*
|
|
767
|
+
* If there is an existing Promise for the experiment, the function will not make an API call and will return
|
|
768
|
+
* the existing Promise. If there is no existing Promise but the assignment or ghost assignment already exists,
|
|
769
|
+
* the function will not make an API call and a resolved Promise will be returned.
|
|
770
|
+
* If the activeOrLaunchedExperimentsToStatus map has been initialized and the experiment is in not in the map
|
|
771
|
+
* as LIVE or LAUNCHED, skips making a network request to assign.
|
|
772
|
+
*
|
|
773
|
+
* CAN make a POST API call.
|
|
774
|
+
* (For more information on the POST API call, see the
|
|
775
|
+
* [wiki](https://wiki.corp.mongodb.com/display/MMS/MDB+Experiment+JS+SDK+Usage))
|
|
776
|
+
*
|
|
777
|
+
* Does NOT return assignment information--users should use the getAssignment function for that.
|
|
778
|
+
*
|
|
779
|
+
* Intended usage:
|
|
780
|
+
* Assign the SDK entity for an experiment.
|
|
781
|
+
* Can only take 1 experiment name per call. (If you are looking to pass multiple experiment names in 1 call,
|
|
782
|
+
* perhaps that means this experiment allocation point should be a reusable allocation point.)
|
|
783
|
+
*
|
|
784
|
+
* @param experimentName - Required. An experiment name string.
|
|
785
|
+
* @param {AssignOptions} options - Optional. Object with additional optional props, such as a "team" override
|
|
786
|
+
* for logging purposes and a timeoutMs prop to define the API timeout.
|
|
787
|
+
*
|
|
788
|
+
* @return A Promise that resolves to an AsyncStatus object. If the Promise resolves, the AsyncStatus
|
|
789
|
+
* object should represent success. In case of error, the Promise will reject.
|
|
790
|
+
*
|
|
791
|
+
* @throws Can throw an error if the API call throws an error.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* const experimentName: ExperimentName = ExperimentName.EXP_ONE;
|
|
795
|
+
*
|
|
796
|
+
* const options: AssignOptions<Types['loggerTeam']> = {
|
|
797
|
+
* team: LoggerOptions.Team1,
|
|
798
|
+
* };
|
|
799
|
+
*
|
|
800
|
+
* try {
|
|
801
|
+
* await sdk.assign(experimentName, options);
|
|
802
|
+
* } catch (e) {
|
|
803
|
+
* // error handling in case the promise rejects. In this case, assume
|
|
804
|
+
* // the assignment data is not available in the SDK. Can retry, bubble up the error, etc.
|
|
805
|
+
* }
|
|
806
|
+
*
|
|
807
|
+
* // at this point, can assume assignment info for this experiment is in the SDK so can retrieve the assignment
|
|
808
|
+
* const assignment: SDKAssignment<Types['experimentName'], Types['experimentVariantName']> | null =
|
|
809
|
+
* await sdk.getAssignment(
|
|
810
|
+
* ExperimentName.EXP_ONE,
|
|
811
|
+
* true,
|
|
812
|
+
* options as GetAssignmentOptions<Types>
|
|
813
|
+
* );
|
|
814
|
+
* // see getAssignment documentation for more details on using that function
|
|
815
|
+
*/
|
|
816
|
+
assign(experimentName: T['experimentName'], options?: AssignOptions<T['loggerTeam']>): Promise<AsyncStatus>;
|
|
817
|
+
/**
|
|
818
|
+
* @description
|
|
819
|
+
* Given an array of allocation point names, returns a Promise that is successfully resolved if all the experiments
|
|
820
|
+
* associated with the given points are successfully assigned via the API for the SDK entity.
|
|
821
|
+
* If ANY of the points in the given array is NOT successfully assigned, this function should log the error message
|
|
822
|
+
* and return a rejected Promise with the error. In these cases, the function will "clean up" the errored API call
|
|
823
|
+
* so that the point assignment can be reattempted by another "assignByPoints" call later if the user wishes.
|
|
824
|
+
* If a point was previously successfully assigned or if the promise is currently pending,
|
|
825
|
+
* the function will not make another API call for that point and will use the existing Promise for that point.
|
|
826
|
+
* If allocationPointsToLiveOrLaunchedExperiments is initialized, it will not make API calls for points that do not
|
|
827
|
+
* map to at least 1 experiment.
|
|
828
|
+
*
|
|
829
|
+
* CAN make a POST API call.
|
|
830
|
+
* (For more information on the POST API call, see the
|
|
831
|
+
* [wiki](https://wiki.corp.mongodb.com/display/MMS/MDB+Experiment+JS+SDK+Usage))
|
|
832
|
+
*
|
|
833
|
+
* Does NOT return assignment information--users should use the getAssignment function for that.
|
|
834
|
+
*
|
|
835
|
+
* Intended usage:
|
|
836
|
+
* Assign entities for experiments configured to use reusable allocation points.
|
|
837
|
+
* Can take multiple points in 1 request.
|
|
838
|
+
*
|
|
839
|
+
* @param allocationPoints - Required. An array of allocation point name strings.
|
|
840
|
+
* @param {AssignByPointsOptions} options - Optional. Object with additional optional props, such as a "team" override
|
|
841
|
+
* for logging purposes and a timeoutMs prop to define the API timeout.
|
|
842
|
+
*
|
|
843
|
+
* @return A Promise that resolves to an array of AsyncStatus objects. If the Promise resolves, all the AsyncStatus
|
|
844
|
+
* objects should represent success. In case of error, the Promise will reject.
|
|
845
|
+
*
|
|
846
|
+
* @throws Can throw an error if the API call throws an error.
|
|
847
|
+
*
|
|
848
|
+
* @example
|
|
849
|
+
* const allocationPointsArray: Array<AllocationPointName> = [
|
|
850
|
+
* AllocationPointName.CLUSTER_CARD_PAGE,
|
|
851
|
+
* AllocationPointName.REGISTRATION_SUCCESS_PAGE,
|
|
852
|
+
* ];
|
|
853
|
+
*
|
|
854
|
+
* const options: AssignByPointsOptions<Types['loggerTeam']> = {
|
|
855
|
+
* team: LoggerTeam.Team1,
|
|
856
|
+
* };
|
|
857
|
+
*
|
|
858
|
+
* try {
|
|
859
|
+
* await sdk.assignByPoints(allocationPointsArray, options);
|
|
860
|
+
* } catch (e) {
|
|
861
|
+
* // error handling in case the promise rejects. In this case, assume
|
|
862
|
+
* // the assignment data is not available in the SDK. Can retry, bubble up the error, etc.
|
|
863
|
+
* }
|
|
864
|
+
*
|
|
865
|
+
* // at this point, can assume assignment information for those points is in the SDK so can retrieve assignments
|
|
866
|
+
* const assignment: SDKAssignment<Types['experimentName'], Types['experimentVariantName']> | null =
|
|
867
|
+
* await sdk.getAssignment(
|
|
868
|
+
* 'experiment_that_was_allocated_with_allocation_points',
|
|
869
|
+
* true,
|
|
870
|
+
* options as GetAssignmentOptions<Types>
|
|
871
|
+
* );
|
|
872
|
+
* // see getAssignment documentation for more details on using that function
|
|
873
|
+
*/
|
|
874
|
+
assignByPoints(allocationPoints: Array<T['allocationPointName']>, options?: AssignByPointsOptions<T['loggerTeam']>): Promise<Array<AsyncStatus>>;
|
|
875
|
+
/**
|
|
876
|
+
* @description
|
|
877
|
+
* Submits an "Experiment Viewed" or "Experiment GhostViewed" event with the client's tracker (if any).
|
|
878
|
+
* Sends through default props ({@link ExperimentViewedBaseEvent}) and any custom props defined.
|
|
879
|
+
* Will wait for relevant pending assignment calls to resolve to get assignment data.
|
|
880
|
+
* (If there is an error, will log it but try to continue.) If there isn't a tracker or if
|
|
881
|
+
* the assignment data or assignment call doesn't exist, it will log a warning and result in a no-op.
|
|
882
|
+
*
|
|
883
|
+
* Any error encountered in the client's track call will be bubbled up.
|
|
884
|
+
*
|
|
885
|
+
* Intended usage:
|
|
886
|
+
* Fires the "Experiment Viewed" event using the client's tracker, if the client tracker
|
|
887
|
+
* has been initialized and the entity is in the experiment, OR
|
|
888
|
+
* Fires the "Experiment GhostViewed" event using the client's tracker, if the client tracker
|
|
889
|
+
* has been initialized and the entity is in an Experiment Holdout but has a ghost assignment
|
|
890
|
+
* for the experiment.
|
|
891
|
+
*
|
|
892
|
+
* @param {ExperimentName} experimentName - Required
|
|
893
|
+
* @param {Object} customProps - Optional. User of this function can pass in an optional
|
|
894
|
+
* customProps object if they want the Experiment Viewed/GhostViewed event to have custom
|
|
895
|
+
* properties in addition to the default experiment props ({@link ExperimentViewedBaseEvent})
|
|
896
|
+
*
|
|
897
|
+
* @return {Promise<AsyncStatus|null>}
|
|
898
|
+
* If there is a no op, returns a Promise that resolves with null.
|
|
899
|
+
* Else if there is an error with the client's track call, throws an error.
|
|
900
|
+
* Else if there is no error and track was called successfully, returns a Promise
|
|
901
|
+
* that resolves with a 2XX code.
|
|
902
|
+
*
|
|
903
|
+
* @throws Can throw an error if the registered Tracker's track function throws an error.
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* const experimentName = "experimentNameExample";
|
|
907
|
+
* const customProps = { property1: true, property2: 0 };
|
|
908
|
+
* const res: <AsyncStatus | null> = await sdk.trackIsInSample(experimentName, customProps);
|
|
909
|
+
* if(res?.statusCode === 200) {
|
|
910
|
+
* console.log("track call succeeded");
|
|
911
|
+
* }
|
|
912
|
+
*/
|
|
913
|
+
trackIsInSample(experimentName: T['experimentName'], customProps?: T['experimentViewedProps'], team?: string): Promise<AsyncStatus | null>;
|
|
914
|
+
/**
|
|
915
|
+
* @description
|
|
916
|
+
* Intended for TESTING USAGE ONLY. Populates the #assignmentCalls and #allocationPointCalls maps.
|
|
917
|
+
* This function only works in DEV and LOCAL environments.
|
|
918
|
+
*
|
|
919
|
+
* Intended usage:
|
|
920
|
+
* Used for tests for setting up SDK internal state to test certain scenarios.
|
|
921
|
+
*
|
|
922
|
+
* @param {AddExperimentCallsProps} - Required. an object containing optional assignmentCalls and
|
|
923
|
+
* allocationPointCalls props
|
|
924
|
+
*/
|
|
925
|
+
addExperimentCalls({ assignmentCalls, allocationPointCalls }: AddExperimentCallsProps<T>): void;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Context values.
|
|
930
|
+
*/
|
|
931
|
+
declare interface ExperimentSDKContextType<T extends TypeData> {
|
|
932
|
+
/**
|
|
933
|
+
* An instance of the {@link ExperimentSDK}. "null" by default.
|
|
934
|
+
*/
|
|
935
|
+
sdkInstance: ExperimentSDK<T> | null;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Context provider properties.
|
|
940
|
+
* Takes in {@link ExperimentSDKContextType} values, plus the React "children" property
|
|
941
|
+
*/
|
|
942
|
+
declare type ExperimentSDKProviderProps<T extends TypeData> = React.PropsWithChildren<ExperimentSDKContextType<T>>;
|
|
943
|
+
|
|
944
|
+
declare enum ExperimentTestName {
|
|
945
|
+
earlyJourneyIndexesGuidance = "EARLY_JOURNEY_INDEXES_GUIDANCE_20250328",
|
|
946
|
+
mockDataGenerator = "MOCK_DATA_GENERATOR_20251001"
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
declare enum ExperimentViewedEventName {
|
|
950
|
+
EXPERIMENT_VIEWED = "Experiment Viewed",
|
|
951
|
+
EXPERIMENT_GHOSTVIEWED = "Experiment GhostViewed"
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
declare type FeatureFlags = {
|
|
955
|
+
enableOidc: boolean;
|
|
956
|
+
newExplainPlan: boolean;
|
|
957
|
+
showInsights: boolean;
|
|
958
|
+
enableExportSchema: boolean;
|
|
959
|
+
enableRenameCollectionModal: boolean;
|
|
960
|
+
enableProxySupport: boolean;
|
|
961
|
+
enableRollingIndexes: boolean;
|
|
962
|
+
showDisabledConnections: boolean;
|
|
963
|
+
enableGlobalWrites: boolean;
|
|
964
|
+
enableDataModeling: boolean;
|
|
965
|
+
enableIndexesGuidanceExp: boolean;
|
|
966
|
+
showIndexesGuidanceVariant: boolean;
|
|
967
|
+
enableContextMenus: boolean;
|
|
968
|
+
enableSearchActivationProgramP1: boolean;
|
|
969
|
+
enableUnauthenticatedGenAI: boolean;
|
|
970
|
+
enableAIAssistant: boolean;
|
|
971
|
+
enablePerformanceInsightsEntrypoints: boolean;
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Represents additional options for ExperimentSDK.getAssignments
|
|
976
|
+
*/
|
|
977
|
+
declare interface GetAssignmentOptions<T extends TypeData> extends BasicAPICallingFunctionOptions<T['loggerTeam']> {
|
|
978
|
+
/**
|
|
979
|
+
* Custom properties that will be passed to "trackIsInSample" to be used in the
|
|
980
|
+
* "Experiment Viewed" call
|
|
981
|
+
*/
|
|
982
|
+
trackIsInSampleCustomProps?: T['experimentViewedProps'];
|
|
983
|
+
/**
|
|
984
|
+
* Set to true to use the entity generic mmsGetAssignmentV3 api method
|
|
985
|
+
*
|
|
986
|
+
* @default undefined which will use the deprecated mmsGetAssignment api function instead when unspecified
|
|
987
|
+
*
|
|
988
|
+
* @todo remove this property after the deprecated mmsGetAssignment api function is removed.
|
|
989
|
+
* Once the deprecated function is removed, by default all getAssignment requests should be using v3.
|
|
990
|
+
*/
|
|
991
|
+
useV3Assignment?: boolean;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Response object from ExperimentSDK.getProperties
|
|
996
|
+
* (Very similar to {@link ConstructorOptions} except Logger and TrackerOptions can be null)
|
|
997
|
+
*/
|
|
998
|
+
declare interface GetPropertiesResponse<T extends TypeData> {
|
|
999
|
+
/** The entityId(s) of the SDK instance. */
|
|
1000
|
+
entityIds: EntityIds;
|
|
1001
|
+
/** Logger-related properties of the SDK instance */
|
|
1002
|
+
loggerOptions: LoggerOptions<T['loggerTeam']> | null;
|
|
1003
|
+
/** Tracker-related properties of the SDK instance */
|
|
1004
|
+
trackerOptions: TrackerOptions<T['experimentViewedProps']> | null;
|
|
1005
|
+
/** The environment of the SDK instance.. */
|
|
1006
|
+
environment: Environment;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/** @public */
|
|
1010
|
+
export declare function getRouteFromWorkspaceTab(tab: WorkspaceTab | null): string;
|
|
1011
|
+
|
|
1012
|
+
/** @public */
|
|
1013
|
+
export declare function getWorkspaceTabFromRoute(route: string): OpenWorkspaceOptions | null;
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* Valid values to represent the lifecycle of a hook with an async call.
|
|
1017
|
+
* "null" is the default status when a hook is initialized
|
|
1018
|
+
*/
|
|
1019
|
+
declare enum HookAsyncStatus {
|
|
1020
|
+
LOADING = "LOADING",
|
|
1021
|
+
SUCCESS = "SUCCESS",
|
|
1022
|
+
ERROR = "ERROR"
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Internally used preferences that are not configurable by users.
|
|
1027
|
+
*/
|
|
1028
|
+
declare type InternalUserPreferences = {
|
|
1029
|
+
showedNetworkOptIn: boolean;
|
|
1030
|
+
id: string;
|
|
1031
|
+
cloudFeatureRolloutAccess?: {
|
|
1032
|
+
GEN_AI_COMPASS?: boolean;
|
|
1033
|
+
};
|
|
1034
|
+
lastKnownVersion: string;
|
|
1035
|
+
highestInstalledVersion?: string;
|
|
1036
|
+
currentUserId?: string;
|
|
1037
|
+
telemetryAnonymousId?: string;
|
|
1038
|
+
telemetryAtlasUserId?: string;
|
|
1039
|
+
userCreatedAt: number;
|
|
1040
|
+
enableConnectInNewWindow: boolean;
|
|
1041
|
+
showEndOfLifeConnectionModal: boolean;
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* The interface for a log message + metadata, for use with the {@link Logger}.
|
|
1046
|
+
*/
|
|
1047
|
+
declare interface Log<LoggerTeam> {
|
|
1048
|
+
logMessage: string;
|
|
1049
|
+
severity: Severity;
|
|
1050
|
+
team?: LoggerTeam;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/** @public */
|
|
1054
|
+
export declare type LogFunction = (message: LogMessage) => void;
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* A Logger object that can be used to monitor SDK health.
|
|
1058
|
+
*/
|
|
1059
|
+
declare interface Logger<LoggerTeam> {
|
|
1060
|
+
/**
|
|
1061
|
+
* @description
|
|
1062
|
+
* Function to log a message to a log store
|
|
1063
|
+
*
|
|
1064
|
+
* Intended usage:
|
|
1065
|
+
* Call this to log
|
|
1066
|
+
*
|
|
1067
|
+
* @param {string} logMessage - Required
|
|
1068
|
+
* @param {Severity} severity - Required
|
|
1069
|
+
* @param {LoggerTeam} team
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* enum LoggerTeam {
|
|
1073
|
+
* Team1 = 'Test Team 1',
|
|
1074
|
+
* };
|
|
1075
|
+
*
|
|
1076
|
+
* Logger.log({
|
|
1077
|
+
* logMessage: 'There was an error',
|
|
1078
|
+
* severity: Severity.ERROR,
|
|
1079
|
+
* team: LoggerTeam.Team1
|
|
1080
|
+
* });
|
|
1081
|
+
*/
|
|
1082
|
+
log: ({ logMessage, severity, team }: Log<LoggerTeam>) => void;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Object representing Logger object and logging-related properties
|
|
1087
|
+
*/
|
|
1088
|
+
declare interface LoggerOptions<LoggerTeam> {
|
|
1089
|
+
/** A Logger */
|
|
1090
|
+
logger: Logger<LoggerTeam>;
|
|
1091
|
+
/** The default team a log should be assigned to */
|
|
1092
|
+
defaultTeam: LoggerTeam;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/** @public */
|
|
1096
|
+
export declare type LogMessage = {
|
|
1097
|
+
id: number;
|
|
1098
|
+
t: {
|
|
1099
|
+
$date: string;
|
|
1100
|
+
};
|
|
1101
|
+
s: 'F' | 'E' | 'W' | 'I' | 'D1' | 'D2' | 'D3' | 'D4' | 'D5';
|
|
1102
|
+
c: string;
|
|
1103
|
+
ctx: string;
|
|
1104
|
+
msg: string;
|
|
1105
|
+
attr?: any;
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
declare type MyQueriesWorkspace = {
|
|
1109
|
+
type: 'My Queries';
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
declare type NonUserPreferences = {
|
|
1113
|
+
ignoreAdditionalCommandLineFlags?: boolean;
|
|
1114
|
+
positionalArguments?: string[];
|
|
1115
|
+
file?: string;
|
|
1116
|
+
username?: string;
|
|
1117
|
+
password?: string;
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
export declare type OpenWorkspaceOptions = Pick<Workspace<'Welcome'>, 'type'> | Pick<Workspace<'My Queries'>, 'type'> | Pick<Workspace<'Data Modeling'>, 'type'> | Pick<Workspace<'Shell'>, 'type' | 'connectionId' | 'initialEvaluate' | 'initialInput'> | Pick<Workspace<'Databases'>, 'type' | 'connectionId'> | Pick<Workspace<'Performance'>, 'type' | 'connectionId'> | Pick<Workspace<'Collections'>, 'type' | 'connectionId' | 'namespace'> | (Pick<Workspace<'Collection'>, 'type' | 'connectionId' | 'namespace'> & Partial<Pick<Workspace<'Collection'>, 'initialQuery' | 'initialAggregation' | 'initialPipeline' | 'initialPipelineText' | 'editViewName'>> & {
|
|
1121
|
+
initialSubtab?: CollectionSubtab;
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
declare type PermanentFeatureFlags = {
|
|
1125
|
+
showDevFeatureFlags?: boolean;
|
|
1126
|
+
enableDebugUseCsfleSchemaMap?: boolean;
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* An experiment assignment for a given entity and experiment in the SDK.
|
|
1131
|
+
* This represents an assignment object in {@link ExperimentSDK.#assignmentsMap}
|
|
1132
|
+
*/
|
|
1133
|
+
declare interface SDKAssignment<ExperimentName, ExperimentVariantName> {
|
|
1134
|
+
/**
|
|
1135
|
+
* Critical data about the specific entity's assignment
|
|
1136
|
+
*/
|
|
1137
|
+
assignmentData: AssignmentData<ExperimentVariantName>;
|
|
1138
|
+
/**
|
|
1139
|
+
* All the information from the server about the experiment and the entity's assignment
|
|
1140
|
+
*/
|
|
1141
|
+
experimentData: ServerAssignment<ExperimentName, ExperimentVariantName>;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* An experiment attribute in the SDK.
|
|
1146
|
+
* This represents an experiment attribute object in {@link ExperimentSDK.#experimentAttributesMap}
|
|
1147
|
+
*/
|
|
1148
|
+
declare type SDKExperimentAttributes<ExperimentAttributeName extends string> = {
|
|
1149
|
+
[key in ExperimentAttributeName]?: ExperimentAttributeValue;
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* A GHOST experiment assignment for a given entity and experiment in the SDK.
|
|
1154
|
+
* This represents an assignment object in {@link ExperimentSDK.#ghostAssignmentsMap}
|
|
1155
|
+
*/
|
|
1156
|
+
declare interface SDKGhostAssignment<ExperimentName, ExperimentVariantName> {
|
|
1157
|
+
/**
|
|
1158
|
+
* Critical data about the specific entity's assignment
|
|
1159
|
+
*/
|
|
1160
|
+
assignmentData: AssignmentData<ExperimentVariantName>;
|
|
1161
|
+
/**
|
|
1162
|
+
* All the information from the server about the experiment and the entity's GHOST assignment
|
|
1163
|
+
*/
|
|
1164
|
+
experimentData: ServerGhostAssignment<ExperimentName, ExperimentVariantName>;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* An experiment assignment for a given entity and experiment.
|
|
1169
|
+
* This represents the raw assignment data fed into {@link ExperimentSDK.addExistingExperimentData}.
|
|
1170
|
+
* (FYI The below interface is taken from MMS: packages/types/abTest.ts)
|
|
1171
|
+
*/
|
|
1172
|
+
declare interface ServerAssignment<ExperimentName, ExperimentVariantName> {
|
|
1173
|
+
/**
|
|
1174
|
+
* The date of the experiment assignment, in ms.
|
|
1175
|
+
* @example
|
|
1176
|
+
* "1658340252128"
|
|
1177
|
+
*/
|
|
1178
|
+
assignmentDate: string;
|
|
1179
|
+
/**
|
|
1180
|
+
* The ID of the entity assigned.
|
|
1181
|
+
* @example
|
|
1182
|
+
* "621509aae911cb2e37ba91ca"
|
|
1183
|
+
*/
|
|
1184
|
+
entityId: string;
|
|
1185
|
+
/**
|
|
1186
|
+
* The "type" of entity. Experiments are configured to allocate specific entity types.
|
|
1187
|
+
* @example
|
|
1188
|
+
* "ORG"
|
|
1189
|
+
*/
|
|
1190
|
+
entityType: EntityType;
|
|
1191
|
+
/**
|
|
1192
|
+
* ID of the experiment assignment. Normally populated, but can be null
|
|
1193
|
+
* if the Assignment is for a LAUNCHED experiment.
|
|
1194
|
+
* @example
|
|
1195
|
+
* "62d8439c9ce6473793cff6ca"
|
|
1196
|
+
*/
|
|
1197
|
+
id: string | null;
|
|
1198
|
+
/**
|
|
1199
|
+
* Experiment tag, set in the experiment configuration. Experiments on the same tag
|
|
1200
|
+
* are mutually exclusive.
|
|
1201
|
+
* @example
|
|
1202
|
+
* "activation"
|
|
1203
|
+
*/
|
|
1204
|
+
tag: string;
|
|
1205
|
+
/**
|
|
1206
|
+
* The ID of the experiment configuration.
|
|
1207
|
+
* @example
|
|
1208
|
+
* "62bb810b61be7d017fcc2198"
|
|
1209
|
+
*/
|
|
1210
|
+
testId: string;
|
|
1211
|
+
/**
|
|
1212
|
+
* The name of the experiment. Should be a value from the {@link TypeData.experimentName} enum.
|
|
1213
|
+
* @example
|
|
1214
|
+
* "ATLAS_SEARCH_IN_PROJECT_SIDE_NAV_20220620"
|
|
1215
|
+
*/
|
|
1216
|
+
testName: ExperimentName;
|
|
1217
|
+
/**
|
|
1218
|
+
* The name of the assigned experiment variant for the entity.
|
|
1219
|
+
* (Confusingly is NOT an ObjectId.)
|
|
1220
|
+
* If defined, should be a value from the {@link TypeData.experimentVariantName} enum.
|
|
1221
|
+
* The "/assign" server response will have this always
|
|
1222
|
+
* defined as a string, but the "/params" and "/assignByPoint" endpoints may have "null" for an
|
|
1223
|
+
* experiment, which would mean the entity is NOT allocated into the experiment
|
|
1224
|
+
* (aka not in any of the variants, including control).
|
|
1225
|
+
*
|
|
1226
|
+
* @example
|
|
1227
|
+
* "atlasSearchProjectSideNavControl"
|
|
1228
|
+
*/
|
|
1229
|
+
testGroupId: ExperimentVariantName | null;
|
|
1230
|
+
/**
|
|
1231
|
+
* The ID of the assigned experiment variant for the entity.
|
|
1232
|
+
* The "/assign" server response will have this always
|
|
1233
|
+
* defined as a string, but the "/params" and "/assignByPoint" endpoints may have "null" for an
|
|
1234
|
+
* experiment, which would mean the entity is NOT allocated into the experiment
|
|
1235
|
+
* (aka not in any of the variants, including control).
|
|
1236
|
+
*
|
|
1237
|
+
* @example
|
|
1238
|
+
* "62bb810b61be7d017fcc2196"
|
|
1239
|
+
*/
|
|
1240
|
+
testGroupDatabaseId: string | null;
|
|
1241
|
+
/**
|
|
1242
|
+
* An object containing assignment metadata, which currently consists of 1 field (isLaunchedExperiment).
|
|
1243
|
+
* Should normally be present, though can be "null" for 1. older assignments, or 2. override assignments.
|
|
1244
|
+
*
|
|
1245
|
+
* @example
|
|
1246
|
+
* { isLaunchedExperiment: false }
|
|
1247
|
+
*/
|
|
1248
|
+
meta: {
|
|
1249
|
+
isLaunchedExperiment: boolean;
|
|
1250
|
+
} | null;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* Server-formatted assignment array that's specific to the passed in list of possible experiment and variant names.
|
|
1255
|
+
*/
|
|
1256
|
+
declare type ServerAssignments<T extends TypeData> = Array<ServerAssignment<T['experimentName'], T['experimentVariantName']>>;
|
|
1257
|
+
|
|
1258
|
+
/** Server-formatted map of experiment attribute keys to values. */
|
|
1259
|
+
declare type ServerExperimentAttributeMap<T extends TypeData> = ServerExperimentAttributes<T['experimentAttributeName']>;
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* An experiment attribute from the server. The values are all strings.
|
|
1263
|
+
* This represents the raw experiment attribute data fed into {@link ExperimentSDK.addExistingExperimentData}
|
|
1264
|
+
* (which takes cares of transforming the strings into booleans and numbers as needed).
|
|
1265
|
+
* (FYI The below interface is taken from MMS: js/admin/controlpanel/types/abTest.ts)
|
|
1266
|
+
*/
|
|
1267
|
+
declare type ServerExperimentAttributes<ExperimentAttributeName extends string> = {
|
|
1268
|
+
[key in ExperimentAttributeName]?: string;
|
|
1269
|
+
};
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* A GHOST experiment assignment for a given entity and experiment. Extends the base "ServerAssignment" type.
|
|
1273
|
+
* This represents the raw assignment data fed into {@link ExperimentSDK.addExistingExperimentData}.
|
|
1274
|
+
* (FYI The below interface is taken from MMS: packages/types/abTest.ts)
|
|
1275
|
+
*/
|
|
1276
|
+
declare interface ServerGhostAssignment<ExperimentName, ExperimentVariantName> extends ServerAssignment<ExperimentName, ExperimentVariantName> {
|
|
1277
|
+
/**
|
|
1278
|
+
* The ID of the Holdout experiment which is responsible for the entity getting a
|
|
1279
|
+
* ghost assignment for the given test (aka the experiment represented by testName/testId).
|
|
1280
|
+
* Ghost assignments should always have this field populated.
|
|
1281
|
+
* (Ghost assignments are used for trackIsInSample functionality and can be ignored by most consumers.)
|
|
1282
|
+
*
|
|
1283
|
+
* @example
|
|
1284
|
+
* "645e70f9e40f6ce91c1efbaf"
|
|
1285
|
+
*/
|
|
1286
|
+
linkedHoldoutTestId: string;
|
|
1287
|
+
/**
|
|
1288
|
+
* The name of the Holdout experiment which is responsible for the entity getting a
|
|
1289
|
+
* ghost assignment for the given test (aka the experiment represented by testName/testId).
|
|
1290
|
+
* Ghost assignments should always have this field populated.
|
|
1291
|
+
* NOT necessarily a {@link TypeData.experimentName} enum value, as Holdout experiments are
|
|
1292
|
+
* generally configured and managed outside of the client platform.
|
|
1293
|
+
* (Ghost assignments are used for trackIsInSample functionality and can be ignored by most consumers.)
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* "HOLDOUT_2Q2023"
|
|
1297
|
+
*/
|
|
1298
|
+
linkedHoldoutTestName: string;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
declare type ServerStatsWorkspace = {
|
|
1302
|
+
type: 'Performance';
|
|
1303
|
+
connectionId: string;
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* The different values of severity for logging
|
|
1308
|
+
*/
|
|
1309
|
+
declare enum Severity {
|
|
1310
|
+
INFO = "info",
|
|
1311
|
+
WARNING = "warning",
|
|
1312
|
+
ERROR = "error"
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
declare type ShellWorkspace = {
|
|
1316
|
+
type: 'Shell';
|
|
1317
|
+
connectionId: string;
|
|
1318
|
+
initialEvaluate?: string | string[];
|
|
1319
|
+
initialInput?: string;
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1322
|
+
declare const SORT_ORDER_VALUES: readonly ["", "{ _id: 1 }", "{ _id: -1 }", "{ $natural: -1 }"];
|
|
1323
|
+
|
|
1324
|
+
declare type SORT_ORDERS = (typeof SORT_ORDER_VALUES)[number];
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Commonly used status codes (for {@link AsyncStatus})
|
|
1328
|
+
* Currently we only create AsyncStatus objects for success states; errors are thrown
|
|
1329
|
+
* and bubble up instead, hence why only 20X status codes are represented here.
|
|
1330
|
+
*/
|
|
1331
|
+
declare enum StatusCode {
|
|
1332
|
+
SUCCESS = 200,
|
|
1333
|
+
ACCEPTED = 202
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
declare type THEMES = (typeof THEMES_VALUES)[number];
|
|
1337
|
+
|
|
1338
|
+
declare const THEMES_VALUES: readonly ["DARK", "LIGHT", "OS_THEME"];
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* A Tracker object that can send data on client metrics.
|
|
1342
|
+
*/
|
|
1343
|
+
declare interface Tracker<ExperimentViewedProps> {
|
|
1344
|
+
/**
|
|
1345
|
+
* @description
|
|
1346
|
+
* Function that broadcasts client-side analytics events
|
|
1347
|
+
*
|
|
1348
|
+
* Intended usage:
|
|
1349
|
+
* Used by the function `trackIsInSample` to broadcast 'Experiment Viewed' and 'Experiment GhostViewed' events
|
|
1350
|
+
*
|
|
1351
|
+
* @param {
|
|
1352
|
+
* {
|
|
1353
|
+
* eventName: 'Experiment Viewed',
|
|
1354
|
+
* properties?: {},
|
|
1355
|
+
* timeout?: number,
|
|
1356
|
+
* }
|
|
1357
|
+
* } trackOptions - Required
|
|
1358
|
+
*
|
|
1359
|
+
* @return {Promise<void | Error | { message?: string }>}
|
|
1360
|
+
* Calling `track` will always return a promise.
|
|
1361
|
+
* - If the call is successful, the value of the promise will be void.
|
|
1362
|
+
* - If there is an error, the value of the promise will be the error.
|
|
1363
|
+
* - In some specific situations, the value of the promise will be an object with a key `message`.
|
|
1364
|
+
* -- {@link https://github.com/10gen/heliotrope|Heliotrope} returns these "objects with a message"
|
|
1365
|
+
* -- when it caches an analytics call (tries to make a track call before Heliotrope is
|
|
1366
|
+
* -- initialized), or when it attempts to make a track call when Heliotrope is not enabled.
|
|
1367
|
+
*
|
|
1368
|
+
* @example
|
|
1369
|
+
* `const trackPromise = this.#tracker.track({
|
|
1370
|
+
* eventName: 'Experiment Viewed',
|
|
1371
|
+
* properties: {
|
|
1372
|
+
* customProperty: 'A Relevant Value',
|
|
1373
|
+
* },
|
|
1374
|
+
* timeout: 100,
|
|
1375
|
+
* });`
|
|
1376
|
+
*
|
|
1377
|
+
* Note: `this.#tracker.track()` will only be called via `ExperimentSDK.trackIsInSample({...})`, and not
|
|
1378
|
+
* by the SDK's consumers.
|
|
1379
|
+
*
|
|
1380
|
+
* Note: Any properties that are passed into the `properties` object will have to match the
|
|
1381
|
+
* `experimentViewedProps` type that was passed in when the SDK was initialized.
|
|
1382
|
+
*
|
|
1383
|
+
*/
|
|
1384
|
+
track: (trackOptions: {
|
|
1385
|
+
eventName: ExperimentViewedEventName;
|
|
1386
|
+
properties?: ExperimentViewedProps;
|
|
1387
|
+
timeout?: number;
|
|
1388
|
+
}) => Promise<void | Error | {
|
|
1389
|
+
message?: string;
|
|
1390
|
+
}>;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Object representing Tracker object and tracking-related properties
|
|
1395
|
+
*/
|
|
1396
|
+
declare interface TrackerOptions<ExperimentViewedProps> {
|
|
1397
|
+
/** A Tracker */
|
|
1398
|
+
tracker: Tracker<ExperimentViewedProps>;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
/** @public */
|
|
1402
|
+
export declare type TrackFunction = (event: string, properties: Record<string, any>) => void;
|
|
1403
|
+
|
|
1404
|
+
/**
|
|
1405
|
+
* An optional type interface consumers can pass in during initializiation
|
|
1406
|
+
* to enforce enums for Experiment data. It is highly encouraged to pass this typing
|
|
1407
|
+
* in.
|
|
1408
|
+
*/
|
|
1409
|
+
declare type TypeData = {
|
|
1410
|
+
/**
|
|
1411
|
+
* Enum representing experiment names. Should match expected values for
|
|
1412
|
+
* {@link ExperimentAssignment.testName}
|
|
1413
|
+
* @example
|
|
1414
|
+
* enum ExperimentName {
|
|
1415
|
+
* EXP_ONE = 'expOne',
|
|
1416
|
+
* };
|
|
1417
|
+
* const types: TypeData = {
|
|
1418
|
+
* experimentName: ExperimentName,
|
|
1419
|
+
* ...
|
|
1420
|
+
* }
|
|
1421
|
+
*/
|
|
1422
|
+
experimentName: string;
|
|
1423
|
+
/**
|
|
1424
|
+
* Enum representing experiment variant names. Should match expected values for
|
|
1425
|
+
* {@link ExperimentAssignment.testGroupId}
|
|
1426
|
+
* @example
|
|
1427
|
+
* enum ExperimentVariantName {
|
|
1428
|
+
* EXP_VARIANT_ONE = 'expVariantOne',
|
|
1429
|
+
* };
|
|
1430
|
+
* const types: TypeData = {
|
|
1431
|
+
* experimentVariantName: ExperimentVariantName,
|
|
1432
|
+
* ...
|
|
1433
|
+
* }
|
|
1434
|
+
*/
|
|
1435
|
+
experimentVariantName: string;
|
|
1436
|
+
/**
|
|
1437
|
+
* Enum representing experiment attribute names
|
|
1438
|
+
* @example
|
|
1439
|
+
* enum ExperimentAttributeName {
|
|
1440
|
+
* SHOW_LEFT_NAV_LINK = 'showLeftNavLink',
|
|
1441
|
+
* };
|
|
1442
|
+
* const types: TypeData = {
|
|
1443
|
+
* experimentAttributeName: ExperimentAttributeName,
|
|
1444
|
+
* ...
|
|
1445
|
+
* }
|
|
1446
|
+
*/
|
|
1447
|
+
experimentAttributeName: string;
|
|
1448
|
+
/**
|
|
1449
|
+
* Enum representing allocation point names
|
|
1450
|
+
* @example
|
|
1451
|
+
* enum AllocationPointName {
|
|
1452
|
+
* CLUSTER_CARD_PAGE = 'CLUSTER_CARD_PAGE',
|
|
1453
|
+
* };
|
|
1454
|
+
* const types: TypeData = {
|
|
1455
|
+
* allocationPointName: AllocationPointName,
|
|
1456
|
+
* ...
|
|
1457
|
+
* }
|
|
1458
|
+
*/
|
|
1459
|
+
allocationPointName: string;
|
|
1460
|
+
/**
|
|
1461
|
+
* Type/Interface containing key/value pairs of properties that may be included in the
|
|
1462
|
+
* "Experiment Ghost/Viewed" event
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* export interface ExperimentViewedBaseEvent {
|
|
1466
|
+
* test_name: TestName;
|
|
1467
|
+
* test_group_name: TestGroupName;
|
|
1468
|
+
* }
|
|
1469
|
+
* interface ExperimentViewedPropertiesForExperimentA {
|
|
1470
|
+
* aCustomProp: string;
|
|
1471
|
+
* }
|
|
1472
|
+
* interface ExperimentViewedPropertiesForExperimentB {
|
|
1473
|
+
* aSecondCustomProp: string;
|
|
1474
|
+
* aThirdCustomProp: string;
|
|
1475
|
+
* }
|
|
1476
|
+
* type ExperimentViewedAdditionalProperties =
|
|
1477
|
+
* | ExperimentViewedPropertiesForExperimentA | ExperimentViewedPropertiesForExperimentB;
|
|
1478
|
+
* type ExperimentViewedEventProps =
|
|
1479
|
+
* | ExperimentViewedBaseEvent
|
|
1480
|
+
* | (ExperimentViewedBaseEvent & ExperimentViewedAdditionalProperties);
|
|
1481
|
+
*
|
|
1482
|
+
* const types: TypesToPassIn = {
|
|
1483
|
+
* experimentViewedProps: ExperimentViewedEventProps,
|
|
1484
|
+
* ...
|
|
1485
|
+
* }
|
|
1486
|
+
*/
|
|
1487
|
+
experimentViewedProps: {
|
|
1488
|
+
[name: string]: string | number;
|
|
1489
|
+
};
|
|
1490
|
+
/**
|
|
1491
|
+
* Enum representing different teams that can be assigned application logs
|
|
1492
|
+
* @example
|
|
1493
|
+
* enum LoggerTeam {
|
|
1494
|
+
* Team1 = 'Test Team 1',
|
|
1495
|
+
* };
|
|
1496
|
+
* const types: TypeData = {
|
|
1497
|
+
* loggerTeam: LoggerTeam,
|
|
1498
|
+
* ...
|
|
1499
|
+
* }
|
|
1500
|
+
*/
|
|
1501
|
+
loggerTeam: string;
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
export declare namespace types {
|
|
1505
|
+
export {
|
|
1506
|
+
Environment,
|
|
1507
|
+
StatusCode,
|
|
1508
|
+
Severity,
|
|
1509
|
+
EntityType,
|
|
1510
|
+
TypeData,
|
|
1511
|
+
AsyncStatus,
|
|
1512
|
+
ServerAssignment,
|
|
1513
|
+
ServerGhostAssignment,
|
|
1514
|
+
AssignmentData,
|
|
1515
|
+
SDKAssignment,
|
|
1516
|
+
SDKGhostAssignment,
|
|
1517
|
+
ServerExperimentAttributes,
|
|
1518
|
+
ExperimentAttributeValue,
|
|
1519
|
+
SDKExperimentAttributes,
|
|
1520
|
+
EntityIds,
|
|
1521
|
+
Log,
|
|
1522
|
+
Logger,
|
|
1523
|
+
LoggerOptions,
|
|
1524
|
+
Tracker,
|
|
1525
|
+
TrackerOptions,
|
|
1526
|
+
ConstructorOptions,
|
|
1527
|
+
GetPropertiesResponse,
|
|
1528
|
+
ExistingData,
|
|
1529
|
+
AddExperimentCallsProps,
|
|
1530
|
+
AddExistingExperimentDataOptions,
|
|
1531
|
+
GetAssignmentOptions,
|
|
1532
|
+
AssignOptions,
|
|
1533
|
+
AssignByPointsOptions,
|
|
1534
|
+
AssignmentsMap
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
export declare namespace typesReact {
|
|
1539
|
+
export {
|
|
1540
|
+
HookAsyncStatus,
|
|
1541
|
+
ExperimentSDKContextType,
|
|
1542
|
+
ExperimentSDKProviderProps,
|
|
1543
|
+
UseTrackIsInSampleConfig,
|
|
1544
|
+
UseAssignmentOptions,
|
|
1545
|
+
BasicHookResponse,
|
|
1546
|
+
UseAssignmentResponse
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
declare type UseAssignmentHook = (experimentName: ExperimentTestName, trackIsInSample: boolean, options?: typesReact.UseAssignmentOptions<types.TypeData>) => typesReact.UseAssignmentResponse<types.TypeData>;
|
|
1551
|
+
|
|
1552
|
+
/**
|
|
1553
|
+
* Additional options the useAssignment hook can take beyond the {@link GetAssignmentOptions} options.
|
|
1554
|
+
*/
|
|
1555
|
+
declare interface UseAssignmentOptions<T extends TypeData> extends GetAssignmentOptions<T> {
|
|
1556
|
+
/**
|
|
1557
|
+
* An optional array of {@link BasicHookResponse} objects that should trigger a refetch of assignments.
|
|
1558
|
+
* For example, if you want to refetch assignments after a "useAssign" call is complete, you can pass
|
|
1559
|
+
* the return value of "useAssign" in this array.
|
|
1560
|
+
*/
|
|
1561
|
+
hookDependencies?: Array<BasicHookResponse>;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* Additional response props of the {@link useAssignment} hook.
|
|
1566
|
+
*/
|
|
1567
|
+
declare interface UseAssignmentResponse<T extends TypeData> extends BasicHookResponse {
|
|
1568
|
+
assignment: SDKAssignment<T['experimentName'], T['experimentVariantName']> | null;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
declare type UserConfigurablePreferences = PermanentFeatureFlags & FeatureFlags & {
|
|
1572
|
+
autoUpdates: boolean;
|
|
1573
|
+
enableGenAIFeatures: boolean;
|
|
1574
|
+
enableMaps: boolean;
|
|
1575
|
+
trackUsageStatistics: boolean;
|
|
1576
|
+
enableFeedbackPanel: boolean;
|
|
1577
|
+
networkTraffic: boolean;
|
|
1578
|
+
readOnly: boolean;
|
|
1579
|
+
enableShell: boolean;
|
|
1580
|
+
enableDbAndCollStats: boolean;
|
|
1581
|
+
protectConnectionStrings?: boolean;
|
|
1582
|
+
forceConnectionOptions?: [key: string, value: string][];
|
|
1583
|
+
showKerberosPasswordField: boolean;
|
|
1584
|
+
showOIDCDeviceAuthFlow: boolean;
|
|
1585
|
+
browserCommandForOIDCAuth?: string;
|
|
1586
|
+
persistOIDCTokens?: boolean;
|
|
1587
|
+
enableDevTools: boolean;
|
|
1588
|
+
theme: THEMES;
|
|
1589
|
+
maxTimeMS?: number;
|
|
1590
|
+
installURLHandlers: boolean;
|
|
1591
|
+
protectConnectionStringsForNewConnections: boolean;
|
|
1592
|
+
atlasServiceBackendPreset: 'atlas-local' | 'atlas-dev' | 'atlas-qa' | 'atlas' | 'web-sandbox-atlas-local' | 'web-sandbox-atlas-dev' | 'web-sandbox-atlas-qa' | 'web-sandbox-atlas';
|
|
1593
|
+
optInGenAIFeatures: boolean;
|
|
1594
|
+
enableExplainPlan: boolean;
|
|
1595
|
+
enableAtlasSearchIndexes: boolean;
|
|
1596
|
+
enableImportExport: boolean;
|
|
1597
|
+
enableAggregationBuilderRunPipeline: boolean;
|
|
1598
|
+
enableAggregationBuilderExtraOptions: boolean;
|
|
1599
|
+
enableGenAISampleDocumentPassing: boolean;
|
|
1600
|
+
enablePerformanceAdvisorBanner: boolean;
|
|
1601
|
+
maximumNumberOfActiveConnections?: number;
|
|
1602
|
+
defaultSortOrder: SORT_ORDERS;
|
|
1603
|
+
enableShowDialogOnQuit: boolean;
|
|
1604
|
+
enableCreatingNewConnections: boolean;
|
|
1605
|
+
enableProxySupport: boolean;
|
|
1606
|
+
proxy: string;
|
|
1607
|
+
inferNamespacesFromPrivileges?: boolean;
|
|
1608
|
+
};
|
|
1609
|
+
|
|
1610
|
+
declare type UserPreferences = UserConfigurablePreferences & InternalUserPreferences & AtlasOrgPreferences & AtlasProjectPreferences;
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Config object passed into the {@link useTrackIsInSample} hook.
|
|
1614
|
+
*/
|
|
1615
|
+
declare interface UseTrackIsInSampleConfig<ExperimentViewedProps, LoggerTeam> {
|
|
1616
|
+
experimentName: string;
|
|
1617
|
+
shouldFireEvent?: boolean;
|
|
1618
|
+
customProperties?: ExperimentViewedProps;
|
|
1619
|
+
team?: LoggerTeam;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
declare type WelcomeWorkspace = {
|
|
1623
|
+
type: 'Welcome';
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
declare type Workspace<T extends AnyWorkspace['type']> = Extract<AnyWorkspace, {
|
|
1627
|
+
type: T;
|
|
1628
|
+
}>;
|
|
1629
|
+
|
|
1630
|
+
export declare type WorkspaceTab = {
|
|
1631
|
+
id: string;
|
|
1632
|
+
} & WorkspaceTabProps;
|
|
1633
|
+
|
|
1634
|
+
declare type WorkspaceTabProps = WelcomeWorkspace | MyQueriesWorkspace | DataModelingWorkspace | ShellWorkspace | ServerStatsWorkspace | DatabasesWorkspace | CollectionsWorkspace | (Omit<CollectionWorkspace, 'tabId'> & {
|
|
1635
|
+
subTab: CollectionSubtab;
|
|
1636
|
+
});
|
|
1637
|
+
|
|
1638
|
+
export { }
|