-
Notifications
You must be signed in to change notification settings - Fork 83
feat: Created declaration file for project config index.d.ts module #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
cd3a438
9cf0aad
4e0a752
215c0fe
ae6186c
99cb5d1
1f551e7
b6f73d0
b7df251
ecbd322
e54a9fc
0e1b56c
36c9e62
6add538
fb07216
0694c7c
5f4d9d4
941c5f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** | ||
| * Copyright 2020, Optimizely | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UserAttributes and EventTags from optimizely-sdk can be defined here and import using it's reference there. |
||
|
|
||
| export type UserAttributes = { | ||
| // TODO[OASIS-6649]: Don't use any type | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [name: string]: any; | ||
| }; | ||
|
|
||
| export type EventTags = { | ||
| [key: string]: string | number | boolean; | ||
| }; | ||
|
|
||
| export type ConditionTree<Leaf> = Leaf | unknown[]; | ||
|
||
|
|
||
| export interface Variation { | ||
| id: string; | ||
| key: string; | ||
| } | ||
|
|
||
| export type TrafficAllocation = { | ||
| entityId: string; | ||
| endOfRange: number; | ||
| }; | ||
|
|
||
| export interface Experiment { | ||
| id: string; | ||
| key: string; | ||
| status: string; | ||
| layerId: string; | ||
| variations: Variation[]; | ||
| trafficAllocation: TrafficAllocation[]; | ||
| audienceIds: string[]; | ||
| // TODO[OASIS-6649]: Don't use object type | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| forcedVariations: object; | ||
| } | ||
|
|
||
| export interface Group { | ||
| experiments: Experiment[]; | ||
| id: string; | ||
| policy: string; | ||
| trafficAllocation: TrafficAllocation[]; | ||
| } | ||
|
|
||
| export type Condition = { | ||
| name: string; | ||
| type: string; | ||
| match?: string; | ||
| value: string | number | boolean | null; | ||
| }; | ||
|
||
|
|
||
| export interface Audience { | ||
| id: string; | ||
| conditions: ConditionTree<Condition>; | ||
| name: string; | ||
| } | ||
|
|
||
| export interface Event { | ||
| experimentIds: string[]; | ||
| id: string; | ||
| key: string; | ||
| } | ||
|
|
||
| export interface FeatureVariable { | ||
| defaultValue: string; | ||
| id: string; | ||
| key: string; | ||
| subType?: string; | ||
| type: string; | ||
| } | ||
|
|
||
| export interface Rollout { | ||
| experiments: Experiment[]; | ||
| id: string; | ||
| } | ||
|
|
||
| export interface FeatureFlag { | ||
| experimentIds: string[]; | ||
| id: string; | ||
| key: string; | ||
| rolloutId: string; | ||
| variables: FeatureVariable[]; | ||
| } | ||
|
|
||
| export interface Attribute { | ||
| id: string; | ||
| key: string; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| * Copyright 2020, Optimizely | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| declare module '@optimizely/optimizely-sdk/lib/core/project_config' { | ||
| export interface ProjectConfig {} | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add function definitions which will be called or used from lib/optimizely/index.js |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,48 +63,73 @@ declare module '@optimizely/optimizely-sdk' { | |
|
|
||
| export interface Client { | ||
| notificationCenter: NotificationCenter; | ||
| activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; | ||
| track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void; | ||
| getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; | ||
| activate( | ||
| experimentKey: string, | ||
| userId: string, | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): string | null; | ||
| track( | ||
| eventKey: string, | ||
| userId: string, | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes, | ||
| eventTags?: import('../lib/core/project_config/entities').EventTags | ||
| ): void; | ||
| getVariation( | ||
| experimentKey: string, | ||
| userId: string, | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): string | null; | ||
| setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean; | ||
| getForcedVariation(experimentKey: string, userId: string): string | null; | ||
| isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean; | ||
| getEnabledFeatures(userId: string, attributes?: UserAttributes): string[]; | ||
| getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown | ||
| isFeatureEnabled( | ||
| featureKey: string, | ||
| userId: string, | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): boolean; | ||
| getEnabledFeatures( | ||
| userId: string, | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): string[]; | ||
| getFeatureVariable( | ||
| featureKey: string, | ||
| variableKey: string, | ||
| userId: string, | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): unknown; | ||
| getFeatureVariableBoolean( | ||
| featureKey: string, | ||
| variableKey: string, | ||
| userId: string, | ||
| attributes?: UserAttributes | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): boolean | null; | ||
| getFeatureVariableDouble( | ||
| featureKey: string, | ||
| variableKey: string, | ||
| userId: string, | ||
| attributes?: UserAttributes | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): number | null; | ||
| getFeatureVariableInteger( | ||
| featureKey: string, | ||
| variableKey: string, | ||
| userId: string, | ||
| attributes?: UserAttributes | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): number | null; | ||
| getFeatureVariableString( | ||
| featureKey: string, | ||
| variableKey: string, | ||
| userId: string, | ||
| attributes?: UserAttributes | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): string | null; | ||
| getFeatureVariableJSON( | ||
| featureKey: string, | ||
| variableKey: string, | ||
| userId: string, | ||
| attributes?: UserAttributes | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): unknown; | ||
| getAllFeatureVariables( | ||
| featureKey: string, | ||
| userId: string, | ||
| attributes?: UserAttributes | ||
| attributes?: import('../lib/core/project_config/entities').UserAttributes | ||
| ): { [variableKey: string]: unknown }; | ||
| getOptimizelyConfig(): OptimizelyConfig | null; | ||
| onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>; | ||
|
|
@@ -155,52 +180,21 @@ declare module '@optimizely/optimizely-sdk' { | |
|
|
||
| export interface ListenerPayload { | ||
| userId: string; | ||
| attributes: UserAttributes; | ||
| attributes: import('../lib/core/project_config/entities').UserAttributes; | ||
| } | ||
|
|
||
| export interface ActivateListenerPayload extends ListenerPayload { | ||
| experiment: Experiment; | ||
| variation: Variation; | ||
| experiment: import('./core/project_config/entities').Experiment; | ||
| variation: import('./core/project_config/entities').Variation; | ||
| logEvent: Event; | ||
| } | ||
|
|
||
| export type UserAttributes = { | ||
| // TODO[OASIS-6649]: Don't use any type | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [name: string]: any; | ||
| }; | ||
|
|
||
| export type EventTags = { | ||
| [key: string]: string | number | boolean; | ||
| }; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't remove these from here, these are part of the public interface used by SDK users. |
||
| export interface TrackListenerPayload extends ListenerPayload { | ||
| eventKey: string; | ||
| eventTags: EventTags; | ||
| eventTags: import('../lib/core/project_config/entities').EventTags; | ||
| logEvent: Event; | ||
| } | ||
|
|
||
| interface Experiment { | ||
| id: string; | ||
| key: string; | ||
| status: string; | ||
| layerId: string; | ||
| variations: Variation[]; | ||
| trafficAllocation: Array<{ | ||
| entityId: string; | ||
| endOfRange: number; | ||
| }>; | ||
| audienceIds: string[]; | ||
| // TODO[OASIS-6649]: Don't use object type | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| forcedVariations: object; | ||
| } | ||
|
|
||
| interface Variation { | ||
| id: string; | ||
| key: string; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't remove this, this is part of the public interface used by SDK users. |
||
| // Information about past bucketing decisions for a user. | ||
| export interface UserProfile { | ||
| user_id: string; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't import.