@deck-shelves/host 1.3.0 → 1.3.2

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 CHANGED
@@ -11,7 +11,7 @@
11
11
  [![npm version](https://img.shields.io/npm/v/@deck-shelves/host?logo=npm&color=cb3837)](https://www.npmjs.com/package/@deck-shelves/host)
12
12
  [![npm downloads](https://img.shields.io/npm/dt/@deck-shelves/host?label=downloads&logo=npm&color=blue)](https://www.npmjs.com/package/@deck-shelves/host)
13
13
  [![npm monthly](https://img.shields.io/npm/dm/@deck-shelves/host?label=monthly&logo=npm&color=blue)](https://www.npmjs.com/package/@deck-shelves/host)
14
- [![Tests](https://img.shields.io/badge/tests-7%20passed-brightgreen?logo=vitest&logoColor=white)](src/contract/index.test.ts)
14
+ [![Tests](https://img.shields.io/badge/tests-8%20passed-brightgreen?logo=vitest&logoColor=white)](src/contract/index.test.ts)
15
15
  [![Types](https://img.shields.io/npm/types/@deck-shelves/host?logo=typescript&logoColor=white)](src/contract/index.ts)
16
16
  [![Bundle size](https://img.shields.io/bundlephobia/minzip/@deck-shelves/host?label=minzip&color=blue)](https://bundlephobia.com/package/@deck-shelves/host)
17
17
  [![License](https://img.shields.io/npm/l/@deck-shelves/host?color=blue)](LICENSE)
package/dist/index.cjs CHANGED
@@ -2,5 +2,45 @@
2
2
 
3
3
  // src/contract/index.ts
4
4
  var HOST_API_VERSION = "1.2.0";
5
+ var INJECTED_HOST_GLOBAL = "__SHELVES_HOST__";
6
+ var FORCE_OWNER_GLOBAL = "__SHELVES_FORCE_OWNER__";
7
+ var OWNER_GLOBAL = "__DECK_SHELVES_OWNER__";
8
+ var OWNER_METADATA_GLOBAL = "__DECK_SHELVES_OWNER_META__";
9
+ function ownershipScope() {
10
+ const g = globalThis;
11
+ return g.window ?? g;
12
+ }
13
+ function readOwnerString(name) {
14
+ try {
15
+ const v = ownershipScope()[name];
16
+ return typeof v === "string" && v.length > 0 ? v : null;
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+ function getInjectedHost() {
22
+ try {
23
+ return ownershipScope()[INJECTED_HOST_GLOBAL] ?? null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ function readForcedOwner() {
29
+ return readOwnerString(FORCE_OWNER_GLOBAL);
30
+ }
31
+ function readOwner() {
32
+ return readOwnerString(OWNER_GLOBAL);
33
+ }
34
+ function isForcedOwner() {
35
+ return readForcedOwner() != null;
36
+ }
5
37
 
38
+ exports.FORCE_OWNER_GLOBAL = FORCE_OWNER_GLOBAL;
6
39
  exports.HOST_API_VERSION = HOST_API_VERSION;
40
+ exports.INJECTED_HOST_GLOBAL = INJECTED_HOST_GLOBAL;
41
+ exports.OWNER_GLOBAL = OWNER_GLOBAL;
42
+ exports.OWNER_METADATA_GLOBAL = OWNER_METADATA_GLOBAL;
43
+ exports.getInjectedHost = getInjectedHost;
44
+ exports.isForcedOwner = isForcedOwner;
45
+ exports.readForcedOwner = readForcedOwner;
46
+ exports.readOwner = readOwner;
package/dist/index.d.cts CHANGED
@@ -243,6 +243,31 @@ interface HostApi {
243
243
  * apply an update themselves (see `HostUpdates`). */
244
244
  readonly updates?: HostUpdates;
245
245
  }
246
+ /** An owner label is an opaque, host-chosen string; the contract never enumerates
247
+ concrete names (that would bake a host/loader identity into the boundary). */
248
+ type HostOwnerKind = string;
249
+ /** Renderer global NAMES (augmented on `Window` below). */
250
+ declare const INJECTED_HOST_GLOBAL: "__SHELVES_HOST__";
251
+ declare const FORCE_OWNER_GLOBAL: "__SHELVES_FORCE_OWNER__";
252
+ declare const OWNER_GLOBAL: "__DECK_SHELVES_OWNER__";
253
+ declare const OWNER_METADATA_GLOBAL: "__DECK_SHELVES_OWNER_META__";
254
+ /** Version identity published by the bundle that currently owns the renderer. */
255
+ interface HostOwnerMetadata {
256
+ host: HostOwnerKind;
257
+ dsVersion: string;
258
+ }
259
+ /** The injected host runtime, or null when no neutral host is present. */
260
+ declare function getInjectedHost(): ShelvesHostGlobal | null;
261
+ /** The forced-owner label a host stamped, or null when none. */
262
+ declare function readForcedOwner(): string | null;
263
+ /** The renderer's single-owner claim, or null when still unclaimed. */
264
+ declare function readOwner(): string | null;
265
+ /** True when a host stamped a forced-owner claim. Only the injected neutral host
266
+ does this, so `isForcedOwner() && getInjectedHost()` means "the injected host
267
+ was forced to own" (cooperative ownership) without naming any host: the loader
268
+ keeps the renderer + its other plugins, and the bundle binds to the injected
269
+ host — waiting via {@link getInjectedHost} if the loader booted it first. */
270
+ declare function isForcedOwner(): boolean;
246
271
  /** Shape of the runtime global the host installs in the renderer. */
247
272
  type ShelvesHostGlobal = HostApi;
248
273
  declare global {
@@ -278,7 +303,25 @@ declare global {
278
303
  * both vanishing. Unset means no host has claimed the tab.
279
304
  */
280
305
  __SHELVES_QAM_OWNER__?: string;
306
+ /**
307
+ * Forced-owner handshake. A host stamps its own (opaque) owner label here to
308
+ * claim the renderer even alongside a loader (cooperative ownership): the
309
+ * loader keeps owning the renderer and its other plugins, but the bundle binds
310
+ * to the injected host (`__SHELVES_HOST__`) — waiting for it to appear if the
311
+ * loader booted the bundle first — instead of the loader that launched it.
312
+ * Only the injected host stamps this, so presence (not the label's value) is
313
+ * what the bundle keys on.
314
+ */
315
+ __SHELVES_FORCE_OWNER__?: HostOwnerKind;
316
+ /**
317
+ * The renderer's single-owner claim. The first host/bundle to claim writes
318
+ * its kind; a second instance reads it and stands down (no home patch, no
319
+ * settings writes) so there is exactly one injector and one writer.
320
+ */
321
+ __DECK_SHELVES_OWNER__?: HostOwnerKind;
322
+ /** Version identity of the bundle that currently owns the renderer. */
323
+ __DECK_SHELVES_OWNER_META__?: HostOwnerMetadata;
281
324
  }
282
325
  }
283
326
 
284
- export { type Disposable, HOST_API_VERSION, type HostApi, type HostLifecycle, type HostMainMenu, type HostNotifications, type HostQam, type HostRoutes, type HostRpc, type HostUi, type HostUpdates, type MainMenuEntry, type PlatformApi, type PlatformAppMeta, type PlatformCollection, type PlatformTab, type PluginDescriptor, type QamPanel, type ShelfSource, type ShelvesHostGlobal, type ToastOptions };
327
+ export { type Disposable, FORCE_OWNER_GLOBAL, HOST_API_VERSION, type HostApi, type HostLifecycle, type HostMainMenu, type HostNotifications, type HostOwnerKind, type HostOwnerMetadata, type HostQam, type HostRoutes, type HostRpc, type HostUi, type HostUpdates, INJECTED_HOST_GLOBAL, type MainMenuEntry, OWNER_GLOBAL, OWNER_METADATA_GLOBAL, type PlatformApi, type PlatformAppMeta, type PlatformCollection, type PlatformTab, type PluginDescriptor, type QamPanel, type ShelfSource, type ShelvesHostGlobal, type ToastOptions, getInjectedHost, isForcedOwner, readForcedOwner, readOwner };
package/dist/index.d.ts CHANGED
@@ -243,6 +243,31 @@ interface HostApi {
243
243
  * apply an update themselves (see `HostUpdates`). */
244
244
  readonly updates?: HostUpdates;
245
245
  }
246
+ /** An owner label is an opaque, host-chosen string; the contract never enumerates
247
+ concrete names (that would bake a host/loader identity into the boundary). */
248
+ type HostOwnerKind = string;
249
+ /** Renderer global NAMES (augmented on `Window` below). */
250
+ declare const INJECTED_HOST_GLOBAL: "__SHELVES_HOST__";
251
+ declare const FORCE_OWNER_GLOBAL: "__SHELVES_FORCE_OWNER__";
252
+ declare const OWNER_GLOBAL: "__DECK_SHELVES_OWNER__";
253
+ declare const OWNER_METADATA_GLOBAL: "__DECK_SHELVES_OWNER_META__";
254
+ /** Version identity published by the bundle that currently owns the renderer. */
255
+ interface HostOwnerMetadata {
256
+ host: HostOwnerKind;
257
+ dsVersion: string;
258
+ }
259
+ /** The injected host runtime, or null when no neutral host is present. */
260
+ declare function getInjectedHost(): ShelvesHostGlobal | null;
261
+ /** The forced-owner label a host stamped, or null when none. */
262
+ declare function readForcedOwner(): string | null;
263
+ /** The renderer's single-owner claim, or null when still unclaimed. */
264
+ declare function readOwner(): string | null;
265
+ /** True when a host stamped a forced-owner claim. Only the injected neutral host
266
+ does this, so `isForcedOwner() && getInjectedHost()` means "the injected host
267
+ was forced to own" (cooperative ownership) without naming any host: the loader
268
+ keeps the renderer + its other plugins, and the bundle binds to the injected
269
+ host — waiting via {@link getInjectedHost} if the loader booted it first. */
270
+ declare function isForcedOwner(): boolean;
246
271
  /** Shape of the runtime global the host installs in the renderer. */
247
272
  type ShelvesHostGlobal = HostApi;
248
273
  declare global {
@@ -278,7 +303,25 @@ declare global {
278
303
  * both vanishing. Unset means no host has claimed the tab.
279
304
  */
280
305
  __SHELVES_QAM_OWNER__?: string;
306
+ /**
307
+ * Forced-owner handshake. A host stamps its own (opaque) owner label here to
308
+ * claim the renderer even alongside a loader (cooperative ownership): the
309
+ * loader keeps owning the renderer and its other plugins, but the bundle binds
310
+ * to the injected host (`__SHELVES_HOST__`) — waiting for it to appear if the
311
+ * loader booted the bundle first — instead of the loader that launched it.
312
+ * Only the injected host stamps this, so presence (not the label's value) is
313
+ * what the bundle keys on.
314
+ */
315
+ __SHELVES_FORCE_OWNER__?: HostOwnerKind;
316
+ /**
317
+ * The renderer's single-owner claim. The first host/bundle to claim writes
318
+ * its kind; a second instance reads it and stands down (no home patch, no
319
+ * settings writes) so there is exactly one injector and one writer.
320
+ */
321
+ __DECK_SHELVES_OWNER__?: HostOwnerKind;
322
+ /** Version identity of the bundle that currently owns the renderer. */
323
+ __DECK_SHELVES_OWNER_META__?: HostOwnerMetadata;
281
324
  }
282
325
  }
283
326
 
284
- export { type Disposable, HOST_API_VERSION, type HostApi, type HostLifecycle, type HostMainMenu, type HostNotifications, type HostQam, type HostRoutes, type HostRpc, type HostUi, type HostUpdates, type MainMenuEntry, type PlatformApi, type PlatformAppMeta, type PlatformCollection, type PlatformTab, type PluginDescriptor, type QamPanel, type ShelfSource, type ShelvesHostGlobal, type ToastOptions };
327
+ export { type Disposable, FORCE_OWNER_GLOBAL, HOST_API_VERSION, type HostApi, type HostLifecycle, type HostMainMenu, type HostNotifications, type HostOwnerKind, type HostOwnerMetadata, type HostQam, type HostRoutes, type HostRpc, type HostUi, type HostUpdates, INJECTED_HOST_GLOBAL, type MainMenuEntry, OWNER_GLOBAL, OWNER_METADATA_GLOBAL, type PlatformApi, type PlatformAppMeta, type PlatformCollection, type PlatformTab, type PluginDescriptor, type QamPanel, type ShelfSource, type ShelvesHostGlobal, type ToastOptions, getInjectedHost, isForcedOwner, readForcedOwner, readOwner };
package/dist/index.js CHANGED
@@ -1,4 +1,36 @@
1
1
  // src/contract/index.ts
2
2
  var HOST_API_VERSION = "1.2.0";
3
+ var INJECTED_HOST_GLOBAL = "__SHELVES_HOST__";
4
+ var FORCE_OWNER_GLOBAL = "__SHELVES_FORCE_OWNER__";
5
+ var OWNER_GLOBAL = "__DECK_SHELVES_OWNER__";
6
+ var OWNER_METADATA_GLOBAL = "__DECK_SHELVES_OWNER_META__";
7
+ function ownershipScope() {
8
+ const g = globalThis;
9
+ return g.window ?? g;
10
+ }
11
+ function readOwnerString(name) {
12
+ try {
13
+ const v = ownershipScope()[name];
14
+ return typeof v === "string" && v.length > 0 ? v : null;
15
+ } catch {
16
+ return null;
17
+ }
18
+ }
19
+ function getInjectedHost() {
20
+ try {
21
+ return ownershipScope()[INJECTED_HOST_GLOBAL] ?? null;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+ function readForcedOwner() {
27
+ return readOwnerString(FORCE_OWNER_GLOBAL);
28
+ }
29
+ function readOwner() {
30
+ return readOwnerString(OWNER_GLOBAL);
31
+ }
32
+ function isForcedOwner() {
33
+ return readForcedOwner() != null;
34
+ }
3
35
 
4
- export { HOST_API_VERSION };
36
+ export { FORCE_OWNER_GLOBAL, HOST_API_VERSION, INJECTED_HOST_GLOBAL, OWNER_GLOBAL, OWNER_METADATA_GLOBAL, getInjectedHost, isForcedOwner, readForcedOwner, readOwner };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deck-shelves/host",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Deck Shelves host contract — the HostApi types all host adapters and the bundle build against.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",