@palbase/web 6.0.0 → 7.1.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.
Files changed (37) hide show
  1. package/dist/{analytics-facade-Cp3d4QI-.d.ts → analytics-facade-CZIwbsvG.d.ts} +65 -1
  2. package/dist/{analytics-facade-CaluA4bW.d.cts → analytics-facade-esr6cOBN.d.cts} +65 -1
  3. package/dist/{chunk-BNAGRUIQ.js → chunk-ACCJV6FV.js} +32 -2
  4. package/dist/chunk-ACCJV6FV.js.map +1 -0
  5. package/dist/{chunk-KOJ4OAAR.js → chunk-P6TWUWZC.js} +209 -3
  6. package/dist/chunk-P6TWUWZC.js.map +1 -0
  7. package/dist/{chunk-OWLTZG2V.js → chunk-ZC6Q3GPX.js} +2 -2
  8. package/dist/index.cjs +207 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +3 -3
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +2 -2
  13. package/dist/internal.cjs +238 -2
  14. package/dist/internal.cjs.map +1 -1
  15. package/dist/internal.d.cts +3 -3
  16. package/dist/internal.d.ts +3 -3
  17. package/dist/internal.js +2 -2
  18. package/dist/next/client.cjs +238 -2
  19. package/dist/next/client.cjs.map +1 -1
  20. package/dist/next/client.js +2 -2
  21. package/dist/next/index.cjs +238 -2
  22. package/dist/next/index.cjs.map +1 -1
  23. package/dist/next/index.d.cts +2 -2
  24. package/dist/next/index.d.ts +2 -2
  25. package/dist/next/index.js +3 -3
  26. package/dist/next/proxy.js +2 -2
  27. package/dist/{pb-DUK5qy81.d.ts → pb-AWwslm5m.d.ts} +1 -1
  28. package/dist/{pb-DvV6ftmf.d.cts → pb-BT-vKA4j.d.cts} +1 -1
  29. package/dist/react/index.cjs +1 -1
  30. package/dist/react/index.cjs.map +1 -1
  31. package/dist/react/index.d.cts +1 -1
  32. package/dist/react/index.d.ts +1 -1
  33. package/dist/react/index.js +2 -2
  34. package/package.json +1 -1
  35. package/dist/chunk-BNAGRUIQ.js.map +0 -1
  36. package/dist/chunk-KOJ4OAAR.js.map +0 -1
  37. /package/dist/{chunk-OWLTZG2V.js.map → chunk-ZC6Q3GPX.js.map} +0 -0
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 UnreadView, V as Unsubscribe } from './analytics-facade-CaluA4bW.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-esr6cOBN.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-DvV6ftmf.cjs';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-BT-vKA4j.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 = "6.0.0";
209
+ declare const VERSION = "7.1.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 UnreadView, V as Unsubscribe } from './analytics-facade-Cp3d4QI-.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-CZIwbsvG.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-DUK5qy81.js';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-AWwslm5m.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 = "6.0.0";
209
+ declare const VERSION = "7.1.0";
210
210
 
211
211
  export { VERSION, initMls };
package/dist/index.js CHANGED
@@ -11,11 +11,11 @@ import {
11
11
  localStorageSessionStorage,
12
12
  memorySessionStorage,
13
13
  pb
14
- } from "./chunk-KOJ4OAAR.js";
14
+ } from "./chunk-P6TWUWZC.js";
15
15
  import {
16
16
  BackendError,
17
17
  isBackendError
18
- } from "./chunk-BNAGRUIQ.js";
18
+ } from "./chunk-ACCJV6FV.js";
19
19
  import "./chunk-CFDU23TB.js";
20
20
  import "./chunk-PZ5AY32C.js";
21
21
  export {
package/dist/internal.cjs CHANGED
@@ -54,6 +54,27 @@ var PalbaseError = class extends Error {
54
54
  this.details = details;
55
55
  }
56
56
  };
57
+ function detectPlatform() {
58
+ if (typeof Deno !== "undefined") {
59
+ return "deno";
60
+ }
61
+ if (process?.versions) {
62
+ if ("bun" in process.versions) {
63
+ return "bun";
64
+ }
65
+ if ("node" in process.versions) {
66
+ return "node";
67
+ }
68
+ }
69
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
70
+ return "react-native";
71
+ }
72
+ return "browser";
73
+ }
74
+ function wirePlatform() {
75
+ const host = detectPlatform();
76
+ return host === "browser" ? "web" : host;
77
+ }
57
78
  var PALBASE_DEFAULT_HOST = "api.palbase.studio";
58
79
  var API_KEY_RE = /^pb_([a-z0-9]{4,24})_c[A-Za-z0-9]{20}$/;
59
80
  function parseEnvironmentRef(apiKey) {
@@ -139,8 +160,17 @@ var HttpClient = class _HttpClient {
139
160
  }
140
161
  buildHeaders(options) {
141
162
  const headers = {
142
- "Content-Type": "application/json"
163
+ "Content-Type": "application/json",
164
+ // Client identity, the web counterpart of the iOS SDK's
165
+ // ClientInfo.augment(). The server reads these to resolve flag targeting
166
+ // conditions and to label telemetry, so an app declares nothing and calls
167
+ // nothing — whatever the SDK can know, it sends.
168
+ "X-Platform": wirePlatform()
143
169
  };
170
+ const appVersion = this.options?.appVersion?.trim();
171
+ if (appVersion) {
172
+ headers["X-Palbase-Client-Version"] = appVersion;
173
+ }
144
174
  const effectiveKey = this.apiKey;
145
175
  if (effectiveKey) {
146
176
  headers["apikey"] = effectiveKey;
@@ -1448,6 +1478,162 @@ function asWireAuthResult(raw) {
1448
1478
  return raw;
1449
1479
  }
1450
1480
 
1481
+ // src/passkey.ts
1482
+ function base64UrlToBytes(value) {
1483
+ const padded = value.replace(/-/g, "+").replace(/_/g, "/");
1484
+ const binary = atob(padded.padEnd(padded.length + (4 - padded.length % 4) % 4, "="));
1485
+ const bytes = new Uint8Array(new ArrayBuffer(binary.length));
1486
+ for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
1487
+ return bytes;
1488
+ }
1489
+ function bytesToBase64Url(buffer) {
1490
+ const bytes = new Uint8Array(buffer);
1491
+ let binary = "";
1492
+ for (const b of bytes) binary += String.fromCharCode(b);
1493
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1494
+ }
1495
+ function requireString(source, key) {
1496
+ const value = source[key];
1497
+ if (typeof value !== "string" || value === "") {
1498
+ throw new Error(`passkey options are missing ${key}`);
1499
+ }
1500
+ return value;
1501
+ }
1502
+ function toCreationOptions(publicKey) {
1503
+ const rp = publicKey.rp;
1504
+ const user = publicKey.user;
1505
+ if (!user?.id) {
1506
+ throw new Error("passkey options carry no user id \u2014 the credential would be unusable");
1507
+ }
1508
+ const excludeCredentials = Array.isArray(publicKey.excludeCredentials) ? publicKey.excludeCredentials.map((c) => ({
1509
+ id: base64UrlToBytes(c.id),
1510
+ type: "public-key"
1511
+ })) : void 0;
1512
+ return {
1513
+ challenge: base64UrlToBytes(requireString(publicKey, "challenge")),
1514
+ rp: { id: rp?.id, name: rp?.name ?? rp?.id ?? "" },
1515
+ user: {
1516
+ id: base64UrlToBytes(user.id),
1517
+ name: user.name ?? "",
1518
+ displayName: user.displayName ?? user.name ?? ""
1519
+ },
1520
+ pubKeyCredParams: publicKey.pubKeyCredParams ?? [],
1521
+ authenticatorSelection: publicKey.authenticatorSelection,
1522
+ timeout: publicKey.timeout,
1523
+ attestation: publicKey.attestation,
1524
+ excludeCredentials
1525
+ };
1526
+ }
1527
+ function toRequestOptions(publicKey) {
1528
+ const allowCredentials = Array.isArray(publicKey.allowCredentials) ? publicKey.allowCredentials.map((c) => ({
1529
+ id: base64UrlToBytes(c.id),
1530
+ type: "public-key"
1531
+ })) : void 0;
1532
+ return {
1533
+ challenge: base64UrlToBytes(requireString(publicKey, "challenge")),
1534
+ rpId: publicKey.rpId,
1535
+ timeout: publicKey.timeout,
1536
+ userVerification: publicKey.userVerification,
1537
+ allowCredentials
1538
+ };
1539
+ }
1540
+ function attestationToJSON(credential) {
1541
+ const response = credential.response;
1542
+ return {
1543
+ id: credential.id,
1544
+ rawId: bytesToBase64Url(credential.rawId),
1545
+ type: credential.type,
1546
+ response: {
1547
+ clientDataJSON: bytesToBase64Url(response.clientDataJSON),
1548
+ attestationObject: bytesToBase64Url(response.attestationObject)
1549
+ }
1550
+ };
1551
+ }
1552
+ function assertionToJSON(credential) {
1553
+ const response = credential.response;
1554
+ return {
1555
+ id: credential.id,
1556
+ rawId: bytesToBase64Url(credential.rawId),
1557
+ type: credential.type,
1558
+ response: {
1559
+ clientDataJSON: bytesToBase64Url(response.clientDataJSON),
1560
+ authenticatorData: bytesToBase64Url(response.authenticatorData),
1561
+ signature: bytesToBase64Url(response.signature),
1562
+ // The user handle is how palauth resolves WHO signed in on a discoverable
1563
+ // login — there is no identifier in the request.
1564
+ userHandle: response.userHandle ? bytesToBase64Url(response.userHandle) : null
1565
+ }
1566
+ };
1567
+ }
1568
+ function isPasskeySupported() {
1569
+ return typeof window !== "undefined" && typeof window.PublicKeyCredential === "function" && typeof navigator !== "undefined" && navigator.credentials !== void 0;
1570
+ }
1571
+ function ensureSupported() {
1572
+ if (!isPasskeySupported()) {
1573
+ throw new Error("This browser cannot use passkeys \u2014 offer a password or e-mail sign-in");
1574
+ }
1575
+ }
1576
+ async function createCredential(publicKey) {
1577
+ const credential = await navigator.credentials.create({
1578
+ publicKey: toCreationOptions(publicKey)
1579
+ });
1580
+ if (credential === null) {
1581
+ throw new Error("the browser returned no credential");
1582
+ }
1583
+ return credential;
1584
+ }
1585
+ async function getCredential(publicKey) {
1586
+ const credential = await navigator.credentials.get({
1587
+ publicKey: toRequestOptions(publicKey)
1588
+ });
1589
+ if (credential === null) {
1590
+ throw new Error("the browser returned no credential");
1591
+ }
1592
+ return credential;
1593
+ }
1594
+ async function passkeySignIn(rt) {
1595
+ ensureSupported();
1596
+ const envelope = await palbeRequest(rt, "POST", "/auth/webauthn/login/begin", {
1597
+ body: {}
1598
+ });
1599
+ const credential = await getCredential(envelope.options.publicKey);
1600
+ const raw = await palbeRequest(rt, "POST", "/auth/webauthn/login/finish", {
1601
+ body: assertionToJSON(credential)
1602
+ });
1603
+ const result = asWireAuthResult(raw);
1604
+ if (result === null) {
1605
+ throw new Error("passkey sign-in returned an unusable session");
1606
+ }
1607
+ return result;
1608
+ }
1609
+ async function passkeySignUp(rt, email, displayName) {
1610
+ ensureSupported();
1611
+ const begun = await palbeRequest(rt, "POST", "/auth/webauthn/signup/begin", {
1612
+ body: { email, user_name: displayName }
1613
+ });
1614
+ const credential = await createCredential(begun.options.publicKey);
1615
+ await palbeRequest(
1616
+ rt,
1617
+ "POST",
1618
+ `/auth/webauthn/signup/finish?user_id=${encodeURIComponent(begun.user_id)}`,
1619
+ { body: attestationToJSON(credential) }
1620
+ );
1621
+ return await passkeySignIn(rt);
1622
+ }
1623
+ async function passkeyRegister(rt, name) {
1624
+ ensureSupported();
1625
+ const envelope = await palbeRequest(
1626
+ rt,
1627
+ "POST",
1628
+ "/auth/webauthn/register/begin",
1629
+ { body: { name } }
1630
+ );
1631
+ const credential = await createCredential(envelope.options.publicKey);
1632
+ await palbeRequest(rt, "POST", "/auth/webauthn/register/finish", {
1633
+ body: attestationToJSON(credential)
1634
+ });
1635
+ }
1636
+
1451
1637
  // src/auth-facade.ts
1452
1638
  function mapWireUser(raw) {
1453
1639
  return {
@@ -1584,6 +1770,23 @@ var PalbeAuth = class {
1584
1770
  const raw = await palbeRequest(this.rt, "GET", "/auth/user");
1585
1771
  return mapWireUser(raw);
1586
1772
  }
1773
+ /**
1774
+ * Which credentials this account actually has.
1775
+ *
1776
+ * An account reached through Google has no password, so showing it a
1777
+ * "current password" field gives the user something they can never fill —
1778
+ * and `getUser()` cannot tell you, because GET /auth/user carries no
1779
+ * credential information. Read this before rendering any re-auth or
1780
+ * change-password form.
1781
+ */
1782
+ async getSignInMethods() {
1783
+ const raw = await palbeRequest(this.rt, "GET", "/auth/me");
1784
+ return {
1785
+ password: raw.has_password,
1786
+ mfa: raw.has_mfa,
1787
+ providers: raw.providers ?? null
1788
+ };
1789
+ }
1587
1790
  async refreshUser() {
1588
1791
  const user = await this.getUser();
1589
1792
  const changed = !usersEqual(user, this.cachedUser);
@@ -1785,6 +1988,39 @@ var PalbeAuth = class {
1785
1988
  return this.adopt(data);
1786
1989
  });
1787
1990
  }
1991
+ /**
1992
+ * Sign in with a passkey stored for this Environment. No identifier is typed:
1993
+ * the browser lists the accounts it holds and the user picks one.
1994
+ *
1995
+ * Throws when the browser cannot run a ceremony — check `passkeysSupported`
1996
+ * first and keep a password or e-mail path beside the button.
1997
+ */
1998
+ async signInWithPasskey() {
1999
+ return this.withSigningIn(async () => this.adoptWire(await passkeySignIn(this.rt)));
2000
+ }
2001
+ /**
2002
+ * Create an account whose only credential is a passkey — the e-mail is the
2003
+ * identifier, the passkey is the credential, and no password ever exists.
2004
+ */
2005
+ async signUpWithPasskey(email, displayName) {
2006
+ return this.withSigningIn(
2007
+ async () => this.adoptWire(await passkeySignUp(this.rt, email, displayName))
2008
+ );
2009
+ }
2010
+ /**
2011
+ * Add a passkey to the signed-in account, so the next sign-in is one tap.
2012
+ *
2013
+ * Rejects with a 403 `reauthentication_required` when the session is not
2014
+ * recent: a passkey outlives a password reset, so enrolling one takes more
2015
+ * than a valid session.
2016
+ */
2017
+ async registerPasskey(name) {
2018
+ await passkeyRegister(this.rt, name);
2019
+ }
2020
+ /** Whether this browser can run a passkey ceremony at all. */
2021
+ get passkeysSupported() {
2022
+ return isPasskeySupported();
2023
+ }
1788
2024
  async signInWithOAuth(params) {
1789
2025
  const { redirect = true, ...opts } = params;
1790
2026
  const { url } = unwrap(await this.rt.authClient.getOAuthURL(opts));
@@ -9028,7 +9264,7 @@ function defaultSessionStorage(key) {
9028
9264
  }
9029
9265
 
9030
9266
  // src/version.ts
9031
- var VERSION = "6.0.0";
9267
+ var VERSION = "7.1.0";
9032
9268
 
9033
9269
  // src/runtime.ts
9034
9270
  function buildRuntime(config) {