Skip to content

Commit

Permalink
migrate to valtio
Browse files Browse the repository at this point in the history
  • Loading branch information
frontegg-david committed Jul 21, 2024
1 parent 47e1462 commit 03a573f
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 242 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.18.1
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "3.0.36",
"version": "4.0.0",
"npmClient": "yarn",
"useWorkspaces": true,
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/demo-saas/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "vue-demo-saas",
"version": "3.0.36",
"version": "4.0.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@frontegg/vue": "^3.0.36",
"@frontegg/vue": "^4.0.0",
"vue": "^2.6.11",
"vue-router": "^3.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-v3",
"version": "3.0.36",
"version": "4.0.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@frontegg/nuxt",
"version": "3.0.36",
"version": "4.0.0",
"description": "",
"main": "lib/module.js",
"types": "types/index.d.ts",
"files": [
"lib"
],
"dependencies": {
"@frontegg/vue": "^3.0.36"
"@frontegg/vue": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/sanity-check/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "frontegg-angular-sanity-check",
"private": true,
"version": "3.0.36",
"version": "4.0.0",
"scripts": {
"build": "docker-compose build test",
"build:dev": "docker-compose build test --no-cache",
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@frontegg/vue",
"version": "3.0.36",
"version": "4.0.0",
"description": "",
"main": "dist/index.ssr.js",
"browser": "dist/index.js",
Expand All @@ -22,7 +22,7 @@
"build:unpkg": "cross-env NODE_ENV=production rollup --config rollup.config.js --format iife"
},
"dependencies": {
"@frontegg/js": "6.206.0",
"@frontegg/js": "7.0.0-alpha.9",
"get-value": "^3.0.1",
"set-value": "^4.0.1"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/vue/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const external = [
'redux-saga/effects',
'set-value',
'get-value',
'@reduxjs/toolkit',
];

// UMD/IIFE shared settings: output.globals
Expand All @@ -87,7 +86,6 @@ const globals = {
'@frontegg/redux-store': 'fronteggReduxStore',
'@frontegg/rest-api': 'fronteggRestApi',
'vue-moment': 'vueMoment',
'@reduxjs/toolkit': 'ReduxjsToolkit',
'redux-saga': 'reduxSaga',
'redux-saga/effects': 'reduxSagaEffects',
'set-value': 'setValue',
Expand Down
8 changes: 4 additions & 4 deletions packages/vue/src/StoreHolder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EnhancedStore } from '@reduxjs/toolkit';
import { FronteggStore } from '@frontegg/redux-store';


export class StoreHolder {
private static instance: StoreHolder;
private store!: EnhancedStore;
private store!: FronteggStore;
private baseName: string | undefined;

private static getInstance() {
Expand All @@ -13,11 +13,11 @@ export class StoreHolder {
return StoreHolder.instance;
}

static setStore(store: EnhancedStore) {
static setStore(store: FronteggStore) {
StoreHolder.getInstance().store = store;
}

static getStore(): EnhancedStore {
static getStore(): FronteggStore {
return StoreHolder.getInstance().store;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/auth/mapAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const useFrontegg = () => {

const loginWithRedirect = () => {
const path = fronteggAuth.getCurrentRoute();
if (!path.startsWith(authState.routes.hostedLoginRedirectUrl ?? defaultFronteggRoutes.hostedLoginRedirectUrl)) {
if (!path.startsWith(authState.routes.hostedLoginRedirectUrl ?? defaultFronteggRoutes.hostedLoginRedirectUrl ?? "oauth/callback")) {
fronteggStore.dispatch({ type: 'auth/setState', payload: { isLoading: true } });
fronteggAuth.loginActions.requestHostedLoginAuthorize();
}
Expand Down
15 changes: 4 additions & 11 deletions packages/vue/src/auth/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AuthPluginOptions } from './interfaces';
import { FronteggPluginService, FronteggStore, PluginConfig, PluginOptions } from '../interfaces';
import { EnhancedStore } from '@reduxjs/toolkit';
import { bindActionCreators, CaseReducerActions, SliceCaseReducers } from '@frontegg/redux-store';
import { FronteggPluginService, PluginConfig, PluginOptions } from '../interfaces';
import { FronteggStore } from '@frontegg/redux-store';
import {
authActions,
LoginActions,
Expand Down Expand Up @@ -39,17 +38,11 @@ import {
import { ActionsHolder } from './ActionsHolder';
import VueRouter from 'vue-router';

export const sliceReducerActionsBy = <T extends SliceCaseReducers<any>>(reducer: T): CaseReducerActions<T> => {
const reducerKeys = Object.keys(reducer);
const reducerActions = reducerKeys.map(key => ({ [key]: (authActions as any)[key as keyof AuthActions] }));
return reducerActions.reduce((p, n) => ({ ...p, ...n }), {}) as CaseReducerActions<T>;
};

export class FronteggAuthService implements FronteggPluginService {
pluginConfig!: PluginConfig;
router?: VueRouter | null;
private readonly _routes!: AuthPageRoutes;
private store?: EnhancedStore<FronteggStore>;
private store?: FronteggStore;
private state: AuthState = authInitialState;
loginActions!: LoginActions;
socialLoginsActions!: SocialLoginActions;
Expand Down Expand Up @@ -92,7 +85,7 @@ export class FronteggAuthService implements FronteggPluginService {
return this.store?.getState().auth.user;
}

init = (options: PluginOptions, store: EnhancedStore<FronteggStore>) => {
init = (options: PluginOptions, store: FronteggStore) => {
this.store = store;

Object.entries({
Expand Down
8 changes: 3 additions & 5 deletions packages/vue/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import VueRouter from 'vue-router';
import { AuthState, EnhancedStore } from '@frontegg/redux-store';
import { FronteggStore } from '@frontegg/redux-store';
import { FronteggAppOptions } from '@frontegg/types';

export interface PluginConfig {
Expand All @@ -9,9 +9,7 @@ export interface PluginConfig {
preloadedState: any;
}

export interface FronteggStore {
auth: AuthState;
}


export interface PluginOptions extends FronteggAppOptions {
router: VueRouter;
Expand All @@ -21,5 +19,5 @@ export abstract class FronteggPluginService {
public loading!: boolean;
public pluginConfig!: PluginConfig;

public abstract init(options: PluginOptions, store: EnhancedStore<FronteggStore>): void;
public abstract init(options: PluginOptions, store: FronteggStore): void;
}
26 changes: 0 additions & 26 deletions packages/vue/src/reducer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/vue/src/sdkVersion.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default { version: '3.0.36' };
export default { version: '4.0.0' };
40 changes: 19 additions & 21 deletions packages/vue/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { EnhancedStore } from '@reduxjs/toolkit';
import { Unsubscribe } from 'redux';
import { Entitlement, User } from '@frontegg/redux-store';
import { Entitlement, User, FronteggStore } from '@frontegg/redux-store';
import { EntitledToOptions, LoadEntitlementsCallback, CustomAttributes } from '@frontegg/types';
import { FronteggPluginService } from './interfaces';

Expand All @@ -11,44 +9,44 @@ declare module 'vue/types/vue' {
}

interface Vue {
FRONTEGG_STORE_KEY?: EnhancedStore;
FRONTEGG_STORE_KEY?: FronteggStore;
FRONTEGG_ACTIONS_KEY?: any;
FRONTEGG_UNSUBSCRIBE?: Unsubscribe;
FRONTEGG_UNSUBSCRIBE?: () => void;
FRONTEGG_REDUX_BINDINGS?: any;
_data?: any;
fronteggLoaded: boolean;
loginWithRedirect: () => void;

/**
@param key feature key
@param customAttributes consumer attributes
@returns if the user is entitled to the given feature. Attaching the justification if not
@throws when entitlement is not enabled via frontegg options
*/
@param key feature key
@param customAttributes consumer attributes
@returns if the user is entitled to the given feature. Attaching the justification if not
@throws when entitlement is not enabled via frontegg options
*/
getFeatureEntitlements: (_user: User | undefined | null, key: string, customAttributes?: CustomAttributes) => Entitlement;

/**
@param key permission key
@param customAttributes consumer attributes
@returns if the user is entitled to the given permission. Attaching the justification if not
@throws when entitlement is not enabled via frontegg options
*/
@param key permission key
@param customAttributes consumer attributes
@returns if the user is entitled to the given permission. Attaching the justification if not
@throws when entitlement is not enabled via frontegg options
*/
getPermissionEntitlements: (_user: User | undefined | null, key: string, customAttributes?: CustomAttributes) => Entitlement;

/**
@param entitledToOptions - including permission or feature key
@param customAttributes consumer attributes
@returns if the user is entitled to the given permission or feature. Attaching the justification if not
@throws when entitlement is not enabled via frontegg options
*/
@param entitledToOptions - including permission or feature key
@param customAttributes consumer attributes
@returns if the user is entitled to the given permission or feature. Attaching the justification if not
@throws when entitlement is not enabled via frontegg options
*/
getEntitlements: (_user: User | undefined | null, entitledToOptions: EntitledToOptions, customAttributes?: CustomAttributes) => Entitlement;

/**
* Load entitlements
* @param callback called on request completed with true if succeeded, false if failed
*/
loadEntitlements: (callback?: LoadEntitlementsCallback) => void;

/**
* Returns true when user is stepped up, o.w false
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/vue/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import _Vue from 'vue';
import { EnhancedStore } from '@reduxjs/toolkit';
import { FronteggStore } from '@frontegg/redux-store';
import { FRONTEGG_REDUX_BINDINGS, FRONTEGG_STORE_KEY, FRONTEGG_UNSUBSCRIBE, FRONTEGG_LOADER_UNSUBSCRIBE } from './constants';
// import { mapState } from './map-state';
import { FronteggPluginService } from './interfaces';

export const setStoreKey = (instance: any, store: EnhancedStore) => instance[FRONTEGG_STORE_KEY] = instance[FRONTEGG_STORE_KEY] ?? store;
export const getStore = (instance: any): EnhancedStore => instance[FRONTEGG_STORE_KEY];
export const setStoreKey = (instance: any, store: FronteggStore) => instance[FRONTEGG_STORE_KEY] = instance[FRONTEGG_STORE_KEY] ?? store;
export const getStore = (instance: any): FronteggStore => instance[FRONTEGG_STORE_KEY];
export const getStoreBinding = (instance: any) => instance[FRONTEGG_REDUX_BINDINGS];
export const setStoreBinding = (instance: any, data: any) => instance[FRONTEGG_REDUX_BINDINGS] = data;
export const setStoreUnsubscribe = (instance: any, unsubscribe: () => void) => instance[FRONTEGG_UNSUBSCRIBE] = unsubscribe;
Expand Down
Loading

0 comments on commit 03a573f

Please sign in to comment.