@palbase/web 2.0.1 → 3.0.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/README.md +11 -9
- package/dist/{analytics-facade-ChlBRcLZ.d.cts → analytics-facade-BOxQ8IP2.d.cts} +8 -16
- package/dist/{analytics-facade-G0il4NrT.d.ts → analytics-facade-yfMJ69vw.d.ts} +8 -16
- package/dist/{chunk-AIPUO4QX.js → chunk-3HVTEZ7N.js} +30 -36
- package/dist/chunk-3HVTEZ7N.js.map +1 -0
- package/dist/{chunk-VJXFABBW.js → chunk-6VGKMNXO.js} +11 -11
- package/dist/chunk-6VGKMNXO.js.map +1 -0
- package/dist/chunk-S7NAY3MW.js +24 -0
- package/dist/chunk-S7NAY3MW.js.map +1 -0
- package/dist/gen/cli.cjs +32 -6
- package/dist/gen/cli.cjs.map +1 -1
- package/dist/gen/cli.js +28 -7
- package/dist/gen/cli.js.map +1 -1
- package/dist/index.cjs +3 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/internal.cjs +33 -32
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +3 -3
- package/dist/internal.d.ts +3 -3
- package/dist/internal.js +2 -2
- package/dist/next/client.cjs +50 -46
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.cts +1 -1
- package/dist/next/client.d.ts +1 -1
- package/dist/next/client.js +12 -10
- package/dist/next/client.js.map +1 -1
- package/dist/next/index.cjs +53 -47
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +10 -10
- package/dist/next/index.d.ts +10 -10
- package/dist/next/index.js +14 -13
- package/dist/next/index.js.map +1 -1
- package/dist/{pb-B_6o5p79.d.cts → pb-B3h3NIPE.d.cts} +1 -1
- package/dist/{pb-nPBhqhJr.d.ts → pb-QRISxPd1.d.ts} +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-AIPUO4QX.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-VJXFABBW.js.map +0 -1
package/dist/internal.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-
|
|
2
|
-
export { e as buildRuntime } from './analytics-facade-
|
|
1
|
+
import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-BOxQ8IP2.cjs';
|
|
2
|
+
export { e as buildRuntime } from './analytics-facade-BOxQ8IP2.cjs';
|
|
3
3
|
import { B as BackendError } from './errors-fDoNdTrJ.cjs';
|
|
4
|
-
export { P as PB, c as createBoundClient } from './pb-
|
|
4
|
+
export { P as PB, c as createBoundClient } from './pb-B3h3NIPE.cjs';
|
|
5
5
|
import 'livekit-client';
|
|
6
6
|
import './storage-BPaeSG8K.cjs';
|
|
7
7
|
import './pooled-flags-4GtDtsiu.js';
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-
|
|
2
|
-
export { e as buildRuntime } from './analytics-facade-
|
|
1
|
+
import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-yfMJ69vw.js';
|
|
2
|
+
export { e as buildRuntime } from './analytics-facade-yfMJ69vw.js';
|
|
3
3
|
import { B as BackendError } from './errors-fDoNdTrJ.js';
|
|
4
|
-
export { P as PB, c as createBoundClient } from './pb-
|
|
4
|
+
export { P as PB, c as createBoundClient } from './pb-QRISxPd1.js';
|
|
5
5
|
import 'livekit-client';
|
|
6
6
|
import './storage-BPaeSG8K.js';
|
|
7
7
|
import './pooled-flags-4GtDtsiu.js';
|
package/dist/internal.js
CHANGED
package/dist/next/client.cjs
CHANGED
|
@@ -40,18 +40,9 @@ var PalbaseError = class extends Error {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
var PALBASE_DEFAULT_HOST = "api.palbase.studio";
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (apiKey.length < 13) return null;
|
|
47
|
-
if (!apiKey.startsWith("pb_")) return null;
|
|
48
|
-
if (apiKey[11] !== "_") return null;
|
|
49
|
-
const ref = apiKey.slice(3, 11);
|
|
50
|
-
if (ref.length !== REF_LEN) return null;
|
|
51
|
-
if (!BASE62_RE.test(ref)) return null;
|
|
52
|
-
const scope = apiKey[12];
|
|
53
|
-
if (scope !== "c") return null;
|
|
54
|
-
return ref;
|
|
43
|
+
var API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
|
|
44
|
+
function parseEnvironmentRef(apiKey) {
|
|
45
|
+
return API_KEY_RE.exec(apiKey)?.[1] ?? null;
|
|
55
46
|
}
|
|
56
47
|
var MAX_RETRIES = 3;
|
|
57
48
|
var INITIAL_BACKOFF_MS = 200;
|
|
@@ -81,8 +72,7 @@ var HttpClient = class _HttpClient {
|
|
|
81
72
|
* with the parent at runtime — later changes on the parent propagate to
|
|
82
73
|
* the scope and vice versa.
|
|
83
74
|
*
|
|
84
|
-
* Typical use:
|
|
85
|
-
* gateway can route them to the correct project's data plane.
|
|
75
|
+
* Typical use: adding an Environment-routing header for an admin call.
|
|
86
76
|
*/
|
|
87
77
|
withHeaders(extra) {
|
|
88
78
|
const mergedHeaders = { ...this.options?.headers ?? {}, ...extra };
|
|
@@ -123,10 +113,10 @@ var HttpClient = class _HttpClient {
|
|
|
123
113
|
if (this.options?.url) {
|
|
124
114
|
return this.options.url;
|
|
125
115
|
}
|
|
126
|
-
if (this.apiKey &&
|
|
116
|
+
if (this.apiKey && parseEnvironmentRef(this.apiKey) === null) {
|
|
127
117
|
throw new PalbaseError(
|
|
128
118
|
"invalid_api_key",
|
|
129
|
-
'Invalid API key format. Expected pb_{
|
|
119
|
+
'Invalid API key format. Expected pb_{environment_ref}_c{20_base62_chars}. For dev/staging pass `url: "https://api.dev.palbase.studio"` via options.',
|
|
130
120
|
0
|
|
131
121
|
);
|
|
132
122
|
}
|
|
@@ -139,10 +129,6 @@ var HttpClient = class _HttpClient {
|
|
|
139
129
|
const effectiveKey = this.apiKey;
|
|
140
130
|
if (effectiveKey) {
|
|
141
131
|
headers["apikey"] = effectiveKey;
|
|
142
|
-
const ref = parseProjectRef(effectiveKey);
|
|
143
|
-
if (ref) {
|
|
144
|
-
headers["X-Project-Ref"] = ref;
|
|
145
|
-
}
|
|
146
132
|
}
|
|
147
133
|
const token = this.tokenManager?.getAccessToken();
|
|
148
134
|
if (token) {
|
|
@@ -953,13 +939,6 @@ var AuthClient = class {
|
|
|
953
939
|
}
|
|
954
940
|
};
|
|
955
941
|
|
|
956
|
-
// src/api-key.ts
|
|
957
|
-
var API_KEY_RE = /^pb_([^_]+)_[cs][A-Za-z0-9]{20}$/;
|
|
958
|
-
function endpointRefFromApiKey(apiKey) {
|
|
959
|
-
const m = API_KEY_RE.exec(apiKey);
|
|
960
|
-
return m ? m[1] ?? "" : "";
|
|
961
|
-
}
|
|
962
|
-
|
|
963
942
|
// src/analytics-facade.ts
|
|
964
943
|
var EVENT_NAME_RE = /^[a-zA-Z$][a-zA-Z0-9_.:$-]{0,63}$/;
|
|
965
944
|
var FLUSH_AT = 20;
|
|
@@ -1017,7 +996,7 @@ var AnalyticsState = class {
|
|
|
1017
996
|
idKey;
|
|
1018
997
|
optOutKey;
|
|
1019
998
|
constructor(rt) {
|
|
1020
|
-
const ref =
|
|
999
|
+
const ref = rt.config.environmentRef;
|
|
1021
1000
|
this.idKey = ref ? `palbe.analytics.id.${ref}` : "palbe.analytics.id";
|
|
1022
1001
|
this.optOutKey = ref ? `palbe.analytics.optout.${ref}` : "palbe.analytics.optout";
|
|
1023
1002
|
rt.auth.onAuthEvent((event) => {
|
|
@@ -1231,6 +1210,13 @@ var PalbeAnalytics = class {
|
|
|
1231
1210
|
}
|
|
1232
1211
|
};
|
|
1233
1212
|
|
|
1213
|
+
// src/api-key.ts
|
|
1214
|
+
var PUBLISHABLE_API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
|
|
1215
|
+
function environmentRefFromPublishableApiKey(apiKey) {
|
|
1216
|
+
const match = PUBLISHABLE_API_KEY_RE.exec(apiKey);
|
|
1217
|
+
return match ? match[1] ?? "" : "";
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1234
1220
|
// src/auth-wire.ts
|
|
1235
1221
|
function asWireAuthResult(raw) {
|
|
1236
1222
|
if (typeof raw !== "object" || raw === null) return null;
|
|
@@ -2371,7 +2357,7 @@ var PalbeFlags = class {
|
|
|
2371
2357
|
constructor(rt) {
|
|
2372
2358
|
this.transport = new FlagsClient(rt.http);
|
|
2373
2359
|
const browser = typeof document !== "undefined";
|
|
2374
|
-
const ref =
|
|
2360
|
+
const ref = rt.config.environmentRef;
|
|
2375
2361
|
const options = {
|
|
2376
2362
|
auth: palbeAuthAdapter(rt.auth),
|
|
2377
2363
|
...ref ? { storageKey: `palbe.flags.${ref}` } : {},
|
|
@@ -8111,7 +8097,7 @@ var AnonTokenProvider = class {
|
|
|
8111
8097
|
}
|
|
8112
8098
|
/**
|
|
8113
8099
|
* Raw fetch, deliberately NOT through HttpClient/palbeRequest: the mint
|
|
8114
|
-
* must carry the
|
|
8100
|
+
* must carry the Environment API key and NEVER a Bearer (iOS keeps
|
|
8115
8101
|
* `/auth/anonymous` on the unauthenticated-path list), and HttpClient's
|
|
8116
8102
|
* pre-flight would try to refresh a stale session before an anon mint —
|
|
8117
8103
|
* exactly the entanglement this provider exists to avoid.
|
|
@@ -8768,10 +8754,25 @@ function defaultSessionStorage(key) {
|
|
|
8768
8754
|
}
|
|
8769
8755
|
|
|
8770
8756
|
// src/version.ts
|
|
8771
|
-
var VERSION = "
|
|
8757
|
+
var VERSION = "3.0.0";
|
|
8772
8758
|
|
|
8773
8759
|
// src/runtime.ts
|
|
8774
8760
|
function buildRuntime(config) {
|
|
8761
|
+
const keyEnvironmentRef = environmentRefFromPublishableApiKey(config.apiKey);
|
|
8762
|
+
if (keyEnvironmentRef === "") {
|
|
8763
|
+
throw new Error("PalbeConfig.apiKey does not contain a valid publishable Environment identity");
|
|
8764
|
+
} else if (config.environmentRef !== keyEnvironmentRef) {
|
|
8765
|
+
throw new Error("PalbeConfig.environmentRef must match the Environment identity in apiKey");
|
|
8766
|
+
}
|
|
8767
|
+
let runtimeURL;
|
|
8768
|
+
try {
|
|
8769
|
+
runtimeURL = new URL(config.url);
|
|
8770
|
+
} catch {
|
|
8771
|
+
throw new Error("PalbeConfig.url must be a valid URL");
|
|
8772
|
+
}
|
|
8773
|
+
if (runtimeURL.hostname.endsWith(".palbase.studio") && runtimeURL.hostname.split(".")[0] !== config.environmentRef) {
|
|
8774
|
+
throw new Error("PalbeConfig.url must match environmentRef for palbase.studio");
|
|
8775
|
+
}
|
|
8775
8776
|
const http = new HttpClient(config.apiKey, {
|
|
8776
8777
|
url: config.url,
|
|
8777
8778
|
headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
|
|
@@ -8780,7 +8781,7 @@ function buildRuntime(config) {
|
|
|
8780
8781
|
const tokenManager = new TokenManager();
|
|
8781
8782
|
http.tokenManager = tokenManager;
|
|
8782
8783
|
const authClient = new AuthClient(http, tokenManager);
|
|
8783
|
-
const ref =
|
|
8784
|
+
const ref = config.environmentRef;
|
|
8784
8785
|
const storage = config.storage ?? defaultSessionStorage(ref ? `palbe.session.${ref}` : void 0);
|
|
8785
8786
|
const persisted = storage.load();
|
|
8786
8787
|
if (persisted) {
|
|
@@ -8938,11 +8939,11 @@ function getRuntime() {
|
|
|
8938
8939
|
|
|
8939
8940
|
// src/next/cookie-codec.ts
|
|
8940
8941
|
var MAX_COOKIE_VALUE = 3500;
|
|
8941
|
-
function sessionCookieName(
|
|
8942
|
-
return `palbe-session-${
|
|
8942
|
+
function sessionCookieName(environmentRef) {
|
|
8943
|
+
return `palbe-session-${environmentRef}`;
|
|
8943
8944
|
}
|
|
8944
|
-
function encodeSessionCookies(
|
|
8945
|
-
const name = sessionCookieName(
|
|
8945
|
+
function encodeSessionCookies(environmentRef, session) {
|
|
8946
|
+
const name = sessionCookieName(environmentRef);
|
|
8946
8947
|
const value = encodeURIComponent(
|
|
8947
8948
|
JSON.stringify({ a: session.accessToken, r: session.refreshToken, e: session.expiresAt })
|
|
8948
8949
|
);
|
|
@@ -8961,8 +8962,8 @@ function encodeSessionCookies(endpointRef, session) {
|
|
|
8961
8962
|
}
|
|
8962
8963
|
return { set: chunks, clear: [`${name}.${chunks.length}`] };
|
|
8963
8964
|
}
|
|
8964
|
-
function decodeSessionCookies(get,
|
|
8965
|
-
const base = sessionCookieName(
|
|
8965
|
+
function decodeSessionCookies(get, environmentRef) {
|
|
8966
|
+
const base = sessionCookieName(environmentRef);
|
|
8966
8967
|
let encoded = get(base);
|
|
8967
8968
|
if (encoded === void 0) {
|
|
8968
8969
|
let joined = "";
|
|
@@ -8996,8 +8997,8 @@ function parseStoredSession(json) {
|
|
|
8996
8997
|
return null;
|
|
8997
8998
|
}
|
|
8998
8999
|
}
|
|
8999
|
-
function clearedSessionCookieNames(
|
|
9000
|
-
const base = sessionCookieName(
|
|
9000
|
+
function clearedSessionCookieNames(environmentRef, present) {
|
|
9001
|
+
const base = sessionCookieName(environmentRef);
|
|
9001
9002
|
const names = [];
|
|
9002
9003
|
if (present(base)) names.push(base);
|
|
9003
9004
|
for (let i = 0; ; i++) {
|
|
@@ -9024,12 +9025,12 @@ function cookieJar() {
|
|
|
9024
9025
|
function deleteCookie(name) {
|
|
9025
9026
|
document.cookie = `${name}=; ${WRITE_ATTRS}; Max-Age=0`;
|
|
9026
9027
|
}
|
|
9027
|
-
function cookieSessionStorage(
|
|
9028
|
+
function cookieSessionStorage(environmentRef) {
|
|
9028
9029
|
return {
|
|
9029
9030
|
load() {
|
|
9030
9031
|
if (typeof document === "undefined") return null;
|
|
9031
9032
|
const jar = cookieJar();
|
|
9032
|
-
const stored = decodeSessionCookies((name) => jar.get(name),
|
|
9033
|
+
const stored = decodeSessionCookies((name) => jar.get(name), environmentRef);
|
|
9033
9034
|
if (!stored) return null;
|
|
9034
9035
|
return stored.accessToken && stored.expiresAt > 0 ? {
|
|
9035
9036
|
refreshToken: stored.refreshToken,
|
|
@@ -9040,10 +9041,10 @@ function cookieSessionStorage(endpointRef) {
|
|
|
9040
9041
|
save(session) {
|
|
9041
9042
|
if (typeof document === "undefined") return;
|
|
9042
9043
|
const jar = cookieJar();
|
|
9043
|
-
for (const name of clearedSessionCookieNames(
|
|
9044
|
+
for (const name of clearedSessionCookieNames(environmentRef, (n) => jar.has(n))) {
|
|
9044
9045
|
deleteCookie(name);
|
|
9045
9046
|
}
|
|
9046
|
-
const { set, clear } = encodeSessionCookies(
|
|
9047
|
+
const { set, clear } = encodeSessionCookies(environmentRef, {
|
|
9047
9048
|
accessToken: session.accessToken ?? "",
|
|
9048
9049
|
refreshToken: session.refreshToken,
|
|
9049
9050
|
expiresAt: session.expiresAt ?? 0
|
|
@@ -9056,7 +9057,7 @@ function cookieSessionStorage(endpointRef) {
|
|
|
9056
9057
|
clear() {
|
|
9057
9058
|
if (typeof document === "undefined") return;
|
|
9058
9059
|
const jar = cookieJar();
|
|
9059
|
-
for (const name of clearedSessionCookieNames(
|
|
9060
|
+
for (const name of clearedSessionCookieNames(environmentRef, (n) => jar.has(n))) {
|
|
9060
9061
|
deleteCookie(name);
|
|
9061
9062
|
}
|
|
9062
9063
|
}
|
|
@@ -9065,7 +9066,10 @@ function cookieSessionStorage(endpointRef) {
|
|
|
9065
9066
|
function setupPalbeNext() {
|
|
9066
9067
|
if (typeof document === "undefined") return;
|
|
9067
9068
|
const config = getRuntime().config;
|
|
9068
|
-
__configure({
|
|
9069
|
+
__configure({
|
|
9070
|
+
...config,
|
|
9071
|
+
storage: cookieSessionStorage(config.environmentRef)
|
|
9072
|
+
});
|
|
9069
9073
|
}
|
|
9070
9074
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9071
9075
|
0 && (module.exports = {
|