@palbase/web 7.0.0 → 7.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/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-TB-D4ww8.cjs';
1
+ export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-jyXv7Cu4.cjs';
2
2
  export { B as BackendError, a as BackendErrorKind, F as FieldError, i as isBackendError } from './errors-fDoNdTrJ.cjs';
3
- export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-CiSj4lM3.cjs';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-CfYQGEn0.cjs';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.cjs';
5
5
  export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
6
 
@@ -206,6 +206,6 @@ interface MlsGlue {
206
206
  */
207
207
  declare function initMls(): Promise<MlsGlue>;
208
208
 
209
- declare const VERSION = "7.0.0";
209
+ declare const VERSION = "7.2.0";
210
210
 
211
211
  export { VERSION, initMls };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-CdTK9Y0s.js';
1
+ export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-DLfnVVwL.js';
2
2
  export { B as BackendError, a as BackendErrorKind, F as FieldError, i as isBackendError } from './errors-fDoNdTrJ.js';
3
- export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-B6ZcZy8v.js';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-DdzpEkPY.js';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.js';
5
5
  export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
6
 
@@ -206,6 +206,6 @@ interface MlsGlue {
206
206
  */
207
207
  declare function initMls(): Promise<MlsGlue>;
208
208
 
209
- declare const VERSION = "7.0.0";
209
+ declare const VERSION = "7.2.0";
210
210
 
211
211
  export { VERSION, initMls };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  localStorageSessionStorage,
12
12
  memorySessionStorage,
13
13
  pb
14
- } from "./chunk-7SNSLY5M.js";
14
+ } from "./chunk-VXQUBBHG.js";
15
15
  import {
16
16
  BackendError,
17
17
  isBackendError
package/dist/internal.cjs CHANGED
@@ -935,6 +935,20 @@ var AuthClient = class {
935
935
  body: params
936
936
  });
937
937
  }
938
+ /**
939
+ * Give a PASSWORDLESS account its first password.
940
+ *
941
+ * Separate from `changePassword` because that one cannot serve the case: it
942
+ * sends a current password and palauth answers an account that has none with
943
+ * 401. Requires a RECENT sign-in (403 `reauthentication_required` otherwise,
944
+ * the same gate passkey enrollment carries); an account that already has a
945
+ * password gets 409 `password_already_set`.
946
+ */
947
+ async setPassword(params) {
948
+ return this.httpClient.request("POST", "/auth/password/set", {
949
+ body: params
950
+ });
951
+ }
938
952
  // ── Token ───────────────────────────────────────────────
939
953
  async refresh() {
940
954
  const refreshToken = this.tokenManager.getRefreshToken();
@@ -1478,6 +1492,162 @@ function asWireAuthResult(raw) {
1478
1492
  return raw;
1479
1493
  }
1480
1494
 
1495
+ // src/passkey.ts
1496
+ function base64UrlToBytes(value) {
1497
+ const padded = value.replace(/-/g, "+").replace(/_/g, "/");
1498
+ const binary = atob(padded.padEnd(padded.length + (4 - padded.length % 4) % 4, "="));
1499
+ const bytes = new Uint8Array(new ArrayBuffer(binary.length));
1500
+ for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
1501
+ return bytes;
1502
+ }
1503
+ function bytesToBase64Url(buffer) {
1504
+ const bytes = new Uint8Array(buffer);
1505
+ let binary = "";
1506
+ for (const b of bytes) binary += String.fromCharCode(b);
1507
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1508
+ }
1509
+ function requireString(source, key) {
1510
+ const value = source[key];
1511
+ if (typeof value !== "string" || value === "") {
1512
+ throw new Error(`passkey options are missing ${key}`);
1513
+ }
1514
+ return value;
1515
+ }
1516
+ function toCreationOptions(publicKey) {
1517
+ const rp = publicKey.rp;
1518
+ const user = publicKey.user;
1519
+ if (!user?.id) {
1520
+ throw new Error("passkey options carry no user id \u2014 the credential would be unusable");
1521
+ }
1522
+ const excludeCredentials = Array.isArray(publicKey.excludeCredentials) ? publicKey.excludeCredentials.map((c) => ({
1523
+ id: base64UrlToBytes(c.id),
1524
+ type: "public-key"
1525
+ })) : void 0;
1526
+ return {
1527
+ challenge: base64UrlToBytes(requireString(publicKey, "challenge")),
1528
+ rp: { id: rp?.id, name: rp?.name ?? rp?.id ?? "" },
1529
+ user: {
1530
+ id: base64UrlToBytes(user.id),
1531
+ name: user.name ?? "",
1532
+ displayName: user.displayName ?? user.name ?? ""
1533
+ },
1534
+ pubKeyCredParams: publicKey.pubKeyCredParams ?? [],
1535
+ authenticatorSelection: publicKey.authenticatorSelection,
1536
+ timeout: publicKey.timeout,
1537
+ attestation: publicKey.attestation,
1538
+ excludeCredentials
1539
+ };
1540
+ }
1541
+ function toRequestOptions(publicKey) {
1542
+ const allowCredentials = Array.isArray(publicKey.allowCredentials) ? publicKey.allowCredentials.map((c) => ({
1543
+ id: base64UrlToBytes(c.id),
1544
+ type: "public-key"
1545
+ })) : void 0;
1546
+ return {
1547
+ challenge: base64UrlToBytes(requireString(publicKey, "challenge")),
1548
+ rpId: publicKey.rpId,
1549
+ timeout: publicKey.timeout,
1550
+ userVerification: publicKey.userVerification,
1551
+ allowCredentials
1552
+ };
1553
+ }
1554
+ function attestationToJSON(credential) {
1555
+ const response = credential.response;
1556
+ return {
1557
+ id: credential.id,
1558
+ rawId: bytesToBase64Url(credential.rawId),
1559
+ type: credential.type,
1560
+ response: {
1561
+ clientDataJSON: bytesToBase64Url(response.clientDataJSON),
1562
+ attestationObject: bytesToBase64Url(response.attestationObject)
1563
+ }
1564
+ };
1565
+ }
1566
+ function assertionToJSON(credential) {
1567
+ const response = credential.response;
1568
+ return {
1569
+ id: credential.id,
1570
+ rawId: bytesToBase64Url(credential.rawId),
1571
+ type: credential.type,
1572
+ response: {
1573
+ clientDataJSON: bytesToBase64Url(response.clientDataJSON),
1574
+ authenticatorData: bytesToBase64Url(response.authenticatorData),
1575
+ signature: bytesToBase64Url(response.signature),
1576
+ // The user handle is how palauth resolves WHO signed in on a discoverable
1577
+ // login — there is no identifier in the request.
1578
+ userHandle: response.userHandle ? bytesToBase64Url(response.userHandle) : null
1579
+ }
1580
+ };
1581
+ }
1582
+ function isPasskeySupported() {
1583
+ return typeof window !== "undefined" && typeof window.PublicKeyCredential === "function" && typeof navigator !== "undefined" && navigator.credentials !== void 0;
1584
+ }
1585
+ function ensureSupported() {
1586
+ if (!isPasskeySupported()) {
1587
+ throw new Error("This browser cannot use passkeys \u2014 offer a password or e-mail sign-in");
1588
+ }
1589
+ }
1590
+ async function createCredential(publicKey) {
1591
+ const credential = await navigator.credentials.create({
1592
+ publicKey: toCreationOptions(publicKey)
1593
+ });
1594
+ if (credential === null) {
1595
+ throw new Error("the browser returned no credential");
1596
+ }
1597
+ return credential;
1598
+ }
1599
+ async function getCredential(publicKey) {
1600
+ const credential = await navigator.credentials.get({
1601
+ publicKey: toRequestOptions(publicKey)
1602
+ });
1603
+ if (credential === null) {
1604
+ throw new Error("the browser returned no credential");
1605
+ }
1606
+ return credential;
1607
+ }
1608
+ async function passkeySignIn(rt) {
1609
+ ensureSupported();
1610
+ const envelope = await palbeRequest(rt, "POST", "/auth/webauthn/login/begin", {
1611
+ body: {}
1612
+ });
1613
+ const credential = await getCredential(envelope.options.publicKey);
1614
+ const raw = await palbeRequest(rt, "POST", "/auth/webauthn/login/finish", {
1615
+ body: assertionToJSON(credential)
1616
+ });
1617
+ const result = asWireAuthResult(raw);
1618
+ if (result === null) {
1619
+ throw new Error("passkey sign-in returned an unusable session");
1620
+ }
1621
+ return result;
1622
+ }
1623
+ async function passkeySignUp(rt, email, displayName) {
1624
+ ensureSupported();
1625
+ const begun = await palbeRequest(rt, "POST", "/auth/webauthn/signup/begin", {
1626
+ body: { email, user_name: displayName }
1627
+ });
1628
+ const credential = await createCredential(begun.options.publicKey);
1629
+ await palbeRequest(
1630
+ rt,
1631
+ "POST",
1632
+ `/auth/webauthn/signup/finish?user_id=${encodeURIComponent(begun.user_id)}`,
1633
+ { body: attestationToJSON(credential) }
1634
+ );
1635
+ return await passkeySignIn(rt);
1636
+ }
1637
+ async function passkeyRegister(rt, name) {
1638
+ ensureSupported();
1639
+ const envelope = await palbeRequest(
1640
+ rt,
1641
+ "POST",
1642
+ "/auth/webauthn/register/begin",
1643
+ { body: { name } }
1644
+ );
1645
+ const credential = await createCredential(envelope.options.publicKey);
1646
+ await palbeRequest(rt, "POST", "/auth/webauthn/register/finish", {
1647
+ body: attestationToJSON(credential)
1648
+ });
1649
+ }
1650
+
1481
1651
  // src/auth-facade.ts
1482
1652
  function mapWireUser(raw) {
1483
1653
  return {
@@ -1809,6 +1979,26 @@ var PalbeAuth = class {
1809
1979
  })
1810
1980
  );
1811
1981
  }
1982
+ /**
1983
+ * Give a passwordless account its FIRST password, in-app.
1984
+ *
1985
+ * For accounts created with a passkey or a social provider: they have no
1986
+ * current password, so `updatePassword` cannot serve them — it sends one and
1987
+ * the server answers 401. Before this existed the only route was the
1988
+ * password-RESET e-mail, which asks someone already signed in to go find
1989
+ * their inbox.
1990
+ *
1991
+ * Requires a RECENT sign-in, not merely a session: a first password is a
1992
+ * credential that outlives the rest, so the server answers 403
1993
+ * `reauthentication_required` on a stale one — the same gate
1994
+ * `registerPasskey` carries. An account that already has a password gets 409
1995
+ * `password_already_set`; change it with `updatePassword` instead.
1996
+ *
1997
+ * The session stays valid — no re-login.
1998
+ */
1999
+ async setPassword(newPassword) {
2000
+ unwrap(await this.rt.authClient.setPassword({ new_password: newPassword }));
2001
+ }
1812
2002
  async verifyEmail(params) {
1813
2003
  unwrap(await this.rt.authClient.verifyEmail(params));
1814
2004
  }
@@ -1832,6 +2022,39 @@ var PalbeAuth = class {
1832
2022
  return this.adopt(data);
1833
2023
  });
1834
2024
  }
2025
+ /**
2026
+ * Sign in with a passkey stored for this Environment. No identifier is typed:
2027
+ * the browser lists the accounts it holds and the user picks one.
2028
+ *
2029
+ * Throws when the browser cannot run a ceremony — check `passkeysSupported`
2030
+ * first and keep a password or e-mail path beside the button.
2031
+ */
2032
+ async signInWithPasskey() {
2033
+ return this.withSigningIn(async () => this.adoptWire(await passkeySignIn(this.rt)));
2034
+ }
2035
+ /**
2036
+ * Create an account whose only credential is a passkey — the e-mail is the
2037
+ * identifier, the passkey is the credential, and no password ever exists.
2038
+ */
2039
+ async signUpWithPasskey(email, displayName) {
2040
+ return this.withSigningIn(
2041
+ async () => this.adoptWire(await passkeySignUp(this.rt, email, displayName))
2042
+ );
2043
+ }
2044
+ /**
2045
+ * Add a passkey to the signed-in account, so the next sign-in is one tap.
2046
+ *
2047
+ * Rejects with a 403 `reauthentication_required` when the session is not
2048
+ * recent: a passkey outlives a password reset, so enrolling one takes more
2049
+ * than a valid session.
2050
+ */
2051
+ async registerPasskey(name) {
2052
+ await passkeyRegister(this.rt, name);
2053
+ }
2054
+ /** Whether this browser can run a passkey ceremony at all. */
2055
+ get passkeysSupported() {
2056
+ return isPasskeySupported();
2057
+ }
1835
2058
  async signInWithOAuth(params) {
1836
2059
  const { redirect = true, ...opts } = params;
1837
2060
  const { url } = unwrap(await this.rt.authClient.getOAuthURL(opts));
@@ -9075,7 +9298,7 @@ function defaultSessionStorage(key) {
9075
9298
  }
9076
9299
 
9077
9300
  // src/version.ts
9078
- var VERSION = "7.0.0";
9301
+ var VERSION = "7.2.0";
9079
9302
 
9080
9303
  // src/runtime.ts
9081
9304
  function buildRuntime(config) {