@orangecheck/auth-client 2.1.1 → 2.3.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/index.d.mts CHANGED
@@ -139,13 +139,26 @@ interface UseWebAuthnRegisterReturn {
139
139
  reset: () => void;
140
140
  }
141
141
  declare function useWebAuthnRegister(opts?: UseHostOptions): UseWebAuthnRegisterReturn;
142
+ type WebAuthnRenameResult = {
143
+ ok: true;
144
+ credential: WebAuthnCredentialPublic;
145
+ } | {
146
+ ok: false;
147
+ reason: string;
148
+ };
149
+ type WebAuthnRemoveResult = {
150
+ ok: true;
151
+ } | {
152
+ ok: false;
153
+ reason: string;
154
+ };
142
155
  interface UseWebAuthnListReturn {
143
156
  status: WebAuthnListStatus;
144
157
  credentials: WebAuthnCredentialPublic[];
145
158
  error: Error | null;
146
159
  refetch: () => Promise<void>;
147
- rename: (id: string, label: string) => Promise<WebAuthnCredentialPublic | null>;
148
- remove: (id: string) => Promise<boolean>;
160
+ rename: (id: string, label: string) => Promise<WebAuthnRenameResult>;
161
+ remove: (id: string) => Promise<WebAuthnRemoveResult>;
149
162
  }
150
163
  declare function useWebAuthnList(opts?: UseHostOptions): UseWebAuthnListReturn;
151
164
  type WebAuthnStepUpResult = {
@@ -165,4 +178,16 @@ interface UseStepUpAuthReturn {
165
178
  }
166
179
  declare function useStepUpAuth(opts?: UseHostOptions): UseStepUpAuthReturn;
167
180
 
168
- export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnStepUpResult, buildSignInUrl, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
181
+ interface RedirectToSudoArgs {
182
+ returnTo?: string;
183
+ purpose?: string;
184
+ config?: OcAuthConfig;
185
+ }
186
+ declare function redirectToSudo(args?: RedirectToSudoArgs): void;
187
+ declare function handleSudoRequired(body: {
188
+ reason?: string;
189
+ } | null | undefined, args?: Omit<RedirectToSudoArgs, 'returnTo'> & {
190
+ returnTo?: string;
191
+ }): boolean;
192
+
193
+ export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type RedirectToSudoArgs, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildSignInUrl, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
package/dist/index.d.ts CHANGED
@@ -139,13 +139,26 @@ interface UseWebAuthnRegisterReturn {
139
139
  reset: () => void;
140
140
  }
141
141
  declare function useWebAuthnRegister(opts?: UseHostOptions): UseWebAuthnRegisterReturn;
142
+ type WebAuthnRenameResult = {
143
+ ok: true;
144
+ credential: WebAuthnCredentialPublic;
145
+ } | {
146
+ ok: false;
147
+ reason: string;
148
+ };
149
+ type WebAuthnRemoveResult = {
150
+ ok: true;
151
+ } | {
152
+ ok: false;
153
+ reason: string;
154
+ };
142
155
  interface UseWebAuthnListReturn {
143
156
  status: WebAuthnListStatus;
144
157
  credentials: WebAuthnCredentialPublic[];
145
158
  error: Error | null;
146
159
  refetch: () => Promise<void>;
147
- rename: (id: string, label: string) => Promise<WebAuthnCredentialPublic | null>;
148
- remove: (id: string) => Promise<boolean>;
160
+ rename: (id: string, label: string) => Promise<WebAuthnRenameResult>;
161
+ remove: (id: string) => Promise<WebAuthnRemoveResult>;
149
162
  }
150
163
  declare function useWebAuthnList(opts?: UseHostOptions): UseWebAuthnListReturn;
151
164
  type WebAuthnStepUpResult = {
@@ -165,4 +178,16 @@ interface UseStepUpAuthReturn {
165
178
  }
166
179
  declare function useStepUpAuth(opts?: UseHostOptions): UseStepUpAuthReturn;
167
180
 
168
- export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnStepUpResult, buildSignInUrl, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
181
+ interface RedirectToSudoArgs {
182
+ returnTo?: string;
183
+ purpose?: string;
184
+ config?: OcAuthConfig;
185
+ }
186
+ declare function redirectToSudo(args?: RedirectToSudoArgs): void;
187
+ declare function handleSudoRequired(body: {
188
+ reason?: string;
189
+ } | null | undefined, args?: Omit<RedirectToSudoArgs, 'returnTo'> & {
190
+ returnTo?: string;
191
+ }): boolean;
192
+
193
+ export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type RedirectToSudoArgs, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildSignInUrl, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
package/dist/index.js CHANGED
@@ -1395,14 +1395,16 @@ function useWebAuthnList(opts) {
1395
1395
  });
1396
1396
  const j = await r.json();
1397
1397
  if (!j.ok || !j.credential) {
1398
- setError(new Error(j.reason ?? "rename_failed"));
1399
- return null;
1398
+ const reason = j.reason ?? `rename_failed_${r.status}`;
1399
+ setError(new Error(reason));
1400
+ return { ok: false, reason };
1400
1401
  }
1401
1402
  await refetch();
1402
- return j.credential;
1403
+ return { ok: true, credential: j.credential };
1403
1404
  } catch (e) {
1404
- setError(e instanceof Error ? e : new Error(String(e)));
1405
- return null;
1405
+ const reason = e instanceof Error ? e.message : String(e);
1406
+ setError(new Error(reason));
1407
+ return { ok: false, reason };
1406
1408
  }
1407
1409
  },
1408
1410
  [authOrigin, refetch]
@@ -1416,14 +1418,16 @@ function useWebAuthnList(opts) {
1416
1418
  });
1417
1419
  const j = await r.json();
1418
1420
  if (!j.ok) {
1419
- setError(new Error(j.reason ?? "delete_failed"));
1420
- return false;
1421
+ const reason = j.reason ?? `delete_failed_${r.status}`;
1422
+ setError(new Error(reason));
1423
+ return { ok: false, reason };
1421
1424
  }
1422
1425
  await refetch();
1423
- return true;
1426
+ return { ok: true };
1424
1427
  } catch (e) {
1425
- setError(e instanceof Error ? e : new Error(String(e)));
1426
- return false;
1428
+ const reason = e instanceof Error ? e.message : String(e);
1429
+ setError(new Error(reason));
1430
+ return { ok: false, reason };
1427
1431
  }
1428
1432
  },
1429
1433
  [authOrigin, refetch]
@@ -1502,6 +1506,28 @@ function useStepUpAuth(opts) {
1502
1506
  return { status, error, stepUp, reset };
1503
1507
  }
1504
1508
 
1509
+ // src/sudo.tsx
1510
+ function redirectToSudo(args = {}) {
1511
+ if (typeof window === "undefined") {
1512
+ throw new Error(
1513
+ "[@orangecheck/auth-client] redirectToSudo() requires a browser environment"
1514
+ );
1515
+ }
1516
+ const cfg = resolveConfig(args.config);
1517
+ const url = new URL("/sudo", cfg.authOrigin);
1518
+ const returnTo = args.returnTo ?? window.location.href;
1519
+ if (returnTo) url.searchParams.set("return_to", returnTo);
1520
+ if (args.purpose) url.searchParams.set("purpose", args.purpose);
1521
+ window.location.assign(url.toString());
1522
+ }
1523
+ function handleSudoRequired(body, args = {}) {
1524
+ if (body && body.reason === "sudo_required") {
1525
+ redirectToSudo(args);
1526
+ return true;
1527
+ }
1528
+ return false;
1529
+ }
1530
+
1505
1531
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
1506
1532
  exports.OcAccountChip = OcAccountChip;
1507
1533
  exports.OcAccountPill = OcAccountPill;
@@ -1510,6 +1536,8 @@ exports.OcSessionProvider = OcSessionProvider;
1510
1536
  exports.OcSignIn = OcSignIn;
1511
1537
  exports.OcSignInButton = OcSignInButton;
1512
1538
  exports.buildSignInUrl = buildSignInUrl;
1539
+ exports.handleSudoRequired = handleSudoRequired;
1540
+ exports.redirectToSudo = redirectToSudo;
1513
1541
  exports.useOcAddressSuggestion = useOcAddressSuggestion;
1514
1542
  exports.useOcSession = useOcSession;
1515
1543
  exports.useOptionalOcSession = useOptionalOcSession;