Skip to content
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

fix: Implement anonymous context processing #350

Merged
merged 11 commits into from
Jan 19, 2024

Conversation

yusinto
Copy link
Contributor

@yusinto yusinto commented Jan 18, 2024

Apologies, I missed implementing this when moving the project to js-core.

Copy link

This pull request has been linked to Shortcut Story #229700: Implement anonymous context processing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was in index.ts but I moved it now to its own explicit file.

} from '@launchdarkly/js-sdk-common';
import { isLegacyUser, isMultiKind, isSingleKind } from '@launchdarkly/js-sdk-common';

export const ns = (s: string) => `LaunchDarkly_AnonKeys_${s}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using LaunchDarkly_AnonKeys_ which is different from the existing js common. We may have to worry about migrating existing keys. Although for the react native sdk, since it's a brand new sdk using a new storage package, migration maybe difficult if not impossible.

Copy link
Member

Choose a reason for hiding this comment

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

Could we name this function namespaced or something more explicit. I read the later code before this and was like what is an nsKind?

@yusinto yusinto requested a review from tanderson-ld January 18, 2024 20:06
@@ -133,6 +135,20 @@ describe('sdk-client object', () => {
});
});

test('identify anonymous', async () => {
defaultPutResponse['dev-test-flag'].value = false;
const carContext: LDContext = { kind: 'car', anonymous: true, key: '' };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even anonymous, key is a required field so it has to be set to an empty string. I think this is fine, but calling this out for concerns/discussion.

Copy link
Member

Choose a reason for hiding this comment

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

If you are ok with that requirement. I was originally planning on exporting a different type from client SDKs that did not require a key. Then internal to the client implementation decorate it (generate keys, verify anonymous is set) and create a Context.

Because I think that the pattern we had before, where you don't include a key and that makes the context anonymous is very intuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fine with this for now.

@@ -43,7 +43,7 @@ function encodeKey(key: string): string {
* @param context
* @returns true if the context is a single kind context.
*/
function isSingleKind(context: LDContext): context is LDSingleKindContext {
export function isSingleKind(context: LDContext): context is LDSingleKindContext {
Copy link
Member

Choose a reason for hiding this comment

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

I have serious reservations about exporting these functions. We don't want them exported from the final package and becoming part of the stable API of all of the packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will you be open to exporting these from internal please? They are useful internally and the common sdks can re-use them for internal logic.

Copy link
Member

Choose a reason for hiding this comment

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

I am ok with them being in internal.

I am really concerned about them being useful outside these two cases. They really are not supposed to be.

We are provided an LDContext and we then validate that into a Context. Once we have a Context these functions are not useful.

So, if we are careful to try not to use LDContext, aside from adding keys to it and then constructing a context, then that is probably fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I'll add comments in this file reflecting what you said.

@yusinto yusinto enabled auto-merge (squash) January 19, 2024 00:11
@yusinto yusinto requested a review from kinyoklion January 19, 2024 00:11
await ensureKeyCommon('user', c, platform);
};

const ensureKey = async (c: LDContext, platform: Platform) => {
Copy link
Member

Choose a reason for hiding this comment

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

I think I missed that we are modifying the context which is provided, versus modifying a copy. Typically we would never directly change things which are provided to the SDK.

We could either always clone, which is probably fine because identify isn't a high frequency situation.

Or only clone when we determine that we need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I'll clone and return the new object from ensureKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@yusinto yusinto requested a review from kinyoklion January 19, 2024 18:46
@yusinto yusinto merged commit 308100d into main Jan 19, 2024
16 checks passed
@yusinto yusinto deleted the yus/sc-229700/implement-anonymous-context-processing branch January 19, 2024 18:54
@github-actions github-actions bot mentioned this pull request Jan 19, 2024
yusinto pushed a commit that referenced this pull request Feb 6, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>akamai-edgeworker-sdk-common: 1.1.0</summary>

##
[1.1.0](akamai-edgeworker-sdk-common-v1.0.6...akamai-edgeworker-sdk-common-v1.1.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from ^2.1.3 to ^2.2.0
</details>

<details><summary>akamai-server-base-sdk: 2.1.0</summary>

##
[2.1.0](akamai-server-base-sdk-v2.0.6...akamai-server-base-sdk-v2.1.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.6 to
^1.1.0
    * @launchdarkly/js-server-sdk-common bumped from ^2.1.3 to ^2.2.0
</details>

<details><summary>akamai-server-edgekv-sdk: 1.1.0</summary>

##
[1.1.0](akamai-server-edgekv-sdk-v1.0.14...akamai-server-edgekv-sdk-v1.1.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/akamai-edgeworker-sdk-common bumped from ^1.0.6 to
^1.1.0
    * @launchdarkly/js-server-sdk-common bumped from ^2.1.3 to ^2.2.0
</details>

<details><summary>cloudflare-server-sdk: 2.4.0</summary>

##
[2.4.0](cloudflare-server-sdk-v2.3.3...cloudflare-server-sdk-v2.4.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.1.3 to 2.2.0
</details>

<details><summary>js-client-sdk-common: 0.2.0</summary>

##
[0.2.0](js-client-sdk-common-v0.1.2...js-client-sdk-common-v0.2.0)
(2024-02-06)


### Features

* Implement common client side support for auto environment attributes.
([#356](#356))
([8d80259](8d80259))
* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Bug Fixes

* Add LDOptions.application name and versionName.
([#358](#358))
([cd75210](cd75210))
* Add RN SDK offline support through ConnectionMode.
([#361](#361))
([d97ce82](d97ce82))
* Implement anonymous context processing
([#350](#350))
([308100d](308100d))
* Improvements and fixes from docs review.
([#362](#362))
([ba07fbf](ba07fbf))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-sdk-common bumped from 2.1.1 to 2.2.0
</details>

<details><summary>js-sdk-common: 2.2.0</summary>

##
[2.2.0](js-sdk-common-v2.1.1...js-sdk-common-v2.2.0)
(2024-02-06)


### Features

* Implement common client side support for auto environment attributes.
([#356](#356))
([8d80259](8d80259))
* Implement common support for auto environment attributes.
([#355](#355))
([9f562e5](9f562e5))
* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Bug Fixes

* Add LDOptions.application name and versionName.
([#358](#358))
([cd75210](cd75210))
* Add RN SDK offline support through ConnectionMode.
([#361](#361))
([d97ce82](d97ce82))
* Implement anonymous context processing
([#350](#350))
([308100d](308100d))
* RN streamer connection in background and foreground.
([#360](#360))
([c69b768](c69b768))
</details>

<details><summary>js-server-sdk-common: 2.2.0</summary>

##
[2.2.0](js-server-sdk-common-v2.1.3...js-server-sdk-common-v2.2.0)
(2024-02-06)


### Features

* Implement common client side support for auto environment attributes.
([#356](#356))
([8d80259](8d80259))
* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Bug Fixes

* Add LDOptions.application name and versionName.
([#358](#358))
([cd75210](cd75210))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-sdk-common bumped from 2.1.1 to 2.2.0
</details>

<details><summary>js-server-sdk-common-edge: 2.2.0</summary>

##
[2.2.0](js-server-sdk-common-edge-v2.1.3...js-server-sdk-common-edge-v2.2.0)
(2024-02-06)


### Features

* Implement common client side support for auto environment attributes.
([#356](#356))
([8d80259](8d80259))
* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.1.3 to 2.2.0
</details>

<details><summary>node-server-sdk: 9.1.0</summary>

##
[9.1.0](node-server-sdk-v9.0.6...node-server-sdk-v9.1.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common bumped from 2.1.3 to 2.2.0
</details>

<details><summary>node-server-sdk-dynamodb: 6.1.0</summary>

##
[6.1.0](node-server-sdk-dynamodb-v6.0.6...node-server-sdk-dynamodb-v6.1.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.0.6 to 9.1.0
</details>

<details><summary>node-server-sdk-redis: 4.1.0</summary>

##
[4.1.0](node-server-sdk-redis-v4.0.6...node-server-sdk-redis-v4.1.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/node-server-sdk bumped from 9.0.6 to 9.1.0
</details>

<details><summary>react-native-client-sdk: 0.2.0</summary>

##
[0.2.0](react-native-client-sdk-v0.1.5...react-native-client-sdk-v0.2.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Bug Fixes

* Add RN SDK offline support through ConnectionMode.
([#361](#361))
([d97ce82](d97ce82))
* Implement RN SDK EventSource jitter backoff.
([#359](#359))
([95e58bd](95e58bd))
* Improvements and fixes from docs review.
([#362](#362))
([ba07fbf](ba07fbf))
* RN streamer connection in background and foreground.
([#360](#360))
([c69b768](c69b768))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-client-sdk-common bumped from 0.1.2 to 0.2.0
</details>

<details><summary>vercel-server-sdk: 1.3.0</summary>

##
[1.3.0](vercel-server-sdk-v1.2.3...vercel-server-sdk-v1.3.0)
(2024-02-06)


### Features

* React-native support for auto-env attributes. Only affects
react-native package.
([deea99c](deea99c))
* Update eslint jest configuration and versions.
([deea99c](deea99c))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-server-sdk-common-edge bumped from 2.1.3 to 2.2.0
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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