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

feat(js): js sdk preferences #5701

Merged
merged 14 commits into from
Jun 20, 2024
Merged

feat(js): js sdk preferences #5701

merged 14 commits into from
Jun 20, 2024

Conversation

LetItRock
Copy link
Contributor

What changed? Why was the change needed?

The Preferences module for JS SDK.

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

@LetItRock LetItRock self-assigned this Jun 10, 2024
Copy link

linear bot commented Jun 10, 2024

Comment on lines +224 to +231
async getPreferences({
level = PreferenceLevelEnum.TEMPLATE,
}: {
level?: `${PreferenceLevelEnum}`;
}): Promise<Array<IUserPreferenceSettings | IUserGlobalPreferenceSettings>> {
return this.httpClient.get(`/widgets/preferences/${level}`);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We provide newer APIs but it wasn't exposed with this ApiService class.

Comment on lines 9 to 40
export const mapPreference = (apiPreference: {
template?: TODO;
preference: {
enabled: boolean;
channels: {
email?: boolean;
sms?: boolean;
in_app?: boolean;
chat?: boolean;
push?: boolean;
};
overrides?: ChannelPreferenceOverride[];
};
}): Preference => {
const { template: workflow, preference } = apiPreference;
const hasWorkflow = workflow !== undefined;
const level = hasWorkflow ? PreferenceLevel.TEMPLATE : PreferenceLevel.GLOBAL;

return new Preference({
level,
enabled: preference.enabled,
channels: preference.channels,
workflow,
overrides: preference.overrides,
});
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Map server preference to the one that we use in the module with a better interface.

packages/js/src/preferences/helpers.ts Show resolved Hide resolved
Copy link

netlify bot commented Jun 10, 2024

Deploy Preview for novu-design failed. Why did it fail? →

Name Link
🔨 Latest commit 8c6464a
🔍 Latest deploy log https://app.netlify.com/sites/novu-design/deploys/667435350e72b90008652b89

packages/js/src/feeds/notification.ts Outdated Show resolved Hide resolved
packages/js/src/feeds/notification.ts Outdated Show resolved Hide resolved
payload: Record<string, unknown>;
overrides: Record<string, unknown>;
readonly _id: string;
readonly _feedId?: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove this, notifications will always belong to a feed array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but you might want to know to which feed it belongs when using individually

packages/js/src/feeds/notification.ts Outdated Show resolved Hide resolved
packages/js/src/feeds/notification.ts Outdated Show resolved Hide resolved
packages/js/src/types.ts Outdated Show resolved Hide resolved
name: string;
critical: boolean;
tags?: string[];
identifier: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between an identifier and the _id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

identifier is used for the trigger, _id is internal Mongo id

packages/js/src/types.ts Outdated Show resolved Hide resolved
export type ChannelPreference = {
email?: boolean;
sms?: boolean;
in_app?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
in_app?: boolean;
inApp?: boolean;

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 is due to internal implementation and will require changes across the stack :(

push?: boolean;
};

export type ChannelPreferenceOverride = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems overly complicated for the current frontend needs and is driven by the current state of the API. Let's build the DX on an ideal scenario and hide the API tech-debt with internal helper methods. Then we will update the API.

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 think that we can remove it from the new Preference class for now, not even sure if that is used often by clients.

@LetItRock LetItRock force-pushed the com-29-js-sdk-feeds branch from 9448d67 to e62dd85 Compare June 11, 2024 08:28
@LetItRock LetItRock force-pushed the com-30-js-sdk-preferences branch from 713d403 to 708b237 Compare June 11, 2024 08:43
@LetItRock LetItRock force-pushed the com-30-js-sdk-preferences branch from b57c777 to 9b0473d Compare June 11, 2024 10:28
@LetItRock LetItRock requested a review from SokratisVidros June 11, 2024 11:24
@LetItRock LetItRock force-pushed the com-29-js-sdk-feeds branch from 69aa508 to 4fd00de Compare June 13, 2024 09:53
@LetItRock LetItRock force-pushed the com-29-js-sdk-feeds branch from 4fd00de to ab164a5 Compare June 20, 2024 12:19
Base automatically changed from com-29-js-sdk-feeds to next June 20, 2024 13:47
Copy link

netlify bot commented Jun 20, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 8c6464a
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/66743535850bb00008b5cfb8
😎 Deploy Preview https://deploy-preview-5701--dev-web-novu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@LetItRock LetItRock merged commit fad83fa into next Jun 20, 2024
28 checks passed
@LetItRock LetItRock deleted the com-30-js-sdk-preferences branch June 20, 2024 14:20
github-actions bot added a commit that referenced this pull request Jun 21, 2024
* feat(js): js sdk feeds module (#5688)

* feat(js): improve the package json exports and tsup config
* feat(js): lazy session initialization and interface fixes
* feat(js): js sdk feeds module

* feat(js): js sdk preferences (#5701)

* feat(js): js sdk preferences

* feat(js): handling the web socket connection and events (#5704)

* feat(js): handling the web socket connection and events
* feat: ui solid

---------

Co-authored-by: Biswajeet Das <[email protected]>

* fix: caching for session initialize

* fix: worker

---------

Co-authored-by: Paweł Tymczuk <[email protected]>
Co-authored-by: Biswajeet Das <[email protected]>
Co-authored-by: Dima Grossman <[email protected]>
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.

3 participants