@viyv/account-client 0.1.0 → 0.2.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.
package/dist/react.cjs CHANGED
@@ -1,8 +1,11 @@
1
+ "use client";
1
2
  'use strict';
2
3
 
3
4
  var react = require('react');
4
5
  var client = require('better-auth/client');
5
6
 
7
+ // src/components.tsx
8
+
6
9
  // src/entitlement.ts
7
10
  function parseEntitlement(wire) {
8
11
  return {
@@ -60,6 +63,7 @@ var SIGNED_OUT = {
60
63
  entitlement: null
61
64
  };
62
65
  async function loadAccount(apiBase, opts = {}) {
66
+ if (opts.devAccount) return opts.devAccount;
63
67
  const doFetch = opts.fetchImpl ?? fetch;
64
68
  const session = await fetchJson(
65
69
  doFetch,
@@ -94,6 +98,7 @@ function AccountProvider({
94
98
  cookieDomain,
95
99
  signInUrl = "https://app.viyv.io/signin",
96
100
  skipEntitlement = false,
101
+ devAccount,
97
102
  children
98
103
  }) {
99
104
  const clientRef = react.useRef(null);
@@ -109,7 +114,7 @@ function AccountProvider({
109
114
  async (signal) => {
110
115
  try {
111
116
  setError(null);
112
- const result = await loadAccount(apiBase, { skipEntitlement, signal });
117
+ const result = await loadAccount(apiBase, { skipEntitlement, signal, devAccount });
113
118
  setUser(result.user);
114
119
  setActiveOrg(result.activeOrg);
115
120
  setEntitlement(result.entitlement);
@@ -123,7 +128,7 @@ function AccountProvider({
123
128
  setStatus("unauthenticated");
124
129
  }
125
130
  },
126
- [apiBase, skipEntitlement]
131
+ [apiBase, skipEntitlement, devAccount]
127
132
  );
128
133
  react.useEffect(() => {
129
134
  const ctrl = new AbortController();
@@ -206,6 +211,7 @@ function SignOutButton({ children, className, onSignedOut }) {
206
211
  exports.AccountProvider = AccountProvider;
207
212
  exports.SignInButton = SignInButton;
208
213
  exports.SignOutButton = SignOutButton;
214
+ exports.loadAccount = loadAccount;
209
215
  exports.useAccount = useAccount;
210
216
  exports.useActiveOrg = useActiveOrg;
211
217
  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
@@ -1,6 +1,9 @@
1
+ "use client";
1
2
  import { createContext, useRef, useState, useCallback, useEffect, useMemo, createElement, useContext } from 'react';
2
3
  import { createAuthClient } from 'better-auth/client';
3
4
 
5
+ // src/components.tsx
6
+
4
7
  // src/entitlement.ts
5
8
  function parseEntitlement(wire) {
6
9
  return {
@@ -58,6 +61,7 @@ var SIGNED_OUT = {
58
61
  entitlement: null
59
62
  };
60
63
  async function loadAccount(apiBase, opts = {}) {
64
+ if (opts.devAccount) return opts.devAccount;
61
65
  const doFetch = opts.fetchImpl ?? fetch;
62
66
  const session = await fetchJson(
63
67
  doFetch,
@@ -92,6 +96,7 @@ function AccountProvider({
92
96
  cookieDomain,
93
97
  signInUrl = "https://app.viyv.io/signin",
94
98
  skipEntitlement = false,
99
+ devAccount,
95
100
  children
96
101
  }) {
97
102
  const clientRef = useRef(null);
@@ -107,7 +112,7 @@ function AccountProvider({
107
112
  async (signal) => {
108
113
  try {
109
114
  setError(null);
110
- const result = await loadAccount(apiBase, { skipEntitlement, signal });
115
+ const result = await loadAccount(apiBase, { skipEntitlement, signal, devAccount });
111
116
  setUser(result.user);
112
117
  setActiveOrg(result.activeOrg);
113
118
  setEntitlement(result.entitlement);
@@ -121,7 +126,7 @@ function AccountProvider({
121
126
  setStatus("unauthenticated");
122
127
  }
123
128
  },
124
- [apiBase, skipEntitlement]
129
+ [apiBase, skipEntitlement, devAccount]
125
130
  );
126
131
  useEffect(() => {
127
132
  const ctrl = new AbortController();
@@ -201,6 +206,6 @@ function SignOutButton({ children, className, onSignedOut }) {
201
206
  );
202
207
  }
203
208
 
204
- export { AccountProvider, SignInButton, SignOutButton, useAccount, useActiveOrg, useEntitlement, useUser };
209
+ export { AccountProvider, SignInButton, SignOutButton, loadAccount, useAccount, useActiveOrg, useEntitlement, useUser };
205
210
  //# sourceMappingURL=react.js.map
206
211
  //# 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.1",
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.