@quoll/client-lib
Advanced tools
Comparing version 0.8.2 to 0.8.3
@@ -6,2 +6,6 @@ # Change Log | ||
## [0.8.3](https://github.com/mzogheib/quoll/compare/@quoll/client-lib@0.8.2...@quoll/client-lib@0.8.3) (2024-09-08) | ||
**Note:** Version bump only for package @quoll/client-lib | ||
## [0.8.2](https://github.com/mzogheib/quoll/compare/@quoll/client-lib@0.8.1...@quoll/client-lib@0.8.2) (2024-08-16) | ||
@@ -8,0 +12,0 @@ |
{ | ||
"name": "@quoll/client-lib", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "Shared code for client side packages", | ||
@@ -8,13 +8,29 @@ "repository": "https://github.com/mzogheib/quoll", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
"./modules": { | ||
"types": "./dist/modules/index.d.ts", | ||
"import": "./dist/modules/index.js", | ||
"require": "./dist/modules/index.js" | ||
}, | ||
"./storage": { | ||
"types": "./dist/storage/index.d.ts", | ||
"import": "./dist/storage/index.js", | ||
"require": "./dist/storage/index.js" | ||
}, | ||
"./store": { | ||
"types": "./dist/store/index.d.ts", | ||
"import": "./dist/store/index.js", | ||
"require": "./dist/store/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"start": "tsc --watch", | ||
"start": "quoll-build-deps && tsc --watch", | ||
"clean-build": "rm -rf dist", | ||
"build": "yarn clean-build && tsc", | ||
"type-check": "tsc --noEmit", | ||
"prepare": "yarn build" | ||
"prepare": "yarn build", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@quoll/lib": "^0.5.6", | ||
"@quoll/lib": "^0.5.7", | ||
"react-redux": "^7.2.1", | ||
@@ -25,4 +41,7 @@ "redux": "^4.0.5" | ||
"@tsconfig/node18": "^18.2.4", | ||
"@types/jest": "^29.5.12", | ||
"@types/react": "^18.2.45", | ||
"jest": "^29.7.0", | ||
"redux-devtools-extension": "^2.13.9", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.3.3" | ||
@@ -33,3 +52,3 @@ }, | ||
}, | ||
"gitHead": "a8cb58a51772cd4c388f1eb3ad2645770ecc8de0" | ||
"gitHead": "9f5400e042d262d2d9a4e6d820d87b49eb70cdda" | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ISO8601Date } from "@quoll/lib"; | ||
import { ISO8601Date } from "@quoll/lib/modules"; | ||
@@ -26,4 +26,4 @@ import { Store } from "../../../store/types"; | ||
export const useDateModel = (useStore: () => Store<DateState>): DateModel => { | ||
const { state, setProperty, reset } = useStore(); | ||
export const makeDateModel = (store: Store<DateState>): DateModel => { | ||
const { state, setProperty, reset } = store; | ||
@@ -30,0 +30,0 @@ const setDate = (newDate: ISO8601Date) => setProperty("date", newDate); |
@@ -1,2 +0,2 @@ | ||
import { FeedConnectionConfig, FeedName } from "@quoll/lib"; | ||
import { FeedConnectionConfig, FeedName } from "@quoll/lib/modules"; | ||
@@ -24,10 +24,8 @@ import { Store } from "../../../store"; | ||
export const useFeedsModel = ( | ||
useStore: () => Store<FeedsState>, | ||
export const makeFeedsModel = ( | ||
store: Store<FeedsState>, | ||
feedsService: FeedsService, | ||
): FeedsModel => { | ||
const { setProperty, state: feeds, reset } = useStore(); | ||
const { setProperty, state: feeds, reset } = store; | ||
console.log({ feeds }); | ||
const isOneConnected = Object.values(feeds).some((feed) => feed.isConnected); | ||
@@ -34,0 +32,0 @@ |
@@ -1,6 +0,3 @@ | ||
import { | ||
AuthenticatedHttpService, | ||
FeedConnectionConfig, | ||
FeedName, | ||
} from "@quoll/lib"; | ||
import { FeedConnectionConfig, FeedName } from "@quoll/lib/modules"; | ||
import { AuthenticatedHttpService } from "@quoll/lib/services"; | ||
@@ -7,0 +4,0 @@ type AuthenticatePayload = { |
@@ -0,1 +1,2 @@ | ||
export * from "./auth"; | ||
export * from "./date"; | ||
@@ -5,2 +6,1 @@ export * from "./feeds"; | ||
export * from "./user"; | ||
export * from "./auth-user"; |
@@ -1,2 +0,2 @@ | ||
import { ISO8601Date, TimelineEntry } from "@quoll/lib"; | ||
import { ISO8601Date, TimelineEntry } from "@quoll/lib/modules"; | ||
@@ -32,7 +32,7 @@ import { Store } from "../../../store/types"; | ||
export const useTimelineModel = ( | ||
useStore: () => Store<TimelineState>, | ||
export const makeTimelineModel = ( | ||
store: Store<TimelineState>, | ||
timelineService: TimelineService, | ||
): TimelineModel => { | ||
const { state, setProperty, reset } = useStore(); | ||
const { state, setProperty, reset } = store; | ||
@@ -39,0 +39,0 @@ const fetchTimeline = async (date: ISO8601Date) => { |
import { | ||
AuthenticatedHttpService, | ||
ISO8601Date, | ||
@@ -8,3 +7,4 @@ TimelineEntry, | ||
getStartOfDay, | ||
} from "@quoll/lib"; | ||
} from "@quoll/lib/modules"; | ||
import { AuthenticatedHttpService } from "@quoll/lib/services"; | ||
@@ -11,0 +11,0 @@ type EntryConfig = { |
@@ -1,9 +0,8 @@ | ||
import { User } from "@quoll/lib"; | ||
import { User } from "@quoll/lib/modules"; | ||
import { Store } from "../../../store/types"; | ||
import { Storage } from "../../../storage/types"; | ||
import { UserService } from "../service"; | ||
import { IUserService } from "../service"; | ||
export type UserState = { | ||
isAuthenticating: boolean; | ||
isLoading: boolean; | ||
user: User | null; | ||
@@ -13,6 +12,4 @@ }; | ||
type UserActions = { | ||
login: (userId: string) => Promise<User>; | ||
signup: () => Promise<User>; | ||
logout: () => Promise<void>; | ||
getCurrentUserId: () => string | undefined; | ||
getMe: () => Promise<User | null>; | ||
createMe: () => Promise<User>; | ||
reset: () => void; | ||
@@ -23,48 +20,47 @@ }; | ||
export const useUserModel = ( | ||
useStore: () => Store<UserState>, | ||
service: UserService, | ||
storage: Storage<{ id: string }>, | ||
export const makeUserModel = ( | ||
store: Store<UserState>, | ||
service: IUserService, | ||
): UserModel => { | ||
const { state, setProperty, reset } = useStore(); | ||
const { user, isAuthenticating } = state; | ||
const { state, setProperty, reset } = store; | ||
const { user, isLoading } = state; | ||
const login = async (userId: string) => { | ||
setProperty("isAuthenticating", true); | ||
const user = await service.login(userId); | ||
storage.setProperty("id", userId); | ||
setProperty("user", user); | ||
setProperty("isAuthenticating", false); | ||
const getMe = async () => { | ||
try { | ||
setProperty("isLoading", true); | ||
const user = await service.getMe(); | ||
setProperty("user", user); | ||
return user; | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
const parsedError = JSON.parse(error.message); | ||
if (parsedError.status === 404) return null; | ||
} | ||
return user; | ||
throw error; | ||
} finally { | ||
setProperty("isLoading", false); | ||
} | ||
}; | ||
const signup = async () => { | ||
setProperty("isAuthenticating", true); | ||
const user = await service.signup(); | ||
storage.setProperty("id", user._id); | ||
setProperty("user", user); | ||
setProperty("isAuthenticating", false); | ||
return user; | ||
const createMe = async () => { | ||
try { | ||
setProperty("isLoading", true); | ||
const user = await service.createMe(); | ||
setProperty("user", user); | ||
return user; | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
setProperty("isLoading", false); | ||
} | ||
}; | ||
const getCurrentUserId = () => storage.getData()?.id; | ||
const logout = async () => { | ||
setProperty("isAuthenticating", true); | ||
storage.clear(); | ||
setProperty("user", null); | ||
setProperty("isAuthenticating", false); | ||
}; | ||
return { | ||
user, | ||
isAuthenticating, | ||
getCurrentUserId, | ||
login, | ||
signup, | ||
logout, | ||
isLoading, | ||
getMe, | ||
createMe, | ||
reset, | ||
}; | ||
}; |
@@ -1,18 +0,26 @@ | ||
import { HttpService, User } from "@quoll/lib"; | ||
import { User } from "@quoll/lib/modules"; | ||
import { AuthenticatedHttpService } from "@quoll/lib/services"; | ||
export class UserService extends HttpService { | ||
async login(userId: string) { | ||
export interface IUserService { | ||
getMe: () => Promise<User>; | ||
createMe: () => Promise<User>; | ||
} | ||
export class UserService | ||
extends AuthenticatedHttpService | ||
implements IUserService | ||
{ | ||
async getMe() { | ||
return this.request<User>({ | ||
method: "POST", | ||
endpoint: "/login", | ||
payload: { userId }, | ||
method: "GET", | ||
endpoint: "/user/me", | ||
}); | ||
} | ||
async signup() { | ||
return await this.request<User>({ | ||
async createMe() { | ||
return this.request<User>({ | ||
method: "POST", | ||
endpoint: "/signup", | ||
endpoint: "/user/me", | ||
}); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62373
7
30
628
1
Updated@quoll/lib@^0.5.7