@viyv/account-client 0.1.0 → 0.2.0

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.
package/dist/react.cjs CHANGED
@@ -60,6 +60,7 @@ var SIGNED_OUT = {
60
60
  entitlement: null
61
61
  };
62
62
  async function loadAccount(apiBase, opts = {}) {
63
+ if (opts.devAccount) return opts.devAccount;
63
64
  const doFetch = opts.fetchImpl ?? fetch;
64
65
  const session = await fetchJson(
65
66
  doFetch,
@@ -94,6 +95,7 @@ function AccountProvider({
94
95
  cookieDomain,
95
96
  signInUrl = "https://app.viyv.io/signin",
96
97
  skipEntitlement = false,
98
+ devAccount,
97
99
  children
98
100
  }) {
99
101
  const clientRef = react.useRef(null);
@@ -109,7 +111,7 @@ function AccountProvider({
109
111
  async (signal) => {
110
112
  try {
111
113
  setError(null);
112
- const result = await loadAccount(apiBase, { skipEntitlement, signal });
114
+ const result = await loadAccount(apiBase, { skipEntitlement, signal, devAccount });
113
115
  setUser(result.user);
114
116
  setActiveOrg(result.activeOrg);
115
117
  setEntitlement(result.entitlement);
@@ -123,7 +125,7 @@ function AccountProvider({
123
125
  setStatus("unauthenticated");
124
126
  }
125
127
  },
126
- [apiBase, skipEntitlement]
128
+ [apiBase, skipEntitlement, devAccount]
127
129
  );
128
130
  react.useEffect(() => {
129
131
  const ctrl = new AbortController();
@@ -206,6 +208,7 @@ function SignOutButton({ children, className, onSignedOut }) {
206
208
  exports.AccountProvider = AccountProvider;
207
209
  exports.SignInButton = SignInButton;
208
210
  exports.SignOutButton = SignOutButton;
211
+ exports.loadAccount = loadAccount;
209
212
  exports.useAccount = useAccount;
210
213
  exports.useActiveOrg = useActiveOrg;
211
214
  exports.useEntitlement = useEntitlement;
package/dist/react.d.cts CHANGED
@@ -60,6 +60,29 @@ interface ProductEntitlement {
60
60
  }
61
61
 
62
62
  type AccountStatus = "loading" | "authenticated" | "unauthenticated";
63
+ interface LoadedAccount {
64
+ status: "authenticated" | "unauthenticated";
65
+ user: AccountUser | null;
66
+ activeOrg: AccountOrg | null;
67
+ entitlement: Entitlement | null;
68
+ }
69
+ /**
70
+ * Resolve the current account (session + active org + entitlement) from
71
+ * api.viyv.io using the `.viyv.io` cookie. Pure + DOM-free so it is unit-testable
72
+ * with a mocked fetch. Throws on a transport/HTTP error (the caller decides how
73
+ * to surface it); a missing session resolves to {@link SIGNED_OUT}.
74
+ */
75
+ declare function loadAccount(apiBase: string, opts?: {
76
+ skipEntitlement?: boolean;
77
+ signal?: AbortSignal;
78
+ fetchImpl?: typeof fetch;
79
+ /**
80
+ * Dev escape hatch: when supplied, short-circuit ALL network I/O and resolve
81
+ * to this synthetic account. Intended for local `next dev` against an
82
+ * unreachable viyv-account. Env-agnostic — the consumer owns the gate.
83
+ */
84
+ devAccount?: LoadedAccount | null;
85
+ }): Promise<LoadedAccount>;
63
86
  interface AccountContextValue {
64
87
  status: AccountStatus;
65
88
  user: AccountUser | null;
@@ -84,9 +107,15 @@ interface AccountProviderProps {
84
107
  signInUrl?: string;
85
108
  /** Skip the entitlement fetch (session-only consumers). Default false. */
86
109
  skipEntitlement?: boolean;
110
+ /**
111
+ * Dev escape hatch: a synthetic account to render instead of fetching from
112
+ * api.viyv.io. Intended for local `next dev` (gate it on a NEXT_PUBLIC_* flag
113
+ * the consumer owns). null/undefined → normal cookie-session flow.
114
+ */
115
+ devAccount?: LoadedAccount | null;
87
116
  children?: ReactNode;
88
117
  }
89
- declare function AccountProvider({ apiBase, cookieDomain, signInUrl, skipEntitlement, children, }: AccountProviderProps): react.FunctionComponentElement<react.ProviderProps<AccountContextValue | null>>;
118
+ declare function AccountProvider({ apiBase, cookieDomain, signInUrl, skipEntitlement, devAccount, children, }: AccountProviderProps): react.FunctionComponentElement<react.ProviderProps<AccountContextValue | null>>;
90
119
  /** Read the full account context. Throws if used outside <AccountProvider>. */
91
120
  declare function useAccount(): AccountContextValue;
92
121
  /** The signed-in user, or null when unauthenticated/loading. */
@@ -99,4 +128,4 @@ declare function useActiveOrg(): AccountOrg | null;
99
128
  */
100
129
  declare function useEntitlement(product: ProductSlug): ProductEntitlement | null;
101
130
 
102
- export { type AccountContextValue, type AccountOrg, AccountProvider, type AccountProviderProps, type AccountStatus, type AccountUser, type Entitlement, type ProductEntitlement, SignInButton, type SignInButtonProps, SignOutButton, type SignOutButtonProps, useAccount, useActiveOrg, useEntitlement, useUser };
131
+ export { type AccountContextValue, type AccountOrg, AccountProvider, type AccountProviderProps, type AccountStatus, type AccountUser, type Entitlement, type LoadedAccount, type ProductEntitlement, SignInButton, type SignInButtonProps, SignOutButton, type SignOutButtonProps, loadAccount, useAccount, useActiveOrg, useEntitlement, useUser };
package/dist/react.d.ts CHANGED
@@ -60,6 +60,29 @@ interface ProductEntitlement {
60
60
  }
61
61
 
62
62
  type AccountStatus = "loading" | "authenticated" | "unauthenticated";
63
+ interface LoadedAccount {
64
+ status: "authenticated" | "unauthenticated";
65
+ user: AccountUser | null;
66
+ activeOrg: AccountOrg | null;
67
+ entitlement: Entitlement | null;
68
+ }
69
+ /**
70
+ * Resolve the current account (session + active org + entitlement) from
71
+ * api.viyv.io using the `.viyv.io` cookie. Pure + DOM-free so it is unit-testable
72
+ * with a mocked fetch. Throws on a transport/HTTP error (the caller decides how
73
+ * to surface it); a missing session resolves to {@link SIGNED_OUT}.
74
+ */
75
+ declare function loadAccount(apiBase: string, opts?: {
76
+ skipEntitlement?: boolean;
77
+ signal?: AbortSignal;
78
+ fetchImpl?: typeof fetch;
79
+ /**
80
+ * Dev escape hatch: when supplied, short-circuit ALL network I/O and resolve
81
+ * to this synthetic account. Intended for local `next dev` against an
82
+ * unreachable viyv-account. Env-agnostic — the consumer owns the gate.
83
+ */
84
+ devAccount?: LoadedAccount | null;
85
+ }): Promise<LoadedAccount>;
63
86
  interface AccountContextValue {
64
87
  status: AccountStatus;
65
88
  user: AccountUser | null;
@@ -84,9 +107,15 @@ interface AccountProviderProps {
84
107
  signInUrl?: string;
85
108
  /** Skip the entitlement fetch (session-only consumers). Default false. */
86
109
  skipEntitlement?: boolean;
110
+ /**
111
+ * Dev escape hatch: a synthetic account to render instead of fetching from
112
+ * api.viyv.io. Intended for local `next dev` (gate it on a NEXT_PUBLIC_* flag
113
+ * the consumer owns). null/undefined → normal cookie-session flow.
114
+ */
115
+ devAccount?: LoadedAccount | null;
87
116
  children?: ReactNode;
88
117
  }
89
- declare function AccountProvider({ apiBase, cookieDomain, signInUrl, skipEntitlement, children, }: AccountProviderProps): react.FunctionComponentElement<react.ProviderProps<AccountContextValue | null>>;
118
+ declare function AccountProvider({ apiBase, cookieDomain, signInUrl, skipEntitlement, devAccount, children, }: AccountProviderProps): react.FunctionComponentElement<react.ProviderProps<AccountContextValue | null>>;
90
119
  /** Read the full account context. Throws if used outside <AccountProvider>. */
91
120
  declare function useAccount(): AccountContextValue;
92
121
  /** The signed-in user, or null when unauthenticated/loading. */
@@ -99,4 +128,4 @@ declare function useActiveOrg(): AccountOrg | null;
99
128
  */
100
129
  declare function useEntitlement(product: ProductSlug): ProductEntitlement | null;
101
130
 
102
- export { type AccountContextValue, type AccountOrg, AccountProvider, type AccountProviderProps, type AccountStatus, type AccountUser, type Entitlement, type ProductEntitlement, SignInButton, type SignInButtonProps, SignOutButton, type SignOutButtonProps, useAccount, useActiveOrg, useEntitlement, useUser };
131
+ export { type AccountContextValue, type AccountOrg, AccountProvider, type AccountProviderProps, type AccountStatus, type AccountUser, type Entitlement, type LoadedAccount, type ProductEntitlement, SignInButton, type SignInButtonProps, SignOutButton, type SignOutButtonProps, loadAccount, useAccount, useActiveOrg, useEntitlement, useUser };
package/dist/react.js CHANGED
@@ -58,6 +58,7 @@ var SIGNED_OUT = {
58
58
  entitlement: null
59
59
  };
60
60
  async function loadAccount(apiBase, opts = {}) {
61
+ if (opts.devAccount) return opts.devAccount;
61
62
  const doFetch = opts.fetchImpl ?? fetch;
62
63
  const session = await fetchJson(
63
64
  doFetch,
@@ -92,6 +93,7 @@ function AccountProvider({
92
93
  cookieDomain,
93
94
  signInUrl = "https://app.viyv.io/signin",
94
95
  skipEntitlement = false,
96
+ devAccount,
95
97
  children
96
98
  }) {
97
99
  const clientRef = useRef(null);
@@ -107,7 +109,7 @@ function AccountProvider({
107
109
  async (signal) => {
108
110
  try {
109
111
  setError(null);
110
- const result = await loadAccount(apiBase, { skipEntitlement, signal });
112
+ const result = await loadAccount(apiBase, { skipEntitlement, signal, devAccount });
111
113
  setUser(result.user);
112
114
  setActiveOrg(result.activeOrg);
113
115
  setEntitlement(result.entitlement);
@@ -121,7 +123,7 @@ function AccountProvider({
121
123
  setStatus("unauthenticated");
122
124
  }
123
125
  },
124
- [apiBase, skipEntitlement]
126
+ [apiBase, skipEntitlement, devAccount]
125
127
  );
126
128
  useEffect(() => {
127
129
  const ctrl = new AbortController();
@@ -201,6 +203,6 @@ function SignOutButton({ children, className, onSignedOut }) {
201
203
  );
202
204
  }
203
205
 
204
- export { AccountProvider, SignInButton, SignOutButton, useAccount, useActiveOrg, useEntitlement, useUser };
206
+ export { AccountProvider, SignInButton, SignOutButton, loadAccount, useAccount, useActiveOrg, useEntitlement, useUser };
205
207
  //# sourceMappingURL=react.js.map
206
208
  //# sourceMappingURL=react.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viyv/account-client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "React SDK for viyv account SSO (useUser, useEntitlement, AccountProvider).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -36,6 +36,12 @@
36
36
  "access": "public"
37
37
  },
38
38
  "sideEffects": false,
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "typecheck": "tsc --noEmit",
42
+ "lint": "biome check .",
43
+ "test": "vitest run"
44
+ },
39
45
  "peerDependencies": {
40
46
  "react": ">=18"
41
47
  },
@@ -48,17 +54,11 @@
48
54
  "better-auth": "^1.6.12"
49
55
  },
50
56
  "devDependencies": {
57
+ "@viyv/shared": "workspace:*",
51
58
  "@types/react": "^19.2.3",
52
59
  "react": "^19.2.6",
53
60
  "tsup": "^8.5.1",
54
61
  "typescript": "^5.9.3",
55
- "vitest": "^3.2.4",
56
- "@viyv/shared": "0.0.0"
57
- },
58
- "scripts": {
59
- "build": "tsup",
60
- "typecheck": "tsc --noEmit",
61
- "lint": "biome check .",
62
- "test": "vitest run"
62
+ "vitest": "^3.2.4"
63
63
  }
64
- }
64
+ }
package/LICENSE DELETED
@@ -1,27 +0,0 @@
1
- Copyright (c) 2026 viyv. All Rights Reserved.
2
-
3
- PROPRIETARY AND CONFIDENTIAL
4
-
5
- This software and its source code (the "Software") are the proprietary and
6
- confidential property of viyv. Unauthorized copying, distribution,
7
- modification, public display, public performance, reverse engineering, or
8
- commercial use of the Software, in whole or in part, via any medium, is
9
- strictly prohibited without the express prior written permission of viyv.
10
-
11
- No license, express or implied, by estoppel or otherwise, to any intellectual
12
- property rights is granted by this document. The receipt or possession of the
13
- Software does not convey or imply any right to use, reproduce, disclose, or
14
- distribute its contents.
15
-
16
- Separately published SDK packages (e.g. @viyv/account-client,
17
- @viyv/license-verify) may be distributed as compiled artifacts under their own
18
- published package terms; that distribution does not grant any rights to this
19
- repository's source code.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
- SOFTWARE.