forgeframe 0.0.1 → 0.0.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 +18 -4
- package/dist/communication/messenger.d.ts +6 -0
- package/dist/core/component.d.ts +5 -0
- package/dist/core/consumer.d.ts +29 -0
- package/dist/core/host.d.ts +43 -3
- package/dist/forgeframe.js +787 -628
- package/dist/forgeframe.umd.cjs +2 -2
- package/dist/index.d.ts +13 -2
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ await payment.render('#payment-container');
|
|
|
108
108
|
> **`Host`**
|
|
109
109
|
|
|
110
110
|
```typescript
|
|
111
|
-
import { type HostProps } from 'forgeframe';
|
|
111
|
+
import ForgeFrame, { type HostProps } from 'forgeframe';
|
|
112
112
|
|
|
113
113
|
interface PaymentProps {
|
|
114
114
|
amount: number;
|
|
@@ -121,6 +121,10 @@ declare global {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
// Required when the host page doesn't use ForgeFrame.create().
|
|
125
|
+
// If your host defines a component via create(), init is handled automatically.
|
|
126
|
+
ForgeFrame.initHost();
|
|
127
|
+
|
|
124
128
|
const { amount, onSuccess, close } = window.hostProps;
|
|
125
129
|
|
|
126
130
|
document.getElementById('total')!.textContent = `$${amount}`;
|
|
@@ -180,7 +184,7 @@ const LoginForm = ForgeFrame.create<LoginProps>({
|
|
|
180
184
|
The host page runs inside the iframe at the URL you specified. It receives props via `window.hostProps`.
|
|
181
185
|
|
|
182
186
|
```typescript
|
|
183
|
-
import { type HostProps } from 'forgeframe';
|
|
187
|
+
import ForgeFrame, { type HostProps } from 'forgeframe';
|
|
184
188
|
|
|
185
189
|
interface LoginProps {
|
|
186
190
|
email?: string;
|
|
@@ -194,6 +198,10 @@ declare global {
|
|
|
194
198
|
}
|
|
195
199
|
}
|
|
196
200
|
|
|
201
|
+
// Required when the host page doesn't use ForgeFrame.create().
|
|
202
|
+
// If your host defines a component via create(), init is handled automatically.
|
|
203
|
+
ForgeFrame.initHost();
|
|
204
|
+
|
|
197
205
|
const { email, onLogin, onCancel, close } = window.hostProps;
|
|
198
206
|
|
|
199
207
|
if (email) document.getElementById('email')!.value = email;
|
|
@@ -218,7 +226,8 @@ document.getElementById('cancel')!.onclick = async () => {
|
|
|
218
226
|
<summary>Explanation</summary>
|
|
219
227
|
|
|
220
228
|
- **`HostProps<LoginProps>`**: Combines your props with built-in methods (`close`, `resize`, etc.)
|
|
221
|
-
- **`
|
|
229
|
+
- **`ForgeFrame.initHost()`**: Flushes host initialization so the consumer can complete render. Only required when the host page doesn't use `ForgeFrame.create()` — if your host defines a component via `create()`, init is handled automatically.
|
|
230
|
+
- **`window.hostProps`**: Contains all props passed from the consumer plus built-in methods
|
|
222
231
|
- **`close()`**: Built-in method to close the iframe/popup
|
|
223
232
|
|
|
224
233
|
</details>
|
|
@@ -404,7 +413,7 @@ In host windows, `window.hostProps` provides access to props and control methods
|
|
|
404
413
|
### TypeScript Setup
|
|
405
414
|
|
|
406
415
|
```typescript
|
|
407
|
-
import { type HostProps } from 'forgeframe';
|
|
416
|
+
import ForgeFrame, { type HostProps } from 'forgeframe';
|
|
408
417
|
|
|
409
418
|
interface MyProps {
|
|
410
419
|
email: string;
|
|
@@ -417,6 +426,10 @@ declare global {
|
|
|
417
426
|
}
|
|
418
427
|
}
|
|
419
428
|
|
|
429
|
+
// Required when the host page doesn't use ForgeFrame.create().
|
|
430
|
+
// If your host defines a component via create(), init is handled automatically.
|
|
431
|
+
ForgeFrame.initHost();
|
|
432
|
+
|
|
420
433
|
const { email, onLogin, close, resize } = window.hostProps!;
|
|
421
434
|
```
|
|
422
435
|
|
|
@@ -740,6 +753,7 @@ ForgeFrame.destroyByTag(tag) // Destroy all instances of a tag
|
|
|
740
753
|
ForgeFrame.destroyAll() // Destroy all instances
|
|
741
754
|
ForgeFrame.isHost() // Check if in host context
|
|
742
755
|
ForgeFrame.isEmbedded() // Alias for isHost() - more intuitive naming
|
|
756
|
+
ForgeFrame.initHost() // Flush host handshake (only needed when create() is not used on the host)
|
|
743
757
|
ForgeFrame.getHostProps() // Get hostProps in host context
|
|
744
758
|
ForgeFrame.isStandardSchema(val) // Check if value is a Standard Schema
|
|
745
759
|
|
|
@@ -72,6 +72,12 @@ export declare class Messenger {
|
|
|
72
72
|
* @param domain - Domain pattern to trust (string, RegExp, or array)
|
|
73
73
|
*/
|
|
74
74
|
addTrustedDomain(domain: DomainMatcher): void;
|
|
75
|
+
/**
|
|
76
|
+
* Removes a trusted domain from this messenger.
|
|
77
|
+
*
|
|
78
|
+
* @param domain - Domain pattern to remove (string, RegExp, or array)
|
|
79
|
+
*/
|
|
80
|
+
removeTrustedDomain(domain: DomainMatcher): void;
|
|
75
81
|
/**
|
|
76
82
|
* Checks if an origin is trusted.
|
|
77
83
|
*
|
package/dist/core/component.d.ts
CHANGED
|
@@ -60,6 +60,11 @@ export declare function create<P extends Record<string, unknown> = Record<string
|
|
|
60
60
|
* @public
|
|
61
61
|
*/
|
|
62
62
|
export declare function getComponent<P extends Record<string, unknown> = Record<string, unknown>, X = unknown>(tag: string): ForgeFrameComponent<P, X> | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the internal options metadata for a component factory.
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export declare function getComponentOptions<P extends Record<string, unknown> = Record<string, unknown>, X = unknown>(component: ForgeFrameComponent<P, X>): ComponentOptions<P> | undefined;
|
|
63
68
|
/**
|
|
64
69
|
* Destroys a single component instance.
|
|
65
70
|
*
|
package/dist/core/consumer.d.ts
CHANGED
|
@@ -60,6 +60,10 @@ export declare class ConsumerComponent<P extends Record<string, unknown>, X = un
|
|
|
60
60
|
/** @internal */
|
|
61
61
|
private hostWindow;
|
|
62
62
|
/** @internal */
|
|
63
|
+
private openedHostDomain;
|
|
64
|
+
/** @internal */
|
|
65
|
+
private dynamicUrlTrustedOrigin;
|
|
66
|
+
/** @internal */
|
|
63
67
|
private iframe;
|
|
64
68
|
/** @internal */
|
|
65
69
|
private container;
|
|
@@ -174,6 +178,31 @@ export declare class ConsumerComponent<P extends Record<string, unknown>, X = un
|
|
|
174
178
|
* @internal
|
|
175
179
|
*/
|
|
176
180
|
private normalizeOptions;
|
|
181
|
+
/**
|
|
182
|
+
* Resolves the host URL from static or function options.
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
private resolveUrl;
|
|
186
|
+
/**
|
|
187
|
+
* Resolves dimensions from static or function options.
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
private resolveDimensions;
|
|
191
|
+
/**
|
|
192
|
+
* Resolves a URL to an origin, supporting relative URLs.
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
195
|
+
private resolveUrlOrigin;
|
|
196
|
+
/**
|
|
197
|
+
* Returns true when the domain option explicitly includes this origin.
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
private isExplicitDomainTrust;
|
|
201
|
+
/**
|
|
202
|
+
* Ensures the messenger trusts the origin for a resolved host URL.
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
205
|
+
private syncTrustedDomainForUrl;
|
|
177
206
|
/**
|
|
178
207
|
* Creates the prop context passed to prop callbacks and validators.
|
|
179
208
|
* @internal
|
package/dist/core/host.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* or popup and handles communication with the consumer window. It also provides
|
|
8
8
|
* utilities for detecting host context and accessing hostProps.
|
|
9
9
|
*/
|
|
10
|
-
import type { HostProps, WindowNamePayload, PropsDefinition } from '../types';
|
|
10
|
+
import type { HostProps, WindowNamePayload, PropsDefinition, DomainMatcher } from '../types';
|
|
11
11
|
import { EventEmitter } from '../events/emitter';
|
|
12
12
|
/**
|
|
13
13
|
* Host-side component implementation.
|
|
@@ -32,6 +32,8 @@ import { EventEmitter } from '../events/emitter';
|
|
|
32
32
|
*/
|
|
33
33
|
export declare class HostComponent<P extends Record<string, unknown>> {
|
|
34
34
|
private propDefinitions;
|
|
35
|
+
private allowedConsumerDomains?;
|
|
36
|
+
private deferInit;
|
|
35
37
|
/** The hostProps object containing props and control methods passed from the consumer. */
|
|
36
38
|
hostProps: HostProps<P>;
|
|
37
39
|
/** Event emitter for lifecycle events. */
|
|
@@ -54,13 +56,43 @@ export declare class HostComponent<P extends Record<string, unknown>> {
|
|
|
54
56
|
private consumerProps;
|
|
55
57
|
/** @internal */
|
|
56
58
|
private initError;
|
|
59
|
+
/** @internal */
|
|
60
|
+
private destroyed;
|
|
61
|
+
/** @internal */
|
|
62
|
+
private initSent;
|
|
63
|
+
/** @internal */
|
|
64
|
+
private deferredInitFlushScheduled;
|
|
57
65
|
/**
|
|
58
66
|
* Creates a new HostComponent instance.
|
|
59
67
|
*
|
|
60
68
|
* @param payload - The payload parsed from window.name
|
|
61
69
|
* @param propDefinitions - Optional prop definitions for deserialization
|
|
70
|
+
* @param allowedConsumerDomains - Optional allowlist of consumer domains
|
|
71
|
+
* @param deferInit - Whether to defer INIT until a later explicit flush
|
|
72
|
+
*/
|
|
73
|
+
constructor(payload: WindowNamePayload<P>, propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher | undefined, deferInit?: boolean);
|
|
74
|
+
/**
|
|
75
|
+
* Ensures the INIT handshake is sent at most once.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
flushInit(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Schedules deferred INIT flush on the next microtask.
|
|
81
|
+
* This preserves legacy hostProps-only usage while giving same-tick
|
|
82
|
+
* host configuration a chance to run allowlist checks first.
|
|
83
|
+
* @internal
|
|
62
84
|
*/
|
|
63
|
-
|
|
85
|
+
private scheduleDeferredInitFlush;
|
|
86
|
+
/**
|
|
87
|
+
* Exposes hostProps on window and lazily flushes deferred init on first access.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
private exposeHostProps;
|
|
91
|
+
/**
|
|
92
|
+
* Validates that the consumer domain is allowed.
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
private validateConsumerDomain;
|
|
64
96
|
/**
|
|
65
97
|
* Returns the hostProps object.
|
|
66
98
|
*
|
|
@@ -176,7 +208,9 @@ export declare class HostComponent<P extends Record<string, unknown>> {
|
|
|
176
208
|
*
|
|
177
209
|
* @public
|
|
178
210
|
*/
|
|
179
|
-
export declare function initHost<P extends Record<string, unknown>>(propDefinitions?: PropsDefinition<P
|
|
211
|
+
export declare function initHost<P extends Record<string, unknown>>(propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher, options?: {
|
|
212
|
+
deferInit?: boolean;
|
|
213
|
+
}): HostComponent<P> | null;
|
|
180
214
|
/**
|
|
181
215
|
* Gets the current host component instance.
|
|
182
216
|
*
|
|
@@ -247,3 +281,9 @@ export declare function isEmbedded(): boolean;
|
|
|
247
281
|
* @public
|
|
248
282
|
*/
|
|
249
283
|
export declare function getHostProps<P extends Record<string, unknown>>(): HostProps<P> | undefined;
|
|
284
|
+
/**
|
|
285
|
+
* Clears and destroys the global host instance.
|
|
286
|
+
* Primarily intended for testing.
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
export declare function clearHostInstance(): void;
|