@histoire/sdk 0.0.0-stage → 1.0.0-beta.3
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/LICENSE +21 -0
- package/dist/adapters/types.d.ts +152 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/internal.d.ts +16 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +8 -0
- package/dist/mounts/channel.d.ts +20 -0
- package/dist/mounts/channel.d.ts.map +1 -0
- package/dist/mounts/channel.js +76 -0
- package/dist/mounts/events.d.ts +9 -0
- package/dist/mounts/events.d.ts.map +1 -0
- package/dist/mounts/events.js +45 -0
- package/dist/mounts/geometry.d.ts +9 -0
- package/dist/mounts/geometry.d.ts.map +1 -0
- package/dist/mounts/geometry.js +69 -0
- package/dist/mounts/handle.d.ts +5 -0
- package/dist/mounts/handle.d.ts.map +1 -0
- package/dist/mounts/handle.js +44 -0
- package/dist/mounts/iframe.d.ts +4 -0
- package/dist/mounts/iframe.d.ts.map +1 -0
- package/dist/mounts/iframe.js +143 -0
- package/dist/mounts/overlay.d.ts +11 -0
- package/dist/mounts/overlay.d.ts.map +1 -0
- package/dist/mounts/overlay.js +53 -0
- package/dist/mounts/view-snapshot.d.ts +4 -0
- package/dist/mounts/view-snapshot.d.ts.map +1 -0
- package/dist/mounts/view-snapshot.js +24 -0
- package/dist/persistence/key.d.ts +3 -0
- package/dist/persistence/key.d.ts.map +1 -0
- package/dist/persistence/key.js +4 -0
- package/dist/persistence/storage.d.ts +13 -0
- package/dist/persistence/storage.d.ts.map +1 -0
- package/dist/persistence/storage.js +37 -0
- package/dist/session/channels.d.ts +8 -0
- package/dist/session/channels.d.ts.map +1 -0
- package/dist/session/channels.js +117 -0
- package/dist/session/context.d.ts +97 -0
- package/dist/session/context.d.ts.map +1 -0
- package/dist/session/context.js +136 -0
- package/dist/session/controller.d.ts +5 -0
- package/dist/session/controller.d.ts.map +1 -0
- package/dist/session/controller.js +217 -0
- package/dist/session/debug-lease.d.ts +5 -0
- package/dist/session/debug-lease.d.ts.map +1 -0
- package/dist/session/debug-lease.js +64 -0
- package/dist/session/debug.d.ts +14 -0
- package/dist/session/debug.d.ts.map +1 -0
- package/dist/session/debug.js +242 -0
- package/dist/session/events.d.ts +7 -0
- package/dist/session/events.d.ts.map +1 -0
- package/dist/session/events.js +23 -0
- package/dist/session/inspection.d.ts +5 -0
- package/dist/session/inspection.d.ts.map +1 -0
- package/dist/session/inspection.js +88 -0
- package/dist/session/internal.d.ts +87 -0
- package/dist/session/internal.d.ts.map +1 -0
- package/dist/session/internal.js +144 -0
- package/dist/session/mounts.d.ts +6 -0
- package/dist/session/mounts.d.ts.map +1 -0
- package/dist/session/mounts.js +153 -0
- package/dist/session/notifications.d.ts +5 -0
- package/dist/session/notifications.d.ts.map +1 -0
- package/dist/session/notifications.js +143 -0
- package/dist/session/ownership.d.ts +20 -0
- package/dist/session/ownership.d.ts.map +1 -0
- package/dist/session/ownership.js +69 -0
- package/dist/session/plugin-hub.d.ts +59 -0
- package/dist/session/plugin-hub.d.ts.map +1 -0
- package/dist/session/plugin-hub.js +215 -0
- package/dist/session/plugins.d.ts +8 -0
- package/dist/session/plugins.d.ts.map +1 -0
- package/dist/session/plugins.js +78 -0
- package/dist/session/request.d.ts +8 -0
- package/dist/session/request.d.ts.map +1 -0
- package/dist/session/request.js +99 -0
- package/dist/session/runtime.d.ts +5 -0
- package/dist/session/runtime.d.ts.map +1 -0
- package/dist/session/runtime.js +25 -0
- package/dist/session/selection.d.ts +9 -0
- package/dist/session/selection.d.ts.map +1 -0
- package/dist/session/selection.js +111 -0
- package/dist/session/services.d.ts +18 -0
- package/dist/session/services.d.ts.map +1 -0
- package/dist/session/services.js +51 -0
- package/dist/session/settings.d.ts +7 -0
- package/dist/session/settings.d.ts.map +1 -0
- package/dist/session/settings.js +31 -0
- package/dist/session/snapshot.d.ts +12 -0
- package/dist/session/snapshot.d.ts.map +1 -0
- package/dist/session/snapshot.js +72 -0
- package/dist/session/state.d.ts +11 -0
- package/dist/session/state.d.ts.map +1 -0
- package/dist/session/state.js +73 -0
- package/dist/session/variant.d.ts +4 -0
- package/dist/session/variant.d.ts.map +1 -0
- package/dist/session/variant.js +11 -0
- package/dist/transport/authority.d.ts +35 -0
- package/dist/transport/authority.d.ts.map +1 -0
- package/dist/transport/authority.js +110 -0
- package/dist/transport/connection.d.ts +4 -0
- package/dist/transport/connection.d.ts.map +1 -0
- package/dist/transport/connection.js +37 -0
- package/dist/transport/handshake.d.ts +36 -0
- package/dist/transport/handshake.d.ts.map +1 -0
- package/dist/transport/handshake.js +112 -0
- package/dist/transport/inbound.d.ts +15 -0
- package/dist/transport/inbound.d.ts.map +1 -0
- package/dist/transport/inbound.js +51 -0
- package/dist/transport/port.d.ts +51 -0
- package/dist/transport/port.d.ts.map +1 -0
- package/dist/transport/port.js +288 -0
- package/dist/transport/reply.d.ts +6 -0
- package/dist/transport/reply.d.ts.map +1 -0
- package/dist/transport/reply.js +44 -0
- package/dist/transport/requests.d.ts +33 -0
- package/dist/transport/requests.d.ts.map +1 -0
- package/dist/transport/requests.js +62 -0
- package/dist/transport/session-commands.d.ts +5 -0
- package/dist/transport/session-commands.d.ts.map +1 -0
- package/dist/transport/session-commands.js +70 -0
- package/dist/transport/validated.d.ts +13 -0
- package/dist/transport/validated.d.ts.map +1 -0
- package/dist/transport/validated.js +22 -0
- package/dist/transport/validation.d.ts +8 -0
- package/dist/transport/validation.d.ts.map +1 -0
- package/dist/transport/validation.js +20 -0
- package/dist/types.d.ts +143 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +38 -3
- package/README.md +0 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { HistoireSdkError } from '@histoire/protocol';
|
|
2
|
+
/** Correlation registry never retries or reuses request identities. */
|
|
3
|
+
export function createBridgeRequests() {
|
|
4
|
+
const pending = new Map();
|
|
5
|
+
let next = 0;
|
|
6
|
+
return {
|
|
7
|
+
/** Lookup happens before untrusted successful-result validation. */
|
|
8
|
+
get: (id) => pending.get(id),
|
|
9
|
+
/** Allocate and observe one pending request before posting. */
|
|
10
|
+
add(command, owner, signal, timeout, cancel, source = false) {
|
|
11
|
+
const id = `${owner.connectionId}:request:${++next}`;
|
|
12
|
+
let item;
|
|
13
|
+
const promise = new Promise((resolve, reject) => {
|
|
14
|
+
const timer = setTimeout(() => item.settle({ error: new HistoireSdkError('TIMEOUT', `${command} timed out`) }), timeout);
|
|
15
|
+
const abort = () => item.settle({ error: signal.reason ?? new HistoireSdkError('CANCELLED', 'Request cancelled') });
|
|
16
|
+
item = {
|
|
17
|
+
requestId: id,
|
|
18
|
+
command,
|
|
19
|
+
owner,
|
|
20
|
+
source,
|
|
21
|
+
settle(value) {
|
|
22
|
+
if (!pending.delete(id)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
signal.removeEventListener('abort', abort);
|
|
27
|
+
if ('error' in value) {
|
|
28
|
+
try {
|
|
29
|
+
cancel?.(id);
|
|
30
|
+
}
|
|
31
|
+
catch { /* Failed cancellation cannot prevent local settlement. */ }
|
|
32
|
+
reject(value.error);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
resolve(value.result);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
pending.set(id, item);
|
|
40
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
41
|
+
if (signal.aborted) {
|
|
42
|
+
abort();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
void promise.catch(() => {
|
|
46
|
+
});
|
|
47
|
+
return { id, promise };
|
|
48
|
+
},
|
|
49
|
+
/** Settle exactly once after complete response validation. */
|
|
50
|
+
receive(response) {
|
|
51
|
+
pending.get(response.requestId)?.settle(response.ok ? { result: response.result } : { error: new HistoireSdkError(response.error.code, response.error.message, response.error.details) });
|
|
52
|
+
},
|
|
53
|
+
/** Reject affected work before closing/replacing any resource. */
|
|
54
|
+
reject(error, predicate = () => true) {
|
|
55
|
+
for (const item of pending.values()) {
|
|
56
|
+
if (predicate(item)) {
|
|
57
|
+
item.settle({ error });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HistoireBridgeCommand, HistoireBridgeIdentity } from '@histoire/protocol';
|
|
2
|
+
import type { HistoireSession } from '../types.js';
|
|
3
|
+
/** Finite view intent dispatch into local parent controller; no second controller or plugin tunnel. */
|
|
4
|
+
export declare function dispatchHistoireSessionCommand(session: HistoireSession, command: HistoireBridgeCommand, value: unknown, capture?: HistoireBridgeIdentity, signal?: AbortSignal): Promise<unknown> | unknown;
|
|
5
|
+
//# sourceMappingURL=session-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-commands.d.ts","sourceRoot":"","sources":["../../src/transport/session-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAyBlD,uGAAuG;AACvG,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,sBAAsB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CA2C3M"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { HistoireSdkError, validateHistoireStateSnapshot } from '@histoire/protocol';
|
|
2
|
+
import { requestHistoireOpenInEditor, requestHistoireStatePreset } from '../session/internal.js';
|
|
3
|
+
/** Wire mutations acknowledge actual canonical state while public SDK methods stay void. */
|
|
4
|
+
async function mutateViewState(session, command, input) {
|
|
5
|
+
const captured = session.getSnapshot();
|
|
6
|
+
/** Navigation/source replacement between mutation and read cannot acknowledge replacement. */
|
|
7
|
+
function assertCurrent() {
|
|
8
|
+
const current = session.getSnapshot();
|
|
9
|
+
if (current.source?.sourceId !== captured.source?.sourceId || current.source?.epoch !== captured.source?.epoch || current.source?.revision !== captured.source?.revision) {
|
|
10
|
+
throw new HistoireSdkError('STALE_REVISION', 'State acknowledgment belongs to another source revision');
|
|
11
|
+
}
|
|
12
|
+
if (current.runtime.runtimeId !== captured.runtime.runtimeId || current.selection?.storyId !== captured.selection?.storyId || current.selection?.variantId !== captured.selection?.variantId) {
|
|
13
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'State acknowledgment belongs to another runtime');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (command === 'state.patch')
|
|
17
|
+
await session.state.patch(input);
|
|
18
|
+
else
|
|
19
|
+
await session.state.reset();
|
|
20
|
+
assertCurrent();
|
|
21
|
+
const state = await session.state.get();
|
|
22
|
+
assertCurrent();
|
|
23
|
+
validateHistoireStateSnapshot(state);
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
/** Finite view intent dispatch into local parent controller; no second controller or plugin tunnel. */
|
|
27
|
+
export function dispatchHistoireSessionCommand(session, command, value, capture, signal) {
|
|
28
|
+
const input = value;
|
|
29
|
+
if (capture) {
|
|
30
|
+
const snapshot = session.getSnapshot();
|
|
31
|
+
if (capture.sourceId !== snapshot.source?.sourceId || capture.epoch !== snapshot.source.epoch || capture.revision !== snapshot.source.revision) {
|
|
32
|
+
throw new HistoireSdkError('STALE_REVISION', 'View intent belongs to another source revision');
|
|
33
|
+
}
|
|
34
|
+
const runtime = ['state.get', 'state.patch', 'state.reset', 'controls.preset', 'tests.collect', 'channel.post'].includes(command) || (command === 'source.get' && input.mode === 'dynamic') || (command === 'tests.run' && input.mode === 'preview');
|
|
35
|
+
if (runtime || command === 'tests.run') {
|
|
36
|
+
if (capture.target?.storyId !== snapshot.selection?.storyId || capture.target?.variantId !== snapshot.selection?.variantId || (runtime && capture.runtimeId !== (snapshot.runtime.runtimeId ?? undefined))) {
|
|
37
|
+
throw new HistoireSdkError('RUNTIME_CHANGED', 'View intent belongs to another target or runtime');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
switch (command) {
|
|
42
|
+
case 'catalog.list': return session.catalog.list();
|
|
43
|
+
case 'catalog.getStory': return session.catalog.getStory(input.storyId);
|
|
44
|
+
case 'catalog.search': return session.catalog.search(input.query);
|
|
45
|
+
case 'selection.select': return session.selection.select(input);
|
|
46
|
+
case 'state.get': return session.state.get();
|
|
47
|
+
case 'state.patch': return mutateViewState(session, command, input);
|
|
48
|
+
case 'state.reset': return mutateViewState(session, command, input);
|
|
49
|
+
case 'controls.preset': return requestHistoireStatePreset(session, input);
|
|
50
|
+
case 'openInEditor': return requestHistoireOpenInEditor(session, input);
|
|
51
|
+
case 'settings.update': return session.settings.update(input);
|
|
52
|
+
case 'events.clear': return session.events.clear();
|
|
53
|
+
case 'docs.get': return session.docs.get(input.storyId);
|
|
54
|
+
case 'source.get': return session.source.get(input);
|
|
55
|
+
case 'tests.collect': return session.tests.collect();
|
|
56
|
+
case 'tests.run': return session.tests.run({ mode: input.mode, signal });
|
|
57
|
+
case 'inspection.variant': return session.inspect.variant({ ...input, signal });
|
|
58
|
+
case 'inspection.dom': return session.inspect.dom({ ...input, signal });
|
|
59
|
+
case 'inspection.highlight': return session.inspect.highlight({ ...input, signal });
|
|
60
|
+
case 'inspection.highlightLease': return session.inspect.highlightLease({ ...input, signal });
|
|
61
|
+
case 'inspection.highlightClear': return session.inspect.clearHighlight({ ...input, signal });
|
|
62
|
+
case 'inspection.pick': return session.inspect.pick({ ...input, signal });
|
|
63
|
+
case 'inspection.components': return session.inspect.components({ ...input, signal });
|
|
64
|
+
case 'inspection.component': return session.inspect.component({ ...input, signal });
|
|
65
|
+
case 'inspection.componentForElement': return session.inspect.componentForElement({ ...input, signal });
|
|
66
|
+
case 'inspection.accessibility': return session.inspect.accessibility({ ...input, signal });
|
|
67
|
+
case 'channel.post': return session.channels.open(input.name).post(input.type, input.data).then(() => null);
|
|
68
|
+
default: throw new HistoireSdkError('CAPABILITY_UNAVAILABLE', 'View intent unavailable');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HistoireSessionNotification } from '../adapters/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Records that a notification's payload already passed bridge envelope validation.
|
|
4
|
+
* @param notification Notification built directly from a validated envelope payload.
|
|
5
|
+
* @returns Same notification.
|
|
6
|
+
*/
|
|
7
|
+
export declare function markValidatedNotification<T extends HistoireSessionNotification>(notification: T): T;
|
|
8
|
+
/**
|
|
9
|
+
* Whether a notification was emitted by a bridge port from a validated envelope.
|
|
10
|
+
* @param notification Notification received by a session handler.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidatedNotification(notification: HistoireSessionNotification): boolean;
|
|
13
|
+
//# sourceMappingURL=validated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validated.d.ts","sourceRoot":"","sources":["../../src/transport/validated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA;AASvE;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,2BAA2B,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAGnG;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,2BAA2B,GAAG,OAAO,CAE1F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifications emitted by a bridge port after full envelope validation. Membership lets
|
|
3
|
+
* session handlers skip re-measuring and re-validating the same payload objects; any
|
|
4
|
+
* other transport's notifications (or projected copies) are not members and stay validated.
|
|
5
|
+
*/
|
|
6
|
+
const validatedNotifications = new WeakSet();
|
|
7
|
+
/**
|
|
8
|
+
* Records that a notification's payload already passed bridge envelope validation.
|
|
9
|
+
* @param notification Notification built directly from a validated envelope payload.
|
|
10
|
+
* @returns Same notification.
|
|
11
|
+
*/
|
|
12
|
+
export function markValidatedNotification(notification) {
|
|
13
|
+
validatedNotifications.add(notification);
|
|
14
|
+
return notification;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Whether a notification was emitted by a bridge port from a validated envelope.
|
|
18
|
+
* @param notification Notification received by a session handler.
|
|
19
|
+
*/
|
|
20
|
+
export function isValidatedNotification(notification) {
|
|
21
|
+
return validatedNotifications.has(notification);
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HistoireBridgeCommand, HistoireSourceDescriptor } from '@histoire/protocol';
|
|
2
|
+
/** Shared control budget; runtime execution retains its established deadline. */
|
|
3
|
+
export declare const HISTOIRE_CONTROL_TIMEOUT = 15000;
|
|
4
|
+
/** Selects deadline from source execution budgets, never generic connection budget. */
|
|
5
|
+
export declare function getBridgeRequestTimeout(command: HistoireBridgeCommand, payload: unknown, descriptor?: HistoireSourceDescriptor): number;
|
|
6
|
+
/** Port authority derives from requested first-party surface, never message hints. */
|
|
7
|
+
export declare function getBridgeSurfaceRole(surface: string): 'primary' | 'controls' | 'view';
|
|
8
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/transport/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AACzF,iFAAiF;AACjF,eAAO,MAAM,wBAAwB,QAAQ,CAAA;AAC7C,uFAAuF;AACvF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,wBAAwB,GAAG,MAAM,CAcvI;AACD,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,CAErF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Shared control budget; runtime execution retains its established deadline. */
|
|
2
|
+
export const HISTOIRE_CONTROL_TIMEOUT = 15000;
|
|
3
|
+
/** Selects deadline from source execution budgets, never generic connection budget. */
|
|
4
|
+
export function getBridgeRequestTimeout(command, payload, descriptor) {
|
|
5
|
+
const mode = payload.mode;
|
|
6
|
+
if (['view.sync', 'selection.select', 'state.get', 'state.patch', 'state.reset', 'tests.collect'].includes(command) || (command === 'source.get' && mode === 'dynamic')) {
|
|
7
|
+
return (descriptor?.config?.storyCollectTimeout ?? 30000) + HISTOIRE_CONTROL_TIMEOUT;
|
|
8
|
+
}
|
|
9
|
+
if (command !== 'tests.run') {
|
|
10
|
+
return HISTOIRE_CONTROL_TIMEOUT;
|
|
11
|
+
}
|
|
12
|
+
const budget = descriptor?.config?.runTimeout ?? 300000;
|
|
13
|
+
return (payload.mode === 'server'
|
|
14
|
+
? Math.max(360000, budget)
|
|
15
|
+
: budget) + HISTOIRE_CONTROL_TIMEOUT;
|
|
16
|
+
}
|
|
17
|
+
/** Port authority derives from requested first-party surface, never message hints. */
|
|
18
|
+
export function getBridgeSurfaceRole(surface) {
|
|
19
|
+
return ['explorer', 'preview'].includes(surface) ? 'primary' : surface === 'controls' ? 'controls' : 'view';
|
|
20
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { HistoireCatalogStory, HistoireDocsContent, HistoireEmbedPresentation, HistoireEvent, HistoireFramePluginInfo, HistoireHostChannelMessage, HistoireJsonValue, HistoirePluginChannel, HistoireReadonly, HistoireSearchResult, HistoireSelectionInput, HistoireSettingsPatch, HistoireSnapshot, HistoireSourceContent, HistoireStateSnapshot, HistoireSurface, HistoireTarget, HistoireTestCollectionResult, HistoireTestRunSummary } from '@histoire/protocol';
|
|
2
|
+
export type * from '@histoire/protocol';
|
|
3
|
+
/** Opt-in namespace. Subscriptions retire when runtime is replaced/disconnected. */
|
|
4
|
+
export interface HistoireHostChannel {
|
|
5
|
+
/** Send bounded JSON to current selected ready primary; never queue/retry. */
|
|
6
|
+
post: (type: string, data: HistoireJsonValue) => Promise<void>;
|
|
7
|
+
/** Observe attributed messages; subscribe again after runtime replacement. */
|
|
8
|
+
subscribe: (listener: (message: HistoireHostChannelMessage) => void) => () => void;
|
|
9
|
+
/** Saturated local rate, inbound validation, and listener failure count. */
|
|
10
|
+
getDroppedCount: () => number;
|
|
11
|
+
}
|
|
12
|
+
/** Frame plugin actor attached in the session's primary runtime document. */
|
|
13
|
+
export interface HistoirePluginActor {
|
|
14
|
+
/** Attached plugin. */
|
|
15
|
+
readonly pluginId: string;
|
|
16
|
+
/** Rendered mount identity; channels bind to it. */
|
|
17
|
+
readonly actorId: string;
|
|
18
|
+
/** Variant rendered by the actor. */
|
|
19
|
+
readonly target: HistoireTarget;
|
|
20
|
+
/** Runtime document hosting the actor. */
|
|
21
|
+
readonly runtimeId: string;
|
|
22
|
+
}
|
|
23
|
+
/** Frame plugin messaging. Remote hosts never evaluate book plugin modules; this is data only. */
|
|
24
|
+
export interface HistoireSessionPlugins {
|
|
25
|
+
/** Frame plugins the connected book advertises; works on a data-only connection. */
|
|
26
|
+
frames: () => readonly HistoireFramePluginInfo[];
|
|
27
|
+
/** Actors of `pluginId` attached in the primary runtime, in attach order. */
|
|
28
|
+
actors: (pluginId: string) => readonly HistoirePluginActor[];
|
|
29
|
+
/** Observes actor attach and detach; returns unsubscribe. */
|
|
30
|
+
subscribe: (listener: () => void) => () => void;
|
|
31
|
+
/** Channel bound to exactly `frame.actorId`; never retargets, rejects after the actor retires. */
|
|
32
|
+
open: (pluginId: string, frame: {
|
|
33
|
+
readonly actorId: string;
|
|
34
|
+
}) => HistoirePluginChannel;
|
|
35
|
+
}
|
|
36
|
+
/** Remote book options; construction never accesses DOM. */
|
|
37
|
+
export interface HistoireSessionOptions {
|
|
38
|
+
/** Absolute HTTP(S) book base URL. */
|
|
39
|
+
url: string;
|
|
40
|
+
/** Optional source-scoped preference namespace. */
|
|
41
|
+
persistenceKey?: string;
|
|
42
|
+
}
|
|
43
|
+
/** Caller-owned surface attachment, including failed mounts. */
|
|
44
|
+
export interface HistoireMount {
|
|
45
|
+
/** Unique attachment identity. */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Actual view/runtime readiness, never iframe load alone. */
|
|
48
|
+
ready: Promise<void>;
|
|
49
|
+
/** Idempotent complete resource teardown. */
|
|
50
|
+
unmount: () => Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/** Scoped presentation is supported only by explorer mounts. */
|
|
53
|
+
export type HistoireMountOptions = ({
|
|
54
|
+
surface: 'explorer';
|
|
55
|
+
presentation?: HistoireEmbedPresentation;
|
|
56
|
+
} | {
|
|
57
|
+
surface: Exclude<HistoireSurface, 'explorer'>;
|
|
58
|
+
presentation?: never;
|
|
59
|
+
}) & {
|
|
60
|
+
/** Gutter in CSS pixels around the variant of a `preview` or scoped explorer embed, replacing the story and project padding. */
|
|
61
|
+
padding?: number;
|
|
62
|
+
};
|
|
63
|
+
/** Framework-neutral controller shared by iframe and native Vue consumers. */
|
|
64
|
+
export interface HistoireSession {
|
|
65
|
+
/** Opt-in diagnostic observations of the currently mounted document. */
|
|
66
|
+
debug: import('@histoire/protocol').HistoireDebug;
|
|
67
|
+
/** Bounded reads of an already mounted runtime. */
|
|
68
|
+
inspect: import('@histoire/protocol').HistoireInspection;
|
|
69
|
+
/** Explicitly connect data-only source bridge. */
|
|
70
|
+
connect: () => Promise<void>;
|
|
71
|
+
/** Stable read-only current snapshot. */
|
|
72
|
+
getSnapshot: () => HistoireReadonly<HistoireSnapshot>;
|
|
73
|
+
/** Observe future coherent publications; returns unsubscribe. */
|
|
74
|
+
subscribe: (listener: (snapshot: HistoireReadonly<HistoireSnapshot>) => void) => () => void;
|
|
75
|
+
/** Metadata-only catalog operations. */
|
|
76
|
+
catalog: {
|
|
77
|
+
/** Read completed source catalog. */
|
|
78
|
+
list: () => Promise<readonly HistoireCatalogStory[]>;
|
|
79
|
+
/** Resolve exact unambiguous story. */
|
|
80
|
+
getStory: (storyId: string) => Promise<HistoireCatalogStory>;
|
|
81
|
+
/** Search titles/docs without story mounting. */
|
|
82
|
+
search: (query: string) => Promise<readonly HistoireSearchResult[]>;
|
|
83
|
+
};
|
|
84
|
+
/** One session-owned selected target. */
|
|
85
|
+
selection: {
|
|
86
|
+
select: (input: HistoireSelectionInput) => Promise<void>;
|
|
87
|
+
};
|
|
88
|
+
/** Explicit ready-runtime state operations. */
|
|
89
|
+
state: {
|
|
90
|
+
/** Request authoritative cleaned state. */
|
|
91
|
+
get: () => Promise<HistoireStateSnapshot>;
|
|
92
|
+
/** Merge projection without replacing live identities. */
|
|
93
|
+
patch: (patch: Record<string, unknown>) => Promise<void>;
|
|
94
|
+
/** Restore initial runtime snapshot. */
|
|
95
|
+
reset: () => Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
/** Host-owned surface/runtime preferences. */
|
|
98
|
+
settings: {
|
|
99
|
+
update: (patch: HistoireSettingsPatch) => Promise<void>;
|
|
100
|
+
};
|
|
101
|
+
/** Attributable bounded event stream. */
|
|
102
|
+
events: {
|
|
103
|
+
/** Subscribe to future events, returning unsubscribe. */
|
|
104
|
+
subscribe: (listener: (event: HistoireEvent) => void) => () => void;
|
|
105
|
+
/** Clear history and dropped count. */
|
|
106
|
+
clear: () => void;
|
|
107
|
+
};
|
|
108
|
+
/** Application namespaces explicitly enabled by source configuration. */
|
|
109
|
+
channels: {
|
|
110
|
+
open: (name: string) => HistoireHostChannel;
|
|
111
|
+
};
|
|
112
|
+
/** Frame plugin inventory and per-actor channels; absent on view-session proxies. */
|
|
113
|
+
plugins?: HistoireSessionPlugins;
|
|
114
|
+
/** Lazy data-service documentation. */
|
|
115
|
+
docs: {
|
|
116
|
+
get: (storyId: string) => Promise<HistoireDocsContent>;
|
|
117
|
+
};
|
|
118
|
+
/** Raw data-service or explicit runtime-generated source. */
|
|
119
|
+
source: {
|
|
120
|
+
get: (input: {
|
|
121
|
+
storyId: string;
|
|
122
|
+
variantId?: string;
|
|
123
|
+
mode: 'raw' | 'dynamic';
|
|
124
|
+
}) => Promise<HistoireSourceContent>;
|
|
125
|
+
};
|
|
126
|
+
/** Explicit execution modes; never retry/fallback automatically. */
|
|
127
|
+
tests: {
|
|
128
|
+
/** Collect selected ready preview definitions. */
|
|
129
|
+
collect: () => Promise<HistoireTestCollectionResult>;
|
|
130
|
+
/** Run captured selected variant. */
|
|
131
|
+
run: (options: {
|
|
132
|
+
mode: 'preview' | 'server';
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
}) => Promise<HistoireTestRunSummary>;
|
|
135
|
+
};
|
|
136
|
+
/** Reserve runtime synchronously when mounting primary surface. */
|
|
137
|
+
mount: (container: HTMLElement, options: HistoireMountOptions) => HistoireMount;
|
|
138
|
+
/** Explicit offscreen primary with real viewport dimensions. */
|
|
139
|
+
createHiddenPreview: () => HistoireMount;
|
|
140
|
+
/** Terminal idempotent disposal, rejecting pending work immediately. */
|
|
141
|
+
dispose: () => Promise<void>;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,EACb,uBAAuB,EACvB,0BAA0B,EAC1B,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,4BA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,CAAC,KAAK,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAA;SAAE,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAA;KAAE,CAAA;IAC5H,oEAAoE;IACpE,KAAK,EAAE;QACL,kDAAkD;QAClD,OAAO,EAAE,MAAM,OAAO,CAAC,4BAA4B,CAAC,CAAA;QACpD,qCAAqC;QACrC,GAAG,EAAE,CAAC,OAAO,EAAE;YAAE,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;YAAC,MAAM,CAAC,EAAE,WAAW,CAAA;SAAE,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAA;KACxG,CAAA;IACD,mEAAmE;IACnE,KAAK,EAAE,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,KAAK,aAAa,CAAA;IAC/E,gEAAgE;IAChE,mBAAmB,EAAE,MAAM,aAAa,CAAA;IACxC,wEAAwE;IACxE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@histoire/sdk",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.3",
|
|
5
|
+
"description": "Framework-neutral Histoire embedding SDK",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./internal": {
|
|
17
|
+
"types": "./dist/internal.d.ts",
|
|
18
|
+
"default": "./dist/internal.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@histoire/protocol": "^1.0.0-beta.3"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
32
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
33
|
+
"vite": "^8.3.5",
|
|
34
|
+
"vitest": "5.1.1"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "rimraf dist && tsc",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"watch": "tsc -w --sourceMap"
|
|
40
|
+
}
|
|
6
41
|
}
|
package/README.md
DELETED