ab-ecosystem-sso 0.1.10 → 0.1.12

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/README.md CHANGED
@@ -199,6 +199,7 @@ const [open, setOpen] = useState(false);
199
199
  | `token` | `string` | Bearer token. |
200
200
  | `apiBaseUrl` | `string` | Optional API origin. |
201
201
  | `initialSection` | `"general" \| "account" \| "wallet" \| "plans" \| "credits"` | First section shown. Default `"general"`. |
202
+ | `syncUrlHash` | `boolean` | Mirror open state + active section in the URL hash. Default `true`. See [URL hash & refresh](#url-hash--refresh). |
202
203
  | `title` | `string` | Modal heading. Default `"Settings"`. |
203
204
  | `data` | `Partial<AccountSettingsData>` | Override sample data (non-API mode / previews). |
204
205
  | `onLogout` | `() => void` | Sign-out action (closes the modal, then runs this). |
@@ -209,6 +210,23 @@ const [open, setOpen] = useState(false);
209
210
 
210
211
  > In live mode the modal performs the API calls itself (save profile, change password, subscribe, recharge, etc.); the callbacks are observation hooks, not required wiring.
211
212
 
213
+ ### URL hash & refresh
214
+
215
+ While the modal is open it reflects the active section in the URL hash as `#settings-<section>` (e.g. `#settings-general`, `#settings-plans`), updating as the user switches tabs and clearing it on close. This means a **page refresh can re-open the modal on the same section**. It uses `history.replaceState`, so it never adds browser-history entries and never clobbers an unrelated `#anchor`. Opt out with `syncUrlHash={false}`.
216
+
217
+ - **Declarative** `<AccountSettings>`: keep it mounted (even while closed) and wire `open`/`onOpenChange` normally — on load it reads the hash and calls `onOpenChange(true)` for you.
218
+ - **Imperative** `openAccountSettings()`: call `restoreAccountSettings()` once on app load to re-open it after a refresh:
219
+
220
+ ```tsx
221
+ import { restoreAccountSettings } from "ab-ecosystem-sso";
222
+
223
+ useEffect(() => {
224
+ restoreAccountSettings({ projectId: "your-project-id", token, apiBaseUrl: "https://your-api" });
225
+ }, []);
226
+ ```
227
+
228
+ It opens the modal (on the hash's section) only when a `#settings-*` hash is present, and returns the modal handle (or `null`).
229
+
212
230
  ---
213
231
 
214
232
  ## Logout
@@ -282,9 +300,9 @@ const subscription = await getUserSubscription("your-project-id", token, "https
282
300
  | `getUserProfile` | `GET /me` | `MappedProfile` — flat fields (name, `email`/`username`, address, phone, `mainWallet`/`coinWallet`). |
283
301
  | `getUserWallet` | `GET /me` | `UserWallets` — just `{ mainWallet, coinWallet }` balances. |
284
302
  | `getUserCreditWallet` | `GET /credit-wallets` | `CreditWallet[]` — each `{ id, label, balance, balanceFormatted, creditUnit, fundSource, rechargeable }`. |
285
- | `getUserSubscription` | `GET /subscription` | `MappedSubscription` — `planId` (empty if none), `status`, `renewsAt`, `subscribedIds`, `packageCounts`. |
303
+ | `getUserSubscription` | `GET /subscription` | The **raw** subscription object from the API (unmapped). |
286
304
 
287
- > `getUserProfile` and `getUserWallet` both read `/me`; `getUserWallet` just narrows the same response to the wallet balances. All four throw `AccountApiError` on a non-2xx response.
305
+ > `getUserProfile` and `getUserWallet` both read `/me`; `getUserWallet` just narrows the same response to the wallet balances. `getUserSubscription` returns the API response as-is (the unwrapped `data`), unlike the others which map to a friendly shape. All four throw `AccountApiError` on a non-2xx response.
288
306
 
289
307
  ---
290
308
 
@@ -344,11 +362,12 @@ Beyond the components, these functions are exported for building custom UIs:
344
362
 
345
363
  | Function | Endpoint |
346
364
  | --- | --- |
365
+ | `getAuthConfig(projectId, apiBaseUrl?)` | `GET /auth-config` → `AuthConfig` (captcha, branding, card layout; no token) |
347
366
  | `getUser(projectId, token, apiBaseUrl?)` | `GET /me` (raw envelope) |
348
367
  | `getUserProfile(projectId, token, apiBaseUrl?)` | `GET /me` → `MappedProfile` |
349
368
  | `getUserWallet(projectId, token, apiBaseUrl?)` | `GET /me` → `UserWallets` |
350
369
  | `getUserCreditWallet(projectId, token, apiBaseUrl?)` | `GET /credit-wallets` → `CreditWallet[]` |
351
- | `getUserSubscription(projectId, token, apiBaseUrl?)` | `GET /subscription` → `MappedSubscription` |
370
+ | `getUserSubscription(projectId, token, apiBaseUrl?)` | `GET /subscription` → raw subscription object |
352
371
  | `logout(options)` | `POST /auth/logout` + callbacks |
353
372
  | `logoutApi(projectId, token, apiBaseUrl?)` | `POST /auth/logout` |
354
373