@pmate/account-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/api/AccountService.d.ts +11 -0
  2. package/dist/api/Api.d.ts +11 -0
  3. package/dist/api/EntityService.d.ts +9 -0
  4. package/dist/api/ProfileService.d.ts +28 -0
  5. package/dist/api/cacheInMem.d.ts +1 -0
  6. package/dist/api/index.d.ts +4 -0
  7. package/dist/app.config.d.ts +16 -0
  8. package/dist/atoms/accountAtom.d.ts +5 -0
  9. package/dist/atoms/accountProfileAtom.d.ts +3 -0
  10. package/dist/atoms/createProfileAtom.d.ts +7 -0
  11. package/dist/atoms/index.d.ts +16 -0
  12. package/dist/atoms/learningLangAtom.d.ts +1 -0
  13. package/dist/atoms/localStorageAtom.d.ts +8 -0
  14. package/dist/atoms/loginAtom.d.ts +3 -0
  15. package/dist/atoms/motherTongueAtom.d.ts +1 -0
  16. package/dist/atoms/profileAtom.d.ts +6 -0
  17. package/dist/atoms/profileDraftAtom.d.ts +7 -0
  18. package/dist/atoms/profilesAtom.d.ts +2 -0
  19. package/dist/atoms/sessionCheckAtom.d.ts +3 -0
  20. package/dist/atoms/switchProfileAtom.d.ts +4 -0
  21. package/dist/atoms/updateProfileAtom.d.ts +3 -0
  22. package/dist/atoms/uploadAvatarAtom.d.ts +8 -0
  23. package/dist/atoms/userLogoutAtom.d.ts +3 -0
  24. package/dist/atoms/userSettingsAtom.d.ts +3 -0
  25. package/dist/components/AuthProviderV2.d.ts +15 -0
  26. package/dist/components/index.d.ts +1 -0
  27. package/dist/hooks/index.d.ts +3 -0
  28. package/dist/hooks/useAppBackgroundStyle.d.ts +3 -0
  29. package/dist/hooks/useAuthApp.d.ts +21 -0
  30. package/dist/hooks/useAuthSnapshot.d.ts +8 -0
  31. package/dist/hooks/useProfileStepFlow.d.ts +13 -0
  32. package/dist/index.cjs.js +22 -0
  33. package/dist/index.cjs.js.map +1 -0
  34. package/dist/index.d.ts +8 -0
  35. package/dist/index.es.js +2800 -0
  36. package/dist/index.es.js.map +1 -0
  37. package/dist/types/account.types.d.ts +25 -0
  38. package/dist/types/profile.d.ts +5 -0
  39. package/dist/utils/AccountManagerV2.d.ts +43 -0
  40. package/dist/utils/Redirect.d.ts +4 -0
  41. package/dist/utils/accountStorage.d.ts +5 -0
  42. package/dist/utils/errors.d.ts +2 -0
  43. package/dist/utils/index.d.ts +6 -0
  44. package/dist/utils/profileStep.d.ts +6 -0
  45. package/dist/utils/resolveAppId.d.ts +1 -0
  46. package/dist/utils/selectedProfileStorage.d.ts +4 -0
  47. package/dist/utils/tokenStorage.d.ts +4 -0
  48. package/package.json +50 -0
@@ -0,0 +1,25 @@
1
+ import type { AccountState, Profile } from "@pmate/meta";
2
+ export declare enum AccountLifecycleState {
3
+ Idle = "idle",
4
+ Checking = "checking",
5
+ Authenticated = "authenticated",
6
+ Unauthenticated = "unauthenticated",
7
+ ProfileUninitialized = "profile-uninitialized",
8
+ ProfileInitializing = "profile-initializing",
9
+ ProfileReady = "profile-ready",
10
+ LoggingIn = "logging-in",
11
+ LoggingOut = "logging-out",
12
+ Error = "error"
13
+ }
14
+ export type AccountSnapshot = {
15
+ state: AccountLifecycleState;
16
+ account: AccountState | null;
17
+ accountId: string | null;
18
+ error: Error | null;
19
+ profiles: Profile[];
20
+ profile: Profile | null;
21
+ };
22
+ export type AuthBehaviors = {
23
+ authBehavior: "redirect" | "prompt";
24
+ requiresAuth: boolean;
25
+ };
@@ -0,0 +1,5 @@
1
+ import type { Profile } from "@pmate/meta";
2
+ export type ProfileDraft = Partial<Profile> & {
3
+ isAdult?: boolean;
4
+ age?: number;
5
+ };
@@ -0,0 +1,43 @@
1
+ import { Emitter } from "@pchip/utils";
2
+ import { AccountState, LangShort, LocalProfileState, Profile, RoomPeerInfo } from "@pmate/meta";
3
+ import { AccountLifecycleState } from "../types/account.types";
4
+ import type { AccountSnapshot } from "../types/account.types";
5
+ export declare enum AccountManagerEvent {
6
+ StateChange = "stateChange"
7
+ }
8
+ export declare class AccountManagerV2 extends Emitter<AccountManagerEvent> {
9
+ private readonly app;
10
+ private static instances;
11
+ constructor(app: string);
12
+ static get(app?: string): AccountManagerV2;
13
+ session(): Promise<import("@pmate/meta").AuthSession | null>;
14
+ login(): Promise<AccountState>;
15
+ hasUrlSession(): boolean;
16
+ /**
17
+ * When a URL contains a sessionId parameter, this method logs in the user.
18
+ * If URL does not contain a sessionId parameter, this method logs in from existing session.
19
+ */
20
+ loginUrlSessionOverride(): Promise<AccountState>;
21
+ logout(): Promise<void>;
22
+ getSnapshot(): Promise<AccountSnapshot>;
23
+ transition(next: AccountLifecycleState, error?: Error | null): void;
24
+ getAccountState(): Promise<AccountState | null>;
25
+ setAccountState(state: AccountState): void;
26
+ clearAccountState(): void;
27
+ getSelectedProfile(profiles?: Profile[]): Promise<Profile | null>;
28
+ setSelectedProfile(profile: Profile | LocalProfileState | string): void;
29
+ clearSelectedProfile(): void;
30
+ getProfiles(): Promise<Profile[]>;
31
+ clearProfiles(): void;
32
+ clearSession(): void;
33
+ getAuthToken(): string | null;
34
+ setAuthToken(token: string): void;
35
+ clearAuthToken(): void;
36
+ getLocalProfile(): Promise<LocalProfileState | null>;
37
+ getCurrentPeer(): Promise<RoomPeerInfo | undefined>;
38
+ createProfile(payload: {
39
+ nickName: string;
40
+ learningTargetLang?: LangShort;
41
+ }): Promise<Profile>;
42
+ private prepareProfiles;
43
+ }
@@ -0,0 +1,4 @@
1
+ export declare class Redirect {
2
+ static toLogin(app: string, redirect?: string): void;
3
+ static toCreateProfile(app: string, redirect?: string): void;
4
+ }
@@ -0,0 +1,5 @@
1
+ import type { AccountState } from "@pmate/meta";
2
+ export declare const ACCOUNT_STATE_KEY = "account-state";
3
+ export declare const getAccountState: () => AccountState | null;
4
+ export declare const setAccountState: (state: AccountState) => void;
5
+ export declare const clearAccountState: () => void;
@@ -0,0 +1,2 @@
1
+ export declare class NotAuthenticatedError extends Error {
2
+ }
@@ -0,0 +1,6 @@
1
+ export { getLangFull, isNicknameValid, legacyLangMap, normalizeLang, } from "@pmate/lang";
2
+ export * from "./AccountManagerV2";
3
+ export * from "./resolveAppId";
4
+ export * from "./errors";
5
+ export * from "./profileStep";
6
+ export * from "./Redirect";
@@ -0,0 +1,6 @@
1
+ export type ProfileStepType = "nickname" | "learning-language" | "mother-tongue" | "gender" | "is-adult" | "age";
2
+ export interface ProfileStep {
3
+ type: ProfileStepType;
4
+ title: string;
5
+ required: boolean;
6
+ }
@@ -0,0 +1 @@
1
+ export declare const resolveAppId: (fallbackApp?: string) => string;
@@ -0,0 +1,4 @@
1
+ export declare const SELECTED_PROFILE_KEY = "selected-profile";
2
+ export declare const getSelectedProfileId: () => string | null;
3
+ export declare const setSelectedProfileId: (id: string) => void;
4
+ export declare const clearSelectedProfileId: () => void;
@@ -0,0 +1,4 @@
1
+ export declare const TOKEN_STORAGE_KEY = "pmate-auth-token";
2
+ export declare const getAuthToken: () => string | null;
3
+ export declare const setAuthToken: (token: string) => void;
4
+ export declare const clearAuthToken: () => void;
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@pmate/account-sdk",
3
+ "version": "0.0.1",
4
+ "main": "./dist/index.cjs.js",
5
+ "module": "./dist/index.es.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.es.js",
11
+ "require": "./dist/index.cjs.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "scripts": {
21
+ "build": "vite build && tsc -p tsconfig.build.json",
22
+ "npm:publish": "pnpm build && npm publish --registry https://registry.npmjs.org/"
23
+ },
24
+ "peerDependencies": {
25
+ "@pchip/components": "workspace:*",
26
+ "@pchip/utils": "workspace:*",
27
+ "@pmate/i18n": "workspace:*",
28
+ "@pmate/lang": "workspace:*",
29
+ "@pmate/meta": "workspace:*",
30
+ "@pmate/uikit": "workspace:*",
31
+ "jotai": "*",
32
+ "jotai-family": "*",
33
+ "react": "*",
34
+ "react-dom": "*",
35
+ "react-hook-form": "*",
36
+ "react-router": "*",
37
+ "react-router-dom": "*"
38
+ },
39
+ "dependencies": {
40
+ "browser-image-compression": "^2.0.2",
41
+ "react-use": "^17.6.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/react": "*",
45
+ "@types/react-dom": "*",
46
+ "@vitejs/plugin-react": "^4.2.1",
47
+ "typescript": "^5.2.2",
48
+ "vite": "catalog:"
49
+ }
50
+ }