Skip to content

Conversation

ploomiz
Copy link
Contributor

@ploomiz ploomiz commented Jun 17, 2022

This PR copies over the assignment logic from the node-server-sdk. The only notable difference is how the SDK is initialized. The client-side SDK operates in a single-subject environment. Therefore, the subjectKey and subjectAttributes are provided during initialization:

EppoSdk.init({ apiKey: "<API_KEY>", subjectKey: "<SUBJECT_KEY>", subjectAttributes: { "email": "test@example.com" });

With the subject attributes provided during initialization, the getAssignment function only needs one argument for experiment key:

client.getAssignment("<EXPERIMENT_KEY>");

This PR also utilizes browser session storage for storing the assignment configuration.

@ploomiz ploomiz self-assigned this Jun 17, 2022
@ploomiz ploomiz changed the base branch from main to setup-without-code June 17, 2022 16:25
@ploomiz ploomiz force-pushed the setup-without-code branch from d753982 to dd980d1 Compare June 17, 2022 16:34
@ploomiz ploomiz changed the title Setup SDK Repo Assignment logic Jun 17, 2022
@ploomiz ploomiz changed the title Assignment logic Implement Assignment Logic Jun 17, 2022
@@ -0,0 +1,76 @@
import { createHash } from 'crypto';
Copy link
Contributor Author

@ploomiz ploomiz Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk.

@@ -0,0 +1,12 @@
import { Rule } from './rule';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk

@@ -0,0 +1,19 @@
export type AttributeValueType = string | number;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk

@@ -0,0 +1,9 @@
export interface IShardRange {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk

src/rule.ts Outdated
@@ -0,0 +1,19 @@
export type AttributeValueType = string | number;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk

@@ -0,0 +1,59 @@
import { Condition, OperatorType, Rule, AttributeValueType } from './rule';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk

@@ -0,0 +1,15 @@
import { createHash } from 'crypto';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk

@ploomiz ploomiz marked this pull request as ready for review June 17, 2022 21:58
@ploomiz ploomiz requested review from petzel and vpai June 17, 2022 21:58
src/constants.ts Outdated
@@ -0,0 +1,2 @@
export const REQUEST_TIMEOUT_MILLIS = 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this will run on end-users devices, I think we should increase this to 5 or 10 seconds (since the user's internet connection could be really slow).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increased it to 5 seconds


export default class EppoClient implements IEppoClient {
constructor(
private subjectKey: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still pass this into the getAssignment function. A customer way want to experiment on an anonymous/logged out user until they log in, at which point they'd want to use a different type of subject ID. If we require subjectKey to be passed in to the constructor here, they'd have to recreate and initialize the client after login.

Base automatically changed from setup-without-code to main June 21, 2022 19:49
@@ -0,0 +1,66 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from @eppo/node-server-sdk

@ploomiz ploomiz merged commit 3355bed into main Jun 21, 2022
@ploomiz ploomiz deleted the setup branch June 21, 2022 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants