forgeframe 0.0.12 → 0.0.13
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 +105 -43
- package/dist/communication/index.d.ts +5 -4
- package/dist/core/consumer/callbacks.d.ts +19 -0
- package/dist/core/consumer/child-refs.d.ts +15 -0
- package/dist/core/consumer/siblings.d.ts +23 -0
- package/dist/core/consumer/transport.d.ts +11 -8
- package/dist/core/consumer.d.ts +0 -73
- package/dist/core/host/auto-init.d.ts +19 -0
- package/dist/core/host/bootstrap.d.ts +15 -0
- package/dist/core/host/component.d.ts +32 -0
- package/dist/core/host/props-runtime.d.ts +31 -0
- package/dist/core/host/security.d.ts +31 -0
- package/dist/core/host/transport.d.ts +44 -0
- package/dist/core/host/types.d.ts +63 -0
- package/dist/core/host.d.ts +6 -276
- package/dist/drivers/index.d.ts +7 -9
- package/dist/drivers/react.d.ts +1 -2
- package/dist/forgeframe.d.ts +202 -0
- package/dist/forgeframe.js +1626 -1786
- package/dist/forgeframe.umd.cjs +2 -2
- package/dist/index.d.ts +2 -202
- package/dist/render/index.d.ts +5 -29
- package/dist/utils/domain-pattern.d.ts +35 -0
- package/dist/window/helpers.d.ts +1 -1
- package/dist/window/index.d.ts +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# ForgeFrame
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/forgeframe)
|
|
4
|
+
[](https://github.com/jshsmth/ForgeFrame/releases)
|
|
5
|
+
|
|
6
|
+
A TypeScript-first framework for embedding cross-domain iframes and popups with seamless communication. Pass data and callbacks across domains for payment forms, auth widgets, third-party integrations, and micro-frontends. Zero runtime dependencies with ESM and UMD builds.
|
|
4
7
|
|
|
5
8
|
### Terminology
|
|
6
9
|
|
|
@@ -133,10 +136,8 @@ declare global {
|
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
ForgeFrame.initHost();
|
|
139
|
-
|
|
139
|
+
// Importing the runtime registers deferred host initialization for window.hostProps.
|
|
140
|
+
// Call ForgeFrame.initHost() only if you need init before the first read below.
|
|
140
141
|
const { amount, onSuccess, close } = window.hostProps;
|
|
141
142
|
|
|
142
143
|
document.getElementById('total')!.textContent = `$${amount}`;
|
|
@@ -147,6 +148,7 @@ document.getElementById('pay-btn')!.onclick = async () => {
|
|
|
147
148
|
```
|
|
148
149
|
|
|
149
150
|
That's it! ForgeFrame handles all the cross-domain communication automatically.
|
|
151
|
+
If you need to force host initialization before first `window.hostProps` access, see [Manual Host Init with initHost](#manual-host-init-with-inithost).
|
|
150
152
|
|
|
151
153
|
---
|
|
152
154
|
|
|
@@ -210,10 +212,8 @@ declare global {
|
|
|
210
212
|
}
|
|
211
213
|
}
|
|
212
214
|
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
ForgeFrame.initHost();
|
|
216
|
-
|
|
215
|
+
// Importing the runtime registers deferred host initialization for window.hostProps.
|
|
216
|
+
// Call ForgeFrame.initHost() only if you need init before the first read below.
|
|
217
217
|
const { email, onLogin, onCancel, close } = window.hostProps;
|
|
218
218
|
|
|
219
219
|
if (email) document.getElementById('email')!.value = email;
|
|
@@ -223,7 +223,6 @@ document.getElementById('login-form')!.onsubmit = async (e) => {
|
|
|
223
223
|
await onLogin({
|
|
224
224
|
id: 1,
|
|
225
225
|
name: 'John Doe',
|
|
226
|
-
email: document.getElementById('email')!.value,
|
|
227
226
|
});
|
|
228
227
|
await close();
|
|
229
228
|
};
|
|
@@ -238,7 +237,7 @@ document.getElementById('cancel')!.onclick = async () => {
|
|
|
238
237
|
<summary>Explanation</summary>
|
|
239
238
|
|
|
240
239
|
- **`HostProps<LoginProps>`**: Combines your props with built-in methods (`close`, `resize`, etc.)
|
|
241
|
-
-
|
|
240
|
+
- **Host init**: Importing `forgeframe` in the host bundle registers deferred host initialization. Accessing `window.hostProps` then flushes it automatically; use `ForgeFrame.initHost()` only when you need to force init before first `hostProps` access.
|
|
242
241
|
- **`window.hostProps`**: Contains all props passed from the consumer plus built-in methods
|
|
243
242
|
- **`close()`**: Built-in method to close the iframe/popup
|
|
244
243
|
|
|
@@ -400,6 +399,50 @@ const MyComponent = ForgeFrame.create({
|
|
|
400
399
|
});
|
|
401
400
|
```
|
|
402
401
|
|
|
402
|
+
Note: ForgeFrame runs schema validation synchronously. Schemas with async `~standard.validate` are not supported.
|
|
403
|
+
|
|
404
|
+
### Advanced Prop Definitions
|
|
405
|
+
|
|
406
|
+
Use the object form when a prop needs transport rules in addition to validation.
|
|
407
|
+
|
|
408
|
+
```typescript
|
|
409
|
+
import ForgeFrame, { prop, PROP_SERIALIZATION } from 'forgeframe';
|
|
410
|
+
|
|
411
|
+
const SecureWidget = ForgeFrame.create({
|
|
412
|
+
tag: 'secure-widget',
|
|
413
|
+
url: 'https://widgets.example.com/secure',
|
|
414
|
+
props: {
|
|
415
|
+
profile: {
|
|
416
|
+
schema: prop.object(),
|
|
417
|
+
serialization: PROP_SERIALIZATION.DOTIFY,
|
|
418
|
+
},
|
|
419
|
+
secret: {
|
|
420
|
+
schema: prop.string(),
|
|
421
|
+
sameDomain: true,
|
|
422
|
+
},
|
|
423
|
+
auditId: {
|
|
424
|
+
schema: prop.string(),
|
|
425
|
+
queryParam: true,
|
|
426
|
+
},
|
|
427
|
+
internalState: {
|
|
428
|
+
schema: prop.any(),
|
|
429
|
+
sendToHost: false,
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
| Option | Description |
|
|
436
|
+
|--------|-------------|
|
|
437
|
+
| `sendToHost` | Skip sending the prop to the host when set to `false` |
|
|
438
|
+
| `sameDomain` | Only deliver the prop after the loaded host is verified to be same-origin. It is not included in the initial bootstrap payload |
|
|
439
|
+
| `trustedDomains` | Only send the prop to matching host domains |
|
|
440
|
+
| `serialization` | Choose how object props are transferred: `JSON` (default), `BASE64`, or `DOTIFY` |
|
|
441
|
+
| `queryParam` / `bodyParam` | Include the prop in the host page's initial HTTP request |
|
|
442
|
+
|
|
443
|
+
- Use `sameDomain` for values that should never be exposed during cross-origin bootstrap.
|
|
444
|
+
- `DOTIFY` safely preserves nested object keys that contain separators such as `.`, `&`, or `=`.
|
|
445
|
+
|
|
403
446
|
### Passing Props via URL or POST Body (Advanced)
|
|
404
447
|
|
|
405
448
|
Use prop definition flags to include specific values in the host page's initial HTTP request:
|
|
@@ -440,12 +483,23 @@ window.hostProps.onProps((newProps) => {
|
|
|
440
483
|
});
|
|
441
484
|
```
|
|
442
485
|
|
|
486
|
+
Built-in `window.hostProps` names are reserved. Consumer props with names such as
|
|
487
|
+
`uid`, `tag`, `close`, `focus`, `resize`, `show`, `hide`, `onProps`, `onError`,
|
|
488
|
+
`getConsumer`, `getConsumerDomain`, `export`, `consumer`, `getPeerInstances`, and
|
|
489
|
+
`children` are kept in `hostProps.consumer.props`, but they do not override the
|
|
490
|
+
top-level ForgeFrame methods and metadata exposed on `window.hostProps`.
|
|
491
|
+
|
|
443
492
|
---
|
|
444
493
|
|
|
445
494
|
## Host Window API (hostProps)
|
|
446
495
|
|
|
447
496
|
In host windows, `window.hostProps` provides access to props and control methods.
|
|
448
497
|
|
|
498
|
+
When rendering in iframe mode, ForgeFrame applies a default sandbox of
|
|
499
|
+
`allow-scripts allow-same-origin allow-forms allow-popups` unless you explicitly
|
|
500
|
+
set `attributes.sandbox` on the consumer component. An explicit `sandbox` value is
|
|
501
|
+
used as-is.
|
|
502
|
+
|
|
449
503
|
### TypeScript Setup
|
|
450
504
|
|
|
451
505
|
```typescript
|
|
@@ -462,13 +516,21 @@ declare global {
|
|
|
462
516
|
}
|
|
463
517
|
}
|
|
464
518
|
|
|
465
|
-
//
|
|
466
|
-
// If your host defines a component via create(), init is handled automatically.
|
|
467
|
-
ForgeFrame.initHost();
|
|
468
|
-
|
|
519
|
+
// Import the runtime in your host bundle so ForgeFrame can expose window.hostProps.
|
|
469
520
|
const { email, onLogin, close, resize } = window.hostProps!;
|
|
470
521
|
```
|
|
471
522
|
|
|
523
|
+
### Manual Host Init with initHost
|
|
524
|
+
|
|
525
|
+
`ForgeFrame.initHost()` is optional and only needed to force the host handshake early.
|
|
526
|
+
|
|
527
|
+
Use it when:
|
|
528
|
+
- You need initialization to complete before the first read of `window.hostProps`.
|
|
529
|
+
- Your host boot flow delays that first `window.hostProps` access (for example: lazy-loaded modules, async startup, or gated initialization).
|
|
530
|
+
- You want deterministic init timing in tests or instrumentation.
|
|
531
|
+
|
|
532
|
+
You can skip it when the host bundle imports `forgeframe` at runtime and normal startup reads `window.hostProps` directly, since that first access flushes host initialization automatically.
|
|
533
|
+
|
|
472
534
|
### Available Methods
|
|
473
535
|
|
|
474
536
|
```typescript
|
|
@@ -485,16 +547,17 @@ await props.resize({ width: 500, height: 400 });
|
|
|
485
547
|
await props.show();
|
|
486
548
|
await props.hide();
|
|
487
549
|
|
|
488
|
-
props.onProps((newProps) => { /* handle updates */ });
|
|
489
|
-
props.onError(new Error('Something failed'));
|
|
550
|
+
const { cancel } = props.onProps((newProps) => { /* handle updates */ });
|
|
551
|
+
await props.onError(new Error('Something failed'));
|
|
490
552
|
await props.export({ validate: () => true });
|
|
491
553
|
|
|
492
554
|
props.getConsumer();
|
|
493
555
|
props.getConsumerDomain();
|
|
494
556
|
props.consumer.props;
|
|
495
|
-
props.consumer.export(data);
|
|
557
|
+
await props.consumer.export(data);
|
|
496
558
|
|
|
497
559
|
const peers = await props.getPeerInstances();
|
|
560
|
+
cancel();
|
|
498
561
|
```
|
|
499
562
|
|
|
500
563
|
<details>
|
|
@@ -505,16 +568,18 @@ const peers = await props.getPeerInstances();
|
|
|
505
568
|
| `email`, `onLogin` | Your custom props and callbacks |
|
|
506
569
|
| `uid`, `tag` | Built-in identifiers |
|
|
507
570
|
| `close()` | Close the component |
|
|
508
|
-
| `focus()` |
|
|
571
|
+
| `focus()` | Request focus for iframe/popup |
|
|
509
572
|
| `resize()` | Resize the component |
|
|
510
573
|
| `show()`, `hide()` | Toggle visibility |
|
|
511
|
-
| `onProps()` | Listen for prop updates |
|
|
574
|
+
| `onProps()` | Listen for prop updates (returns `{ cancel() }`) |
|
|
512
575
|
| `onError()` | Report errors to consumer |
|
|
513
576
|
| `export()` | Export methods/data to consumer |
|
|
514
577
|
| `getConsumer()` | Get consumer window reference |
|
|
515
578
|
| `getConsumerDomain()` | Get consumer origin |
|
|
516
579
|
| `consumer.props` | Access consumer's props |
|
|
580
|
+
| `consumer.export()` | Send data to consumer from host context |
|
|
517
581
|
| `getPeerInstances()` | Get peer component instances from the same consumer |
|
|
582
|
+
| `children` | Nested component factories provided by consumer (if configured) |
|
|
518
583
|
|
|
519
584
|
</details>
|
|
520
585
|
|
|
@@ -525,7 +590,7 @@ Host components can export methods/data for the consumer to use.
|
|
|
525
590
|
> **`Host`**
|
|
526
591
|
|
|
527
592
|
```typescript
|
|
528
|
-
window.hostProps.export({
|
|
593
|
+
await window.hostProps.export({
|
|
529
594
|
validate: () => document.getElementById('form').checkValidity(),
|
|
530
595
|
getFormData: () => ({ email: document.getElementById('email').value }),
|
|
531
596
|
});
|
|
@@ -624,7 +689,7 @@ const MyComponent = ForgeFrame.create({
|
|
|
624
689
|
### Basic Usage
|
|
625
690
|
|
|
626
691
|
```tsx
|
|
627
|
-
import React from 'react';
|
|
692
|
+
import React, { useState } from 'react';
|
|
628
693
|
import ForgeFrame, { prop, createReactComponent } from 'forgeframe';
|
|
629
694
|
|
|
630
695
|
const LoginComponent = ForgeFrame.create({
|
|
@@ -721,6 +786,7 @@ const AutoResizeComponent = ForgeFrame.create({
|
|
|
721
786
|
### Domain Security
|
|
722
787
|
|
|
723
788
|
Restrict which domains can embed or communicate.
|
|
789
|
+
String domain patterns support `*` wildcards (for example, `'https://*.myapp.com'`), and arrays can mix strings and `RegExp`.
|
|
724
790
|
|
|
725
791
|
```typescript
|
|
726
792
|
const SecureComponent = ForgeFrame.create({
|
|
@@ -793,13 +859,15 @@ ForgeFrame.destroyByTag(tag) // Destroy all instances of a tag
|
|
|
793
859
|
ForgeFrame.destroyAll() // Destroy all instances
|
|
794
860
|
ForgeFrame.isHost() // Check if in host context
|
|
795
861
|
ForgeFrame.isEmbedded() // Alias for isHost() - more intuitive naming
|
|
796
|
-
ForgeFrame.initHost() //
|
|
862
|
+
ForgeFrame.initHost() // Optional: flush host handshake before first hostProps access
|
|
797
863
|
ForgeFrame.getHostProps() // Get hostProps in host context
|
|
798
864
|
ForgeFrame.isStandardSchema(val) // Check if value is a Standard Schema
|
|
799
865
|
|
|
800
866
|
ForgeFrame.prop // Prop schema builders (also exported as `prop`)
|
|
867
|
+
ForgeFrame.PROP_SERIALIZATION // Prop serialization constants
|
|
801
868
|
ForgeFrame.CONTEXT // Context constants (IFRAME, POPUP)
|
|
802
869
|
ForgeFrame.EVENT // Event name constants
|
|
870
|
+
ForgeFrame.PopupOpenError // Popup blocker/open failures
|
|
803
871
|
ForgeFrame.VERSION // Library version
|
|
804
872
|
```
|
|
805
873
|
|
|
@@ -809,20 +877,20 @@ ForgeFrame.VERSION // Library version
|
|
|
809
877
|
interface ComponentOptions<P> {
|
|
810
878
|
tag: string;
|
|
811
879
|
url: string | ((props: P) => string);
|
|
812
|
-
dimensions?: { width?: number | string; height?: number | string };
|
|
880
|
+
dimensions?: { width?: number | string; height?: number | string } | ((props: P) => { width?: number | string; height?: number | string });
|
|
813
881
|
autoResize?: { width?: boolean; height?: boolean; element?: string };
|
|
814
882
|
props?: PropsDefinition<P>;
|
|
815
883
|
defaultContext?: 'iframe' | 'popup';
|
|
816
|
-
containerTemplate?: (ctx: TemplateContext) => HTMLElement;
|
|
817
|
-
prerenderTemplate?: (ctx: TemplateContext) => HTMLElement;
|
|
818
|
-
domain?:
|
|
819
|
-
allowedConsumerDomains?:
|
|
884
|
+
containerTemplate?: (ctx: TemplateContext<P>) => HTMLElement | null;
|
|
885
|
+
prerenderTemplate?: (ctx: TemplateContext<P>) => HTMLElement | null;
|
|
886
|
+
domain?: DomainMatcher;
|
|
887
|
+
allowedConsumerDomains?: DomainMatcher;
|
|
820
888
|
eligible?: (opts: { props: P }) => { eligible: boolean; reason?: string };
|
|
821
889
|
validate?: (opts: { props: P }) => void;
|
|
822
|
-
attributes?: IframeAttributes;
|
|
823
|
-
style?:
|
|
890
|
+
attributes?: IframeAttributes | ((props: P) => IframeAttributes);
|
|
891
|
+
style?: IframeStyles | ((props: P) => IframeStyles);
|
|
824
892
|
timeout?: number;
|
|
825
|
-
children?: () => Record<string, ForgeFrameComponent>;
|
|
893
|
+
children?: (opts: { props: P }) => Record<string, ForgeFrameComponent>;
|
|
826
894
|
}
|
|
827
895
|
```
|
|
828
896
|
|
|
@@ -831,14 +899,14 @@ interface ComponentOptions<P> {
|
|
|
831
899
|
```typescript
|
|
832
900
|
const instance = MyComponent(props);
|
|
833
901
|
|
|
834
|
-
await instance.render(container
|
|
902
|
+
await instance.render(container, context?) // Render into a container (container is required)
|
|
835
903
|
await instance.renderTo(window, container?) // Supports only current window; throws for other windows
|
|
836
904
|
await instance.close() // Close and destroy
|
|
837
905
|
await instance.focus() // Focus
|
|
838
906
|
await instance.resize({ width, height }) // Resize
|
|
839
907
|
await instance.show() // Show
|
|
840
908
|
await instance.hide() // Hide
|
|
841
|
-
await instance.updateProps(newProps) // Update props
|
|
909
|
+
await instance.updateProps(newProps) // Update props (normalized + validated)
|
|
842
910
|
instance.clone() // Clone with same props
|
|
843
911
|
instance.isEligible() // Check eligibility
|
|
844
912
|
|
|
@@ -881,7 +949,7 @@ import ForgeFrame, {
|
|
|
881
949
|
### Typing Host hostProps
|
|
882
950
|
|
|
883
951
|
```typescript
|
|
884
|
-
import { type HostProps } from 'forgeframe';
|
|
952
|
+
import ForgeFrame, { type HostProps } from 'forgeframe';
|
|
885
953
|
|
|
886
954
|
interface MyProps {
|
|
887
955
|
name: string;
|
|
@@ -894,6 +962,7 @@ declare global {
|
|
|
894
962
|
}
|
|
895
963
|
}
|
|
896
964
|
|
|
965
|
+
// Import the runtime in your host bundle so ForgeFrame can expose window.hostProps.
|
|
897
966
|
window.hostProps!.name;
|
|
898
967
|
window.hostProps!.onSubmit;
|
|
899
968
|
window.hostProps!.close;
|
|
@@ -904,16 +973,9 @@ window.hostProps!.resize;
|
|
|
904
973
|
|
|
905
974
|
## Browser Support
|
|
906
975
|
|
|
907
|
-
ForgeFrame
|
|
908
|
-
|
|
909
|
-
| Browser | Minimum Version |
|
|
910
|
-
|---------|-----------------|
|
|
911
|
-
| Chrome | 80+ |
|
|
912
|
-
| Firefox | 75+ |
|
|
913
|
-
| Safari | 14+ |
|
|
914
|
-
| Edge | 80+ |
|
|
976
|
+
ForgeFrame ships ES2022 output. Use modern evergreen browsers or transpile the package for older targets in your consumer build pipeline.
|
|
915
977
|
|
|
916
|
-
**Note:** Internet Explorer is not supported.
|
|
978
|
+
**Note:** Internet Explorer is not supported. If you require IE-era compatibility, use [Zoid](https://github.com/krakenjs/zoid).
|
|
917
979
|
|
|
918
980
|
---
|
|
919
981
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
|
-
*
|
|
3
|
+
* Internal source barrel for ForgeFrame communication primitives.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
* This
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* This file groups the postMessage protocol, function bridge, and messenger
|
|
7
|
+
* internals for source organization. The published package does not expose a
|
|
8
|
+
* `forgeframe/communication` subpath, so consumers should treat this barrel as
|
|
9
|
+
* internal implementation structure.
|
|
9
10
|
*/
|
|
10
11
|
export { Messenger, type MessageHandler } from './messenger';
|
|
11
12
|
export { FunctionBridge, serializeFunctions, deserializeFunctions, } from './bridge';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Consumer callback helper module.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Centralizes consumer-side prop callback invocation and error dispatch so the
|
|
7
|
+
* main consumer component can stay focused on lifecycle orchestration.
|
|
8
|
+
*/
|
|
9
|
+
import type { EventEmitter } from '../../events/emitter';
|
|
10
|
+
/**
|
|
11
|
+
* Calls a prop callback if it exists while isolating sync and async failures.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function invokePropCallback(props: Record<string, unknown>, name: string, ...args: unknown[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* Emits a consumer error event and forwards it to the `onError` prop callback.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function emitConsumerError(event: EventEmitter, props: Record<string, unknown>, error: Error): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Consumer child-reference helper module.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Converts nested consumer child definitions into the serializable host
|
|
7
|
+
* component references included in the consumer window payload.
|
|
8
|
+
*/
|
|
9
|
+
import type { HostComponentRef } from '../../types';
|
|
10
|
+
import type { NormalizedOptions } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* Builds component references for nested host components.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildNestedHostRefs<P extends Record<string, unknown>>(options: Pick<NormalizedOptions<P>, 'children'>, props: P): Record<string, HostComponentRef> | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Consumer sibling lookup helper module.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Encapsulates the indexed-instance queries used to answer host requests for
|
|
7
|
+
* sibling consumer instances without keeping that logic inside the façade.
|
|
8
|
+
*/
|
|
9
|
+
import type { GetPeerInstancesOptions, SiblingInfo } from '../../types';
|
|
10
|
+
/**
|
|
11
|
+
* Request shape used for consumer sibling lookups.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export interface ConsumerSiblingRequest {
|
|
15
|
+
uid: string;
|
|
16
|
+
tag: string;
|
|
17
|
+
options?: GetPeerInstancesOptions;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns sibling component instances for a host peer lookup.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function getSiblingInstances(request: ConsumerSiblingRequest): SiblingInfo[];
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Consumer transport subsystem module.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Owns consumer-side messaging, function bridging, trust management, and host
|
|
7
|
+
* handshake concerns for embedded iframe and popup instances.
|
|
8
|
+
*/
|
|
9
|
+
import type { ConsumerExports, Dimensions, HostComponentRef, PropsDefinition, SerializedProps, SiblingInfo } from '../../types';
|
|
2
10
|
import { Messenger } from '../../communication/messenger';
|
|
3
11
|
import { FunctionBridge } from '../../communication/bridge';
|
|
4
12
|
import { createDeferred } from '../../utils/promise';
|
|
5
13
|
import type { ContextType } from '../../constants';
|
|
14
|
+
import type { ConsumerSiblingRequest } from './siblings';
|
|
6
15
|
import type { NormalizedOptions } from './types';
|
|
7
|
-
interface PeerRequest {
|
|
8
|
-
uid: string;
|
|
9
|
-
tag: string;
|
|
10
|
-
options?: GetPeerInstancesOptions;
|
|
11
|
-
}
|
|
12
16
|
/**
|
|
13
17
|
* Callbacks used by transport to map inbound host messages to component behavior.
|
|
14
18
|
* @internal
|
|
@@ -23,7 +27,7 @@ export interface ConsumerTransportHandlers<X> {
|
|
|
23
27
|
onError: (error: Error) => void;
|
|
24
28
|
onExport: (exports: X) => void;
|
|
25
29
|
onConsumerExport: (data: unknown) => void;
|
|
26
|
-
onGetSiblings: (request:
|
|
30
|
+
onGetSiblings: (request: ConsumerSiblingRequest) => SiblingInfo[] | Promise<SiblingInfo[]>;
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Owns consumer transport concerns (messenger, function bridge, trust management, handshake).
|
|
@@ -108,4 +112,3 @@ export declare class ConsumerTransport<P extends Record<string, unknown>, X = un
|
|
|
108
112
|
*/
|
|
109
113
|
destroy(): void;
|
|
110
114
|
}
|
|
111
|
-
export {};
|
package/dist/core/consumer.d.ts
CHANGED
|
@@ -60,54 +60,6 @@ export declare class ConsumerComponent<P extends Record<string, unknown>, X = un
|
|
|
60
60
|
private destroyed;
|
|
61
61
|
/** @internal */
|
|
62
62
|
private closing;
|
|
63
|
-
/** @internal */
|
|
64
|
-
private get props();
|
|
65
|
-
/** @internal */
|
|
66
|
-
private set props(value);
|
|
67
|
-
/** @internal */
|
|
68
|
-
private get inputProps();
|
|
69
|
-
/** @internal */
|
|
70
|
-
private set inputProps(value);
|
|
71
|
-
/** @internal */
|
|
72
|
-
private get pendingPropsUpdate();
|
|
73
|
-
/** @internal */
|
|
74
|
-
private set pendingPropsUpdate(value);
|
|
75
|
-
/** @internal */
|
|
76
|
-
private get context();
|
|
77
|
-
/** @internal */
|
|
78
|
-
private set context(value);
|
|
79
|
-
/** @internal */
|
|
80
|
-
private get hostWindow();
|
|
81
|
-
/** @internal */
|
|
82
|
-
private set hostWindow(value);
|
|
83
|
-
/** @internal */
|
|
84
|
-
private get openedHostDomain();
|
|
85
|
-
/** @internal */
|
|
86
|
-
private set openedHostDomain(value);
|
|
87
|
-
/** @internal */
|
|
88
|
-
private get dynamicUrlTrustedOrigin();
|
|
89
|
-
/** @internal */
|
|
90
|
-
private set dynamicUrlTrustedOrigin(value);
|
|
91
|
-
/** @internal */
|
|
92
|
-
private get iframe();
|
|
93
|
-
/** @internal */
|
|
94
|
-
private set iframe(value);
|
|
95
|
-
/** @internal */
|
|
96
|
-
private get container();
|
|
97
|
-
/** @internal */
|
|
98
|
-
private set container(value);
|
|
99
|
-
/** @internal */
|
|
100
|
-
private get initPromise();
|
|
101
|
-
/** @internal */
|
|
102
|
-
private set initPromise(value);
|
|
103
|
-
/** @internal */
|
|
104
|
-
private get hostInitialized();
|
|
105
|
-
/** @internal */
|
|
106
|
-
private set hostInitialized(value);
|
|
107
|
-
/** @internal */
|
|
108
|
-
private get messenger();
|
|
109
|
-
/** @internal */
|
|
110
|
-
private get bridge();
|
|
111
63
|
/**
|
|
112
64
|
* Creates a new ConsumerComponent instance.
|
|
113
65
|
*
|
|
@@ -204,11 +156,6 @@ export declare class ConsumerComponent<P extends Record<string, unknown>, X = un
|
|
|
204
156
|
* @internal
|
|
205
157
|
*/
|
|
206
158
|
private sendPropsUpdateToHost;
|
|
207
|
-
/**
|
|
208
|
-
* Emits prop update lifecycle hooks.
|
|
209
|
-
* @internal
|
|
210
|
-
*/
|
|
211
|
-
private emitPropsUpdated;
|
|
212
159
|
/**
|
|
213
160
|
* Creates a clone of this instance with the same props.
|
|
214
161
|
*
|
|
@@ -302,11 +249,6 @@ export declare class ConsumerComponent<P extends Record<string, unknown>, X = un
|
|
|
302
249
|
* @internal
|
|
303
250
|
*/
|
|
304
251
|
private buildWindowName;
|
|
305
|
-
/**
|
|
306
|
-
* Builds component references for nested host components.
|
|
307
|
-
* @internal
|
|
308
|
-
*/
|
|
309
|
-
private buildNestedHostRefs;
|
|
310
252
|
/**
|
|
311
253
|
* Creates the exports object sent to the host.
|
|
312
254
|
* @internal
|
|
@@ -337,26 +279,11 @@ export declare class ConsumerComponent<P extends Record<string, unknown>, X = un
|
|
|
337
279
|
* @internal
|
|
338
280
|
*/
|
|
339
281
|
private hasSameDomainPropDefinition;
|
|
340
|
-
/**
|
|
341
|
-
* Gets sibling component instances for a request.
|
|
342
|
-
* @internal
|
|
343
|
-
*/
|
|
344
|
-
private getSiblingInstances;
|
|
345
282
|
/**
|
|
346
283
|
* Registers cleanup handlers for the instance.
|
|
347
284
|
* @internal
|
|
348
285
|
*/
|
|
349
286
|
private setupCleanup;
|
|
350
|
-
/**
|
|
351
|
-
* Handles errors by emitting events and calling callbacks.
|
|
352
|
-
* @internal
|
|
353
|
-
*/
|
|
354
|
-
private handleError;
|
|
355
|
-
/**
|
|
356
|
-
* Calls a prop callback if it exists.
|
|
357
|
-
* @internal
|
|
358
|
-
*/
|
|
359
|
-
private callPropCallback;
|
|
360
287
|
/**
|
|
361
288
|
* Destroys the component and cleans up all resources.
|
|
362
289
|
* @internal
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Internal root-entrypoint host pre-initialization helper.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Keeps root import-time host setup colocated with the host bootstrap
|
|
7
|
+
* internals instead of mixing it into the public package entrypoint.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Pre-initializes host state when the public root entrypoint is imported in a
|
|
11
|
+
* browser window.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* INIT remains deferred until `initHost()` is explicitly flushed or a host
|
|
15
|
+
* component definition does so.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function preinitHostOnImport(): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Host bootstrap and singleton lifecycle helpers.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This internal module owns host instance creation, singleton reuse, deferred
|
|
7
|
+
* init flushing decisions, and cleanup for `initHost()`/`clearHostInstance()`.
|
|
8
|
+
*/
|
|
9
|
+
import type { DomainMatcher, PropsDefinition } from '../../types';
|
|
10
|
+
import { HostComponent } from './component';
|
|
11
|
+
export declare function initHost<P extends Record<string, unknown>>(propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher, options?: {
|
|
12
|
+
deferInit?: boolean;
|
|
13
|
+
}): HostComponent<P> | null;
|
|
14
|
+
export declare function getHost<P extends Record<string, unknown>>(): HostComponent<P> | null;
|
|
15
|
+
export declare function clearHostInstance(): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Host runtime coordinator.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This internal module keeps `HostComponent` focused on orchestration. It wires
|
|
7
|
+
* together security checks, message transport, and host props state while
|
|
8
|
+
* preserving the public host runtime surface exported from `src/core/host.ts`.
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from '../../events/emitter';
|
|
11
|
+
import type { DomainMatcher, HostProps, PropsDefinition, WindowNamePayload } from '../../types';
|
|
12
|
+
export declare class HostComponent<P extends Record<string, unknown>> {
|
|
13
|
+
event: EventEmitter;
|
|
14
|
+
private uid;
|
|
15
|
+
private tag;
|
|
16
|
+
private consumerWindow;
|
|
17
|
+
private consumerDomain;
|
|
18
|
+
private consumerDomainVerified;
|
|
19
|
+
private allowedConsumerDomains?;
|
|
20
|
+
private transport;
|
|
21
|
+
private propsRuntime;
|
|
22
|
+
private destroyed;
|
|
23
|
+
constructor(payload: WindowNamePayload<P>, propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher, deferInit?: boolean);
|
|
24
|
+
get hostProps(): HostProps<P>;
|
|
25
|
+
set hostProps(value: HostProps<P>);
|
|
26
|
+
flushInit(): void;
|
|
27
|
+
getProps(): HostProps<P>;
|
|
28
|
+
getInitError(): Error | null;
|
|
29
|
+
applyHostConfiguration(propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher): void;
|
|
30
|
+
assertAllowedConsumerDomain(allowedConsumerDomains: DomainMatcher): void;
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Host props state and reconciliation helpers.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This internal module owns `hostProps` construction, reserved key filtering,
|
|
7
|
+
* bootstrap validation, live prop reconciliation, nested child creation, and
|
|
8
|
+
* `window.hostProps` exposure behavior.
|
|
9
|
+
*/
|
|
10
|
+
import type { HostProps, PropsDefinition, SerializedProps, WindowNamePayload } from '../../types';
|
|
11
|
+
import type { HostPropsRuntimeOptions } from './types';
|
|
12
|
+
export declare class HostPropsRuntime<P extends Record<string, unknown>> {
|
|
13
|
+
private propDefinitions;
|
|
14
|
+
private options;
|
|
15
|
+
hostProps: HostProps<P>;
|
|
16
|
+
consumerProps: P;
|
|
17
|
+
propsHandlers: Set<(props: P) => void>;
|
|
18
|
+
constructor(propDefinitions: PropsDefinition<P> | undefined, options: HostPropsRuntimeOptions);
|
|
19
|
+
initializeHostProps(payload: WindowNamePayload<P>): HostProps<P>;
|
|
20
|
+
exposeHostProps(): void;
|
|
21
|
+
applyHostConfiguration(propDefinitions: PropsDefinition<P>): void;
|
|
22
|
+
applySerializedProps(serializedProps: SerializedProps): {
|
|
23
|
+
success: true;
|
|
24
|
+
};
|
|
25
|
+
destroy(): void;
|
|
26
|
+
private onProps;
|
|
27
|
+
private deserialize;
|
|
28
|
+
private getBootstrapValidationDefinitions;
|
|
29
|
+
private buildNestedComponents;
|
|
30
|
+
private removeStaleHostProps;
|
|
31
|
+
}
|