@vaultix.ai/react 0.3.1 → 0.3.2

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/index.d.mts CHANGED
@@ -42,6 +42,22 @@ interface VaultixSession {
42
42
  expiresAt: number;
43
43
  claims: SessionClaims;
44
44
  }
45
+ interface ConnectPlatformOptions {
46
+ /** OAuth scopes to request. Joined by the provider's delimiter (space or comma). */
47
+ scopes?: string[];
48
+ /**
49
+ * Meta-specific: a Login Config ID registered on the Vaultix Meta app.
50
+ * When provided, takes precedence over `scopes` (Meta's rule).
51
+ */
52
+ configId?: string;
53
+ /**
54
+ * Extra provider-specific params forwarded to the authorization URL.
55
+ * e.g. { shop: "mystore.myshopify.com" } for Shopify.
56
+ */
57
+ extraParams?: Record<string, string>;
58
+ /** Where to redirect after the user authorizes. Defaults to current page. */
59
+ redirectUrl?: string;
60
+ }
45
61
  interface VaultixContextValue {
46
62
  user: VaultixUser | null;
47
63
  session: VaultixSession | null;
@@ -49,6 +65,13 @@ interface VaultixContextValue {
49
65
  isLoaded: boolean;
50
66
  isSignedIn: boolean;
51
67
  signOut: () => Promise<void>;
68
+ /**
69
+ * Initiate a platform OAuth connection flow (posting, reading, etc.).
70
+ * Redirects the user to the provider's authorization page via Vaultix.
71
+ * On completion, Vaultix redirects back with `__vaultix_connect` + `provider`
72
+ * query params that your app exchanges via POST /oauth/{provider}/connect-complete.
73
+ */
74
+ connectPlatform: (provider: string, options?: ConnectPlatformOptions) => void;
52
75
  }
53
76
  interface VaultixProviderProps {
54
77
  publishableKey: string;
@@ -149,4 +172,9 @@ interface OrganizationSwitcherProps {
149
172
  }
150
173
  declare function OrganizationSwitcher({ afterSwitchUrl, className, }: OrganizationSwitcherProps): react_jsx_runtime.JSX.Element | null;
151
174
 
152
- export { type ChallengeType, OrganizationSwitcher, RedirectToSignIn, RedirectToSignUp, type RiskLevel, type SessionClaims, SignIn, SignUp, SignedIn, SignedOut, UserButton, type VaultixContextValue, type VaultixOrganization, VaultixProvider, type VaultixProviderProps, type VaultixSession, type VaultixUser, useAuth, useOrganization, useSession, useUser, useVaultix };
175
+ /** Returns the stored session JWT, or null if not signed in. */
176
+ declare function getStoredToken(): string | null;
177
+ /** Clears the stored session JWT. Call on 401 so the user is prompted to sign in again. */
178
+ declare function clearStoredToken(): void;
179
+
180
+ export { type ChallengeType, type ConnectPlatformOptions, OrganizationSwitcher, RedirectToSignIn, RedirectToSignUp, type RiskLevel, type SessionClaims, SignIn, SignUp, SignedIn, SignedOut, UserButton, type VaultixContextValue, type VaultixOrganization, VaultixProvider, type VaultixProviderProps, type VaultixSession, type VaultixUser, clearStoredToken, getStoredToken, useAuth, useOrganization, useSession, useUser, useVaultix };
package/dist/index.d.ts CHANGED
@@ -42,6 +42,22 @@ interface VaultixSession {
42
42
  expiresAt: number;
43
43
  claims: SessionClaims;
44
44
  }
45
+ interface ConnectPlatformOptions {
46
+ /** OAuth scopes to request. Joined by the provider's delimiter (space or comma). */
47
+ scopes?: string[];
48
+ /**
49
+ * Meta-specific: a Login Config ID registered on the Vaultix Meta app.
50
+ * When provided, takes precedence over `scopes` (Meta's rule).
51
+ */
52
+ configId?: string;
53
+ /**
54
+ * Extra provider-specific params forwarded to the authorization URL.
55
+ * e.g. { shop: "mystore.myshopify.com" } for Shopify.
56
+ */
57
+ extraParams?: Record<string, string>;
58
+ /** Where to redirect after the user authorizes. Defaults to current page. */
59
+ redirectUrl?: string;
60
+ }
45
61
  interface VaultixContextValue {
46
62
  user: VaultixUser | null;
47
63
  session: VaultixSession | null;
@@ -49,6 +65,13 @@ interface VaultixContextValue {
49
65
  isLoaded: boolean;
50
66
  isSignedIn: boolean;
51
67
  signOut: () => Promise<void>;
68
+ /**
69
+ * Initiate a platform OAuth connection flow (posting, reading, etc.).
70
+ * Redirects the user to the provider's authorization page via Vaultix.
71
+ * On completion, Vaultix redirects back with `__vaultix_connect` + `provider`
72
+ * query params that your app exchanges via POST /oauth/{provider}/connect-complete.
73
+ */
74
+ connectPlatform: (provider: string, options?: ConnectPlatformOptions) => void;
52
75
  }
53
76
  interface VaultixProviderProps {
54
77
  publishableKey: string;
@@ -149,4 +172,9 @@ interface OrganizationSwitcherProps {
149
172
  }
150
173
  declare function OrganizationSwitcher({ afterSwitchUrl, className, }: OrganizationSwitcherProps): react_jsx_runtime.JSX.Element | null;
151
174
 
152
- export { type ChallengeType, OrganizationSwitcher, RedirectToSignIn, RedirectToSignUp, type RiskLevel, type SessionClaims, SignIn, SignUp, SignedIn, SignedOut, UserButton, type VaultixContextValue, type VaultixOrganization, VaultixProvider, type VaultixProviderProps, type VaultixSession, type VaultixUser, useAuth, useOrganization, useSession, useUser, useVaultix };
175
+ /** Returns the stored session JWT, or null if not signed in. */
176
+ declare function getStoredToken(): string | null;
177
+ /** Clears the stored session JWT. Call on 401 so the user is prompted to sign in again. */
178
+ declare function clearStoredToken(): void;
179
+
180
+ export { type ChallengeType, type ConnectPlatformOptions, OrganizationSwitcher, RedirectToSignIn, RedirectToSignUp, type RiskLevel, type SessionClaims, SignIn, SignUp, SignedIn, SignedOut, UserButton, type VaultixContextValue, type VaultixOrganization, VaultixProvider, type VaultixProviderProps, type VaultixSession, type VaultixUser, clearStoredToken, getStoredToken, useAuth, useOrganization, useSession, useUser, useVaultix };
package/dist/index.js CHANGED
@@ -29,6 +29,8 @@ __export(index_exports, {
29
29
  SignedOut: () => SignedOut,
30
30
  UserButton: () => UserButton,
31
31
  VaultixProvider: () => VaultixProvider,
32
+ clearStoredToken: () => clearStoredToken,
33
+ getStoredToken: () => getStoredToken,
32
34
  useAuth: () => useAuth,
33
35
  useOrganization: () => useOrganization,
34
36
  useSession: () => useSession,
@@ -221,13 +223,25 @@ function VaultixProvider({
221
223
  });
222
224
  if (afterSignInUrl) window.location.href = afterSignInUrl;
223
225
  }, [apiOrigin, afterSignInUrl, clearAuth]);
226
+ const connectPlatform = (0, import_react.useCallback)((provider, options = {}) => {
227
+ const params = new URLSearchParams({ mode: "connect" });
228
+ params.set("redirect_url", options.redirectUrl ?? (typeof window !== "undefined" ? window.location.href : "/"));
229
+ params.set("pk", publishableKey);
230
+ if (options.scopes?.length) params.set("scope", options.scopes.join(" "));
231
+ if (options.configId) params.set("config_id", options.configId);
232
+ if (options.extraParams) Object.entries(options.extraParams).forEach(([k, v]) => params.set(k, v));
233
+ if (typeof window !== "undefined") {
234
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/${provider}/connect?${params}`;
235
+ }
236
+ }, [apiOrigin, publishableKey]);
224
237
  const value = {
225
238
  user,
226
239
  session,
227
240
  organization,
228
241
  isLoaded,
229
242
  isSignedIn: !!session,
230
- signOut
243
+ signOut,
244
+ connectPlatform
231
245
  };
232
246
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VaultixContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
233
247
  "div",
@@ -1566,6 +1580,22 @@ function MiniSpinner() {
1566
1580
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" })
1567
1581
  ] });
1568
1582
  }
1583
+
1584
+ // src/index.ts
1585
+ var STORAGE_KEY2 = "vaultix_jwt";
1586
+ function getStoredToken() {
1587
+ try {
1588
+ return (typeof sessionStorage !== "undefined" ? sessionStorage : null)?.getItem(STORAGE_KEY2) ?? null;
1589
+ } catch {
1590
+ return null;
1591
+ }
1592
+ }
1593
+ function clearStoredToken() {
1594
+ try {
1595
+ if (typeof sessionStorage !== "undefined") sessionStorage.removeItem(STORAGE_KEY2);
1596
+ } catch {
1597
+ }
1598
+ }
1569
1599
  // Annotate the CommonJS export names for ESM import in node:
1570
1600
  0 && (module.exports = {
1571
1601
  OrganizationSwitcher,
@@ -1577,6 +1607,8 @@ function MiniSpinner() {
1577
1607
  SignedOut,
1578
1608
  UserButton,
1579
1609
  VaultixProvider,
1610
+ clearStoredToken,
1611
+ getStoredToken,
1580
1612
  useAuth,
1581
1613
  useOrganization,
1582
1614
  useSession,
package/dist/index.mjs CHANGED
@@ -189,13 +189,25 @@ function VaultixProvider({
189
189
  });
190
190
  if (afterSignInUrl) window.location.href = afterSignInUrl;
191
191
  }, [apiOrigin, afterSignInUrl, clearAuth]);
192
+ const connectPlatform = useCallback((provider, options = {}) => {
193
+ const params = new URLSearchParams({ mode: "connect" });
194
+ params.set("redirect_url", options.redirectUrl ?? (typeof window !== "undefined" ? window.location.href : "/"));
195
+ params.set("pk", publishableKey);
196
+ if (options.scopes?.length) params.set("scope", options.scopes.join(" "));
197
+ if (options.configId) params.set("config_id", options.configId);
198
+ if (options.extraParams) Object.entries(options.extraParams).forEach(([k, v]) => params.set(k, v));
199
+ if (typeof window !== "undefined") {
200
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/${provider}/connect?${params}`;
201
+ }
202
+ }, [apiOrigin, publishableKey]);
192
203
  const value = {
193
204
  user,
194
205
  session,
195
206
  organization,
196
207
  isLoaded,
197
208
  isSignedIn: !!session,
198
- signOut
209
+ signOut,
210
+ connectPlatform
199
211
  };
200
212
  return /* @__PURE__ */ jsx(VaultixContext.Provider, { value, children: /* @__PURE__ */ jsx(
201
213
  "div",
@@ -1534,6 +1546,22 @@ function MiniSpinner() {
1534
1546
  /* @__PURE__ */ jsx6("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" })
1535
1547
  ] });
1536
1548
  }
1549
+
1550
+ // src/index.ts
1551
+ var STORAGE_KEY2 = "vaultix_jwt";
1552
+ function getStoredToken() {
1553
+ try {
1554
+ return (typeof sessionStorage !== "undefined" ? sessionStorage : null)?.getItem(STORAGE_KEY2) ?? null;
1555
+ } catch {
1556
+ return null;
1557
+ }
1558
+ }
1559
+ function clearStoredToken() {
1560
+ try {
1561
+ if (typeof sessionStorage !== "undefined") sessionStorage.removeItem(STORAGE_KEY2);
1562
+ } catch {
1563
+ }
1564
+ }
1537
1565
  export {
1538
1566
  OrganizationSwitcher,
1539
1567
  RedirectToSignIn,
@@ -1544,6 +1572,8 @@ export {
1544
1572
  SignedOut,
1545
1573
  UserButton,
1546
1574
  VaultixProvider,
1575
+ clearStoredToken,
1576
+ getStoredToken,
1547
1577
  useAuth,
1548
1578
  useOrganization,
1549
1579
  useSession,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaultix.ai/react",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Vaultix-ID React SDK — drop-in auth components for any React app",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",