@nebulr-group/bridge-auth-core 0.4.4 → 0.4.5
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.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/instance-guard.d.ts +63 -0
- package/dist/instance-guard.d.ts.map +1 -0
- package/dist/instance-guard.js +109 -0
- package/dist/instance-guard.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { loadedInstanceCount, __resetInstanceRegistryForTests, } from './instance-guard.js';
|
|
1
2
|
export { BridgeAuth } from './bridge-auth.js';
|
|
2
3
|
export type { AppConfig, AuthConfigResponse, AuthResult, AuthState, BridgeAuthConfig, BridgeAuthEventName, BridgeAuthEvents, CheckoutSession, CurrentUser, FederationConnection, FlagRequirement, IDToken, MagicLinkResult, MfaResult, NavigationDecision, PasskeyAuthOptions, PasskeyRegistrationOptions, PasskeyVerificationResult, PaymentClaims, Plan, PriceOfferSdk, Profile, ResolvedConfig, RouteGuard, RouteGuardConfig, RouteRule, SessionStalePayload, SignupResult, SsoOptions, SsoResult, SubscriptionStatus, TenantUser, TokenSet, TokenStorage, Workspace, } from './types.js';
|
|
3
4
|
export { TeamService } from './team-service.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,YAAY,EACV,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,gBAA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AC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EACV,yBAAyB,EACzB,eAAe,EACf,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,GACb,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// Duplicate-instance detection (TBP-598).
|
|
2
|
+
//
|
|
3
|
+
// Runs at import time. This package keeps state at module scope (the billing
|
|
4
|
+
// singleton, the realtime client, the flag cache), so a second copy silently
|
|
5
|
+
// splits it — most sharply the billing lock, which is registered on one copy
|
|
6
|
+
// and emitted on the other and therefore never fires. Warns; never throws.
|
|
7
|
+
import { registerInstance } from './instance-guard.js';
|
|
8
|
+
registerInstance();
|
|
9
|
+
export { loadedInstanceCount, __resetInstanceRegistryForTests, } from './instance-guard.js';
|
|
1
10
|
// Main facade
|
|
2
11
|
export { BridgeAuth } from './bridge-auth.js';
|
|
3
12
|
// Team management
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAyC9C,kBAAkB;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAWhD,uBAAuB;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAQzD,SAAS;AACT,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE7E,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GACjB,MAAM,kBAAkB,CAAC;AAoD1B,+EAA+E;AAC/E,2EAA2E;AAC3E,4DAA4D;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAOpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,iDAAiD;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duplicate-instance detection for bridge-auth-core.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
*
|
|
6
|
+
* This package is NOT safe to load twice in one process or one bundle. It keeps
|
|
7
|
+
* real state at module scope, and a second copy gets its own private copy of all
|
|
8
|
+
* of it:
|
|
9
|
+
*
|
|
10
|
+
* billing/use-bridge.ts `_singleton`, `_quotaStore`, `_entitlementsStore`,
|
|
11
|
+
* `_attachedRt`, `_devHandlers`
|
|
12
|
+
* billing/lock-signal.ts `handler`
|
|
13
|
+
* flags/propagation.ts `_serverInstanceId`
|
|
14
|
+
*
|
|
15
|
+
* The billing lock is the sharpest edge. `lock-signal.ts` exists specifically to
|
|
16
|
+
* decouple the HTTP layer from the billing singleton: `http.ts` calls
|
|
17
|
+
* `emitBillingLock()`, and `useBridge()` registers the receiver via
|
|
18
|
+
* `setBillingLockHandler()`. Split across two copies, the app registers its
|
|
19
|
+
* handler on copy A while the request that trips the lock emits on copy B — so
|
|
20
|
+
* `handler` is null and **the lock never fires**. A workspace gets locked for
|
|
21
|
+
* non-payment and the UI carries on as if nothing happened. Nothing errors.
|
|
22
|
+
*
|
|
23
|
+
* `_attachedRt` is the other one: two copies means two WebSocket connections and
|
|
24
|
+
* two divergent flag caches, which is the shape of TBP-517.
|
|
25
|
+
*
|
|
26
|
+
* HOW DUPLICATES HAPPEN
|
|
27
|
+
*
|
|
28
|
+
* Every framework plugin used to declare this package as an exact-pinned regular
|
|
29
|
+
* dependency. An app on `bridge-react@0.4.0` (pinning auth-core `0.4.0`) that
|
|
30
|
+
* also pinned auth-core `0.4.4` itself got both, nested. The package manager is
|
|
31
|
+
* behaving correctly; the dependency declaration was wrong. The plugins now
|
|
32
|
+
* declare it as a `peerDependency` with a range, which makes the resolver pick
|
|
33
|
+
* ONE — and turns a genuinely incompatible pin into a loud peer conflict instead
|
|
34
|
+
* of a silent second copy.
|
|
35
|
+
*
|
|
36
|
+
* A peer dependency cannot catch everything, though: a bundler fed two different
|
|
37
|
+
* physical paths (mixed ESM/CJS resolution, a monorepo symlink, an aliased copy)
|
|
38
|
+
* still produces two module instances from one installed version. That is what
|
|
39
|
+
* this guard is for. It is the last line, not the first.
|
|
40
|
+
*
|
|
41
|
+
* The check is deliberately a WARNING, never a throw. Refusing to start would
|
|
42
|
+
* turn a degraded-but-working app into a dead one, and this code runs in
|
|
43
|
+
* production browsers.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Records this copy and warns — once per process — if it is not the first.
|
|
47
|
+
*
|
|
48
|
+
* Called at import time from the package entry point.
|
|
49
|
+
*
|
|
50
|
+
* Deliberately does NOT report which versions loaded. Getting the version into
|
|
51
|
+
* the bundle means either importing package.json (which changes the emitted
|
|
52
|
+
* dist layout) or a hand-maintained constant that silently drifts on release.
|
|
53
|
+
* `npm ls` already answers "which versions" precisely, so the message points
|
|
54
|
+
* there instead of carrying a copy that can go stale.
|
|
55
|
+
*
|
|
56
|
+
* @returns the number of copies now registered (1 = healthy)
|
|
57
|
+
*/
|
|
58
|
+
export declare function registerInstance(): number;
|
|
59
|
+
/** How many copies have registered. Exposed for diagnostics and tests. */
|
|
60
|
+
export declare function loadedInstanceCount(): number;
|
|
61
|
+
/** Test-only: clear the registry so cases do not leak into each other. */
|
|
62
|
+
export declare function __resetInstanceRegistryForTests(): void;
|
|
63
|
+
//# sourceMappingURL=instance-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-guard.d.ts","sourceRoot":"","sources":["../src/instance-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAqBH;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CA4BzC;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,IAAI,MAAM,CAM5C;AAED,0EAA0E;AAC1E,wBAAgB,+BAA+B,IAAI,IAAI,CAGtD"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duplicate-instance detection for bridge-auth-core.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
*
|
|
6
|
+
* This package is NOT safe to load twice in one process or one bundle. It keeps
|
|
7
|
+
* real state at module scope, and a second copy gets its own private copy of all
|
|
8
|
+
* of it:
|
|
9
|
+
*
|
|
10
|
+
* billing/use-bridge.ts `_singleton`, `_quotaStore`, `_entitlementsStore`,
|
|
11
|
+
* `_attachedRt`, `_devHandlers`
|
|
12
|
+
* billing/lock-signal.ts `handler`
|
|
13
|
+
* flags/propagation.ts `_serverInstanceId`
|
|
14
|
+
*
|
|
15
|
+
* The billing lock is the sharpest edge. `lock-signal.ts` exists specifically to
|
|
16
|
+
* decouple the HTTP layer from the billing singleton: `http.ts` calls
|
|
17
|
+
* `emitBillingLock()`, and `useBridge()` registers the receiver via
|
|
18
|
+
* `setBillingLockHandler()`. Split across two copies, the app registers its
|
|
19
|
+
* handler on copy A while the request that trips the lock emits on copy B — so
|
|
20
|
+
* `handler` is null and **the lock never fires**. A workspace gets locked for
|
|
21
|
+
* non-payment and the UI carries on as if nothing happened. Nothing errors.
|
|
22
|
+
*
|
|
23
|
+
* `_attachedRt` is the other one: two copies means two WebSocket connections and
|
|
24
|
+
* two divergent flag caches, which is the shape of TBP-517.
|
|
25
|
+
*
|
|
26
|
+
* HOW DUPLICATES HAPPEN
|
|
27
|
+
*
|
|
28
|
+
* Every framework plugin used to declare this package as an exact-pinned regular
|
|
29
|
+
* dependency. An app on `bridge-react@0.4.0` (pinning auth-core `0.4.0`) that
|
|
30
|
+
* also pinned auth-core `0.4.4` itself got both, nested. The package manager is
|
|
31
|
+
* behaving correctly; the dependency declaration was wrong. The plugins now
|
|
32
|
+
* declare it as a `peerDependency` with a range, which makes the resolver pick
|
|
33
|
+
* ONE — and turns a genuinely incompatible pin into a loud peer conflict instead
|
|
34
|
+
* of a silent second copy.
|
|
35
|
+
*
|
|
36
|
+
* A peer dependency cannot catch everything, though: a bundler fed two different
|
|
37
|
+
* physical paths (mixed ESM/CJS resolution, a monorepo symlink, an aliased copy)
|
|
38
|
+
* still produces two module instances from one installed version. That is what
|
|
39
|
+
* this guard is for. It is the last line, not the first.
|
|
40
|
+
*
|
|
41
|
+
* The check is deliberately a WARNING, never a throw. Refusing to start would
|
|
42
|
+
* turn a degraded-but-working app into a dead one, and this code runs in
|
|
43
|
+
* production browsers.
|
|
44
|
+
*/
|
|
45
|
+
/** Registry key. A string-keyed Symbol so every copy resolves the same symbol. */
|
|
46
|
+
const REGISTRY_KEY = Symbol.for('@nebulr-group/bridge-auth-core.instances');
|
|
47
|
+
/** SSR-safe global. `globalThis` is defined in every supported runtime. */
|
|
48
|
+
function registry() {
|
|
49
|
+
const g = globalThis;
|
|
50
|
+
let rec = g[REGISTRY_KEY];
|
|
51
|
+
if (!rec) {
|
|
52
|
+
rec = { count: 0, warned: false };
|
|
53
|
+
g[REGISTRY_KEY] = rec;
|
|
54
|
+
}
|
|
55
|
+
return rec;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Records this copy and warns — once per process — if it is not the first.
|
|
59
|
+
*
|
|
60
|
+
* Called at import time from the package entry point.
|
|
61
|
+
*
|
|
62
|
+
* Deliberately does NOT report which versions loaded. Getting the version into
|
|
63
|
+
* the bundle means either importing package.json (which changes the emitted
|
|
64
|
+
* dist layout) or a hand-maintained constant that silently drifts on release.
|
|
65
|
+
* `npm ls` already answers "which versions" precisely, so the message points
|
|
66
|
+
* there instead of carrying a copy that can go stale.
|
|
67
|
+
*
|
|
68
|
+
* @returns the number of copies now registered (1 = healthy)
|
|
69
|
+
*/
|
|
70
|
+
export function registerInstance() {
|
|
71
|
+
let rec;
|
|
72
|
+
try {
|
|
73
|
+
rec = registry();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// A runtime with a frozen/exotic globalThis. Detection is a nicety; never
|
|
77
|
+
// let it be the reason the SDK fails to load.
|
|
78
|
+
return 1;
|
|
79
|
+
}
|
|
80
|
+
rec.count += 1;
|
|
81
|
+
if (rec.count > 1 && !rec.warned) {
|
|
82
|
+
rec.warned = true;
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
84
|
+
globalThis.console?.warn?.(`[bridge-auth-core] Loaded ${rec.count} copies of this package.\n` +
|
|
85
|
+
'This package keeps state at module scope, so a second copy silently breaks:\n' +
|
|
86
|
+
' - the billing lock (registered on one copy, emitted on the other — it never fires)\n' +
|
|
87
|
+
' - realtime (two WebSocket connections)\n' +
|
|
88
|
+
' - the feature-flag cache (two divergent copies)\n' +
|
|
89
|
+
'Install ONE version: make sure every @nebulr-group/bridge-* plugin resolves the\n' +
|
|
90
|
+
'same @nebulr-group/bridge-auth-core. `npm ls @nebulr-group/bridge-auth-core` shows\n' +
|
|
91
|
+
'the tree; a deduped install has exactly one entry.');
|
|
92
|
+
}
|
|
93
|
+
return rec.count;
|
|
94
|
+
}
|
|
95
|
+
/** How many copies have registered. Exposed for diagnostics and tests. */
|
|
96
|
+
export function loadedInstanceCount() {
|
|
97
|
+
try {
|
|
98
|
+
return registry().count;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Test-only: clear the registry so cases do not leak into each other. */
|
|
105
|
+
export function __resetInstanceRegistryForTests() {
|
|
106
|
+
const g = globalThis;
|
|
107
|
+
g[REGISTRY_KEY] = { count: 0, warned: false };
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=instance-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-guard.js","sourceRoot":"","sources":["../src/instance-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,kFAAkF;AAClF,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;AAO5E,2EAA2E;AAC3E,SAAS,QAAQ;IACf,MAAM,CAAC,GAAG,UAAmE,CAAC;IAC9E,IAAI,GAAG,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC;IAC1B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAClC,CAAC,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,GAAmB,CAAC;IACxB,IAAI,CAAC;QACH,GAAG,GAAG,QAAQ,EAAE,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,8CAA8C;QAC9C,OAAO,CAAC,CAAC;IACX,CAAC;IAED,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC;IAEf,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACjC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;QAClB,sCAAsC;QACrC,UAAoC,CAAC,OAAO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