@palbase/web 1.10.0 → 2.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 +3 -2
- package/dist/{analytics-facade-CHh5EGC2.d.ts → analytics-facade-DMtGDGfd.d.ts} +2 -18
- package/dist/{analytics-facade-B7vujhPJ.d.cts → analytics-facade-ovP0pF2P.d.cts} +2 -18
- package/dist/{chunk-4ZJHHXD3.js → chunk-V6VTX65P.js} +20 -31
- package/dist/chunk-V6VTX65P.js.map +1 -0
- package/dist/gen/cli.cjs +20 -12
- package/dist/gen/cli.cjs.map +1 -1
- package/dist/gen/cli.js +20 -12
- package/dist/gen/cli.js.map +1 -1
- package/dist/index.cjs +18 -9
- 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 +1 -1
- package/dist/internal.cjs +19 -30
- 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 +1 -1
- package/dist/next/client.cjs +16 -29
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/index.cjs +19 -30
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +2 -2
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +1 -1
- package/dist/{pb-ChNq987M.d.ts → pb-CvpcQero.d.ts} +1 -1
- package/dist/{pb-6965XULp.d.cts → pb-DDM_mCQB.d.cts} +1 -1
- package/dist/react/index.cjs +12 -8
- 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 +1 -1
- package/package.json +3 -3
- package/dist/chunk-4ZJHHXD3.js.map +0 -1
package/README.md
CHANGED
|
@@ -34,8 +34,9 @@ wires `import './palbe.gen';` into your app entry, and adds a `predev`/`prebuild
|
|
|
34
34
|
hook that keeps the types in sync. **Commit `palbe.gen.ts`** — it's the typed
|
|
35
35
|
client your app imports, not a build artifact.
|
|
36
36
|
|
|
37
|
-
The generated file calls `__configure(...)` with your project's URL
|
|
38
|
-
key at module load, so importing it once at startup is all the setup
|
|
37
|
+
The generated file calls `__configure(...)` with your project's URL, app ID, and
|
|
38
|
+
anon API key at module load, so importing it once at startup is all the setup
|
|
39
|
+
there is.
|
|
39
40
|
If you forget to import it, every `pb` call throws a guided `BackendError`
|
|
40
41
|
(`kind: 'notConfigured'`).
|
|
41
42
|
|
|
@@ -620,18 +620,10 @@ interface PalbeOAuthConfig {
|
|
|
620
620
|
interface PalbeConfig {
|
|
621
621
|
url: string;
|
|
622
622
|
apiKey: string;
|
|
623
|
+
/** Registered app identity persisted by `palbase web link`. */
|
|
624
|
+
appId: string;
|
|
623
625
|
/** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
|
|
624
626
|
branch?: string;
|
|
625
|
-
/**
|
|
626
|
-
* F2 app-registration: the registered app `identifier` from
|
|
627
|
-
* `palbase-config.json` — for web this is the declared ORIGIN (e.g.
|
|
628
|
-
* `https://app.example.com`). When non-empty, `configure` REFUSES to build the
|
|
629
|
-
* runtime if `window.location.origin` does not match (SDK-REFUSES), and the
|
|
630
|
-
* value rides on `X-Palbase-Bundle` on EVERY request so the Kong gate can match
|
|
631
|
-
* it (the IDENTICAL header + value the iOS SDK sends). Empty/absent → legacy /
|
|
632
|
-
* tooling: no guard, no header.
|
|
633
|
-
*/
|
|
634
|
-
identifier?: string;
|
|
635
627
|
oauth?: PalbeOAuthConfig;
|
|
636
628
|
/** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
|
|
637
629
|
storage?: SessionStorageAdapter;
|
|
@@ -1690,14 +1682,6 @@ declare class PalbeRealtime {
|
|
|
1690
1682
|
|
|
1691
1683
|
interface PalbeRuntime {
|
|
1692
1684
|
config: PalbeConfig;
|
|
1693
|
-
/**
|
|
1694
|
-
* F2 app-registration: the registered app `identifier` (web ORIGIN) stashed at
|
|
1695
|
-
* configure. Rides on `X-Palbase-Bundle` on EVERY request (request.ts) so the
|
|
1696
|
-
* Kong gate can match it. Empty string when the binding is unconfigured/tooling
|
|
1697
|
-
* (no header is sent). Origin-match is enforced in `buildRuntime` BEFORE this
|
|
1698
|
-
* runtime is returned — a mismatch throws there and no runtime is built.
|
|
1699
|
-
*/
|
|
1700
|
-
appIdentifier: string;
|
|
1701
1685
|
http: HttpClient$1;
|
|
1702
1686
|
tokenManager: TokenManager$1;
|
|
1703
1687
|
authClient: AuthClient;
|
|
@@ -620,18 +620,10 @@ interface PalbeOAuthConfig {
|
|
|
620
620
|
interface PalbeConfig {
|
|
621
621
|
url: string;
|
|
622
622
|
apiKey: string;
|
|
623
|
+
/** Registered app identity persisted by `palbase web link`. */
|
|
624
|
+
appId: string;
|
|
623
625
|
/** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
|
|
624
626
|
branch?: string;
|
|
625
|
-
/**
|
|
626
|
-
* F2 app-registration: the registered app `identifier` from
|
|
627
|
-
* `palbase-config.json` — for web this is the declared ORIGIN (e.g.
|
|
628
|
-
* `https://app.example.com`). When non-empty, `configure` REFUSES to build the
|
|
629
|
-
* runtime if `window.location.origin` does not match (SDK-REFUSES), and the
|
|
630
|
-
* value rides on `X-Palbase-Bundle` on EVERY request so the Kong gate can match
|
|
631
|
-
* it (the IDENTICAL header + value the iOS SDK sends). Empty/absent → legacy /
|
|
632
|
-
* tooling: no guard, no header.
|
|
633
|
-
*/
|
|
634
|
-
identifier?: string;
|
|
635
627
|
oauth?: PalbeOAuthConfig;
|
|
636
628
|
/** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
|
|
637
629
|
storage?: SessionStorageAdapter;
|
|
@@ -1690,14 +1682,6 @@ declare class PalbeRealtime {
|
|
|
1690
1682
|
|
|
1691
1683
|
interface PalbeRuntime {
|
|
1692
1684
|
config: PalbeConfig;
|
|
1693
|
-
/**
|
|
1694
|
-
* F2 app-registration: the registered app `identifier` (web ORIGIN) stashed at
|
|
1695
|
-
* configure. Rides on `X-Palbase-Bundle` on EVERY request (request.ts) so the
|
|
1696
|
-
* Kong gate can match it. Empty string when the binding is unconfigured/tooling
|
|
1697
|
-
* (no header is sent). Origin-match is enforced in `buildRuntime` BEFORE this
|
|
1698
|
-
* runtime is returned — a mismatch throws there and no runtime is built.
|
|
1699
|
-
*/
|
|
1700
|
-
appIdentifier: string;
|
|
1701
1685
|
http: HttpClient$1;
|
|
1702
1686
|
tokenManager: TokenManager$1;
|
|
1703
1687
|
authClient: AuthClient;
|
|
@@ -420,12 +420,6 @@ async function palbeRequest(rt, method, path, spec = {}) {
|
|
|
420
420
|
if (MUTATING.has(method) && !callerHasKey) {
|
|
421
421
|
headers["Idempotency-Key"] = crypto.randomUUID();
|
|
422
422
|
}
|
|
423
|
-
if (rt.appIdentifier !== "") {
|
|
424
|
-
const callerHasBundle = Object.keys(headers).some(
|
|
425
|
-
(k) => k.toLowerCase() === "x-palbase-bundle"
|
|
426
|
-
);
|
|
427
|
-
if (!callerHasBundle) headers["X-Palbase-Bundle"] = rt.appIdentifier;
|
|
428
|
-
}
|
|
429
423
|
const attempt = async () => {
|
|
430
424
|
try {
|
|
431
425
|
return await rt.http.request(method, path, {
|
|
@@ -1409,23 +1403,6 @@ var PalbeAnalytics = class {
|
|
|
1409
1403
|
}
|
|
1410
1404
|
};
|
|
1411
1405
|
|
|
1412
|
-
// src/app-config.ts
|
|
1413
|
-
function loadAppConfig(raw) {
|
|
1414
|
-
if (typeof raw !== "object" || raw === null) {
|
|
1415
|
-
throw new Error("app_config_invalid: expected a JSON object");
|
|
1416
|
-
}
|
|
1417
|
-
const r = raw;
|
|
1418
|
-
const str = (k) => typeof r[k] === "string" ? r[k] : "";
|
|
1419
|
-
return { appId: str("app_id"), identifier: str("identifier"), envPreset: str("env_preset") };
|
|
1420
|
-
}
|
|
1421
|
-
function assertOriginMatches(cfg, runtimeOrigin) {
|
|
1422
|
-
if (cfg.identifier === "") return;
|
|
1423
|
-
if (runtimeOrigin === "") return;
|
|
1424
|
-
if (runtimeOrigin !== cfg.identifier) {
|
|
1425
|
-
throw new Error(`app_config_mismatch: expected origin ${cfg.identifier}, got ${runtimeOrigin}`);
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
1406
|
// src/auth-wire.ts
|
|
1430
1407
|
function asWireAuthResult(raw) {
|
|
1431
1408
|
if (typeof raw !== "object" || raw === null) return null;
|
|
@@ -8239,6 +8216,14 @@ function observeWebVitals(record) {
|
|
|
8239
8216
|
};
|
|
8240
8217
|
}
|
|
8241
8218
|
|
|
8219
|
+
// src/runtime-metadata.ts
|
|
8220
|
+
var APP_METADATA_HEADER = "X-Palbase-Bundle";
|
|
8221
|
+
function applyBrowserOriginHeader(headers) {
|
|
8222
|
+
if (Object.keys(headers).some((key) => key.toLowerCase() === "x-palbase-bundle")) return;
|
|
8223
|
+
const origin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
|
|
8224
|
+
if (origin !== "") headers[APP_METADATA_HEADER] = origin;
|
|
8225
|
+
}
|
|
8226
|
+
|
|
8242
8227
|
// src/realtime/anon-token.ts
|
|
8243
8228
|
var REFRESH_SKEW_MS = 6e4;
|
|
8244
8229
|
var AnonTokenProvider = class {
|
|
@@ -8281,11 +8266,16 @@ var AnonTokenProvider = class {
|
|
|
8281
8266
|
*/
|
|
8282
8267
|
async mint() {
|
|
8283
8268
|
const base = this.rt.config.url.replace(/\/+$/, "");
|
|
8269
|
+
const headers = {
|
|
8270
|
+
apikey: this.rt.config.apiKey,
|
|
8271
|
+
...this.rt.config.headers
|
|
8272
|
+
};
|
|
8273
|
+
applyBrowserOriginHeader(headers);
|
|
8284
8274
|
let response;
|
|
8285
8275
|
try {
|
|
8286
8276
|
response = await fetch(`${base}/auth/anonymous`, {
|
|
8287
8277
|
method: "POST",
|
|
8288
|
-
headers
|
|
8278
|
+
headers
|
|
8289
8279
|
});
|
|
8290
8280
|
} catch (e) {
|
|
8291
8281
|
throw new BackendError("network", {
|
|
@@ -8926,17 +8916,15 @@ function defaultSessionStorage(key) {
|
|
|
8926
8916
|
}
|
|
8927
8917
|
|
|
8928
8918
|
// src/version.ts
|
|
8929
|
-
var VERSION = "
|
|
8919
|
+
var VERSION = "2.0.0";
|
|
8930
8920
|
|
|
8931
8921
|
// src/runtime.ts
|
|
8932
8922
|
function buildRuntime(config) {
|
|
8933
|
-
const appIdentifier = config.identifier ?? "";
|
|
8934
|
-
const runtimeOrigin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
|
|
8935
|
-
assertOriginMatches(loadAppConfig({ identifier: appIdentifier }), runtimeOrigin);
|
|
8936
8923
|
const http = new HttpClient(config.apiKey, {
|
|
8937
8924
|
url: config.url,
|
|
8938
8925
|
headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
|
|
8939
8926
|
});
|
|
8927
|
+
http.addInterceptor(({ headers }) => applyBrowserOriginHeader(headers));
|
|
8940
8928
|
const tokenManager = new TokenManager();
|
|
8941
8929
|
http.tokenManager = tokenManager;
|
|
8942
8930
|
const authClient = new AuthClient(http, tokenManager);
|
|
@@ -8985,7 +8973,6 @@ function buildRuntime(config) {
|
|
|
8985
8973
|
let perf;
|
|
8986
8974
|
const rt = {
|
|
8987
8975
|
config,
|
|
8988
|
-
appIdentifier,
|
|
8989
8976
|
http,
|
|
8990
8977
|
tokenManager,
|
|
8991
8978
|
authClient,
|
|
@@ -9144,7 +9131,9 @@ async function buildHeaders(rt, extra) {
|
|
|
9144
9131
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
9145
9132
|
const callerHasKey = Object.keys(extra ?? {}).some((k) => k.toLowerCase() === "idempotency-key");
|
|
9146
9133
|
if (!callerHasKey) headers["Idempotency-Key"] = crypto.randomUUID();
|
|
9147
|
-
|
|
9134
|
+
const merged = { ...headers, ...extra };
|
|
9135
|
+
applyBrowserOriginHeader(merged);
|
|
9136
|
+
return merged;
|
|
9148
9137
|
}
|
|
9149
9138
|
function buildForm(options) {
|
|
9150
9139
|
const form = new FormData();
|
|
@@ -9340,4 +9329,4 @@ export {
|
|
|
9340
9329
|
pb,
|
|
9341
9330
|
createBoundClient
|
|
9342
9331
|
};
|
|
9343
|
-
//# sourceMappingURL=chunk-
|
|
9332
|
+
//# sourceMappingURL=chunk-V6VTX65P.js.map
|