@kadanza/extension-sdk 0.0.13 → 0.1.0
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 +2 -1
- package/dist/extension-sdk.cjs +1 -1
- package/dist/extension-sdk.cjs.map +1 -1
- package/dist/extension-sdk.js +200 -73
- package/dist/extension-sdk.js.map +1 -1
- package/dist/index.d.cts +169 -25
- package/dist/index.d.ts +169 -25
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -78,24 +78,56 @@ export declare interface ConnectOptions {
|
|
|
78
78
|
*/
|
|
79
79
|
export declare const createExtensionSDK: () => IExtensionSDK;
|
|
80
80
|
|
|
81
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Tenant branding from the parent, for aligning extension UI with the host.
|
|
83
|
+
*
|
|
84
|
+
* The host should send this whenever a tenant is in context (Experience Pages
|
|
85
|
+
* and Admin Console). Handshake still succeeds if it is omitted — treat every
|
|
86
|
+
* field as optional.
|
|
87
|
+
*
|
|
88
|
+
* - `primaryColor` — tenant palette primary; accents, buttons, links
|
|
89
|
+
* - `fontFamily` — tenant font family; body and UI type
|
|
90
|
+
* - `borderRadius` — tenant roundness; controls and cards
|
|
91
|
+
*
|
|
92
|
+
* Values may be missing when the tenant has no setting configured.
|
|
93
|
+
*/
|
|
82
94
|
export declare interface DesignTokens {
|
|
83
|
-
primaryColor
|
|
84
|
-
fontFamily
|
|
85
|
-
borderRadius
|
|
95
|
+
primaryColor?: string;
|
|
96
|
+
fontFamily?: string;
|
|
97
|
+
borderRadius?: string;
|
|
86
98
|
}
|
|
87
99
|
|
|
88
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Clones `urlRaw` and sets the `tenantUrl` search param (parent origin).
|
|
102
|
+
*
|
|
103
|
+
* @param urlRaw - Absolute extension URL string.
|
|
104
|
+
* @param tenantUrl - Parent origin to embed (defaults to `window.location.origin`).
|
|
105
|
+
* @returns Enriched `URL`, or `null` when `urlRaw` is missing or unparsable.
|
|
106
|
+
*/
|
|
107
|
+
export declare function enrichExtensionUrl(urlRaw: string | null | undefined, tenantUrl?: string): URL | null;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Host context from handshake. Only set when the parent includes it.
|
|
111
|
+
*
|
|
112
|
+
* Field availability depends on where the iframe is mounted:
|
|
113
|
+
* - Experience Pages typically send `spaceId` and `pageId`.
|
|
114
|
+
* - Admin Console Pages typically omit those — there is no space page.
|
|
115
|
+
*
|
|
116
|
+
* Other identity fields are sent when the host knows them. Handshake does not
|
|
117
|
+
* require this object.
|
|
118
|
+
*/
|
|
89
119
|
export declare interface ExtensionDetails {
|
|
90
|
-
extensionId
|
|
91
|
-
tenantId
|
|
92
|
-
tenantDomain
|
|
93
|
-
/** Base URL of the parent application. */
|
|
94
|
-
baseUrl
|
|
95
|
-
|
|
96
|
-
|
|
120
|
+
extensionId?: string;
|
|
121
|
+
tenantId?: string;
|
|
122
|
+
tenantDomain?: string;
|
|
123
|
+
/** Base URL of the parent application (used to derive the Platform API origin). */
|
|
124
|
+
baseUrl?: string;
|
|
125
|
+
/** Space that owns the Experience Page. Omitted in Admin Console. */
|
|
126
|
+
spaceId?: string;
|
|
127
|
+
/** Experience Page id. Omitted in Admin Console. */
|
|
128
|
+
pageId?: string;
|
|
97
129
|
/** BCP 47 locale from the parent. */
|
|
98
|
-
locale
|
|
130
|
+
locale?: string;
|
|
99
131
|
}
|
|
100
132
|
|
|
101
133
|
/** Envelope for parent/child `postMessage` traffic. */
|
|
@@ -125,14 +157,59 @@ export declare class ExtensionSDK implements IExtensionSDK {
|
|
|
125
157
|
emitNavigationChange(payload: NavigationChangePayload): void;
|
|
126
158
|
}
|
|
127
159
|
|
|
128
|
-
/**
|
|
160
|
+
/** Default {@link IExtensionSDKHost} implementation. */
|
|
161
|
+
export declare class ExtensionSDKHost implements IExtensionSDKHost {
|
|
162
|
+
#private;
|
|
163
|
+
constructor(options: ExtensionSDKHostOptions);
|
|
164
|
+
start(): void;
|
|
165
|
+
destroy(): void;
|
|
166
|
+
emitLoadPageSettings(settings: PageSettings | null): void;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Options for {@link ExtensionSDKHost}.
|
|
171
|
+
*
|
|
172
|
+
* Platform code supplies token minting and page-settings persistence via
|
|
173
|
+
* callbacks; the host owns only the postMessage protocol.
|
|
174
|
+
*/
|
|
175
|
+
export declare interface ExtensionSDKHostOptions {
|
|
176
|
+
/** Returns the iframe `contentWindow`, or `null` if not ready. */
|
|
177
|
+
getContentWindow: () => Window | null;
|
|
178
|
+
/** Extension origin used as `postMessage` targetOrigin / source filter. */
|
|
179
|
+
origin: string;
|
|
180
|
+
/**
|
|
181
|
+
* Builds the handshake payload when the child sends `HANDSHAKE_INIT`.
|
|
182
|
+
* Context fields are optional; send `designTokens` whenever a tenant is in
|
|
183
|
+
* context. `spaceId` / `pageId` apply to Experience Pages only.
|
|
184
|
+
*/
|
|
185
|
+
resolveHandshakePayload: () => Partial<HandshakePayload> | Promise<Partial<HandshakePayload>>;
|
|
186
|
+
/**
|
|
187
|
+
* Resolves a fresh auth token when the child sends `REQUEST_TOKEN_REFRESH`.
|
|
188
|
+
*/
|
|
189
|
+
resolveAuthToken: () => AuthToken | Promise<AuthToken>;
|
|
190
|
+
/**
|
|
191
|
+
* Persists page settings from `UPDATE_PAGE_SETTINGS`.
|
|
192
|
+
* Return `true` on success; the host emits `PAGE_SETTINGS_UPDATED`.
|
|
193
|
+
*/
|
|
194
|
+
onUpdatePageSettings?: (settings: PageSettings) => boolean | Promise<boolean>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Context delivered with `HANDSHAKE_ACK`.
|
|
199
|
+
*
|
|
200
|
+
* Handshake completes as soon as the parent ACKs. Every property is optional
|
|
201
|
+
* and only populated when that host surface provides it. After `connect()`,
|
|
202
|
+
* omitted wire fields are normalized to `null`.
|
|
203
|
+
*/
|
|
129
204
|
export declare interface HandshakePayload {
|
|
130
|
-
authToken: AuthToken;
|
|
131
|
-
extensionDetails: ExtensionDetails;
|
|
132
|
-
designTokens: DesignTokens;
|
|
205
|
+
authToken: AuthToken | null;
|
|
206
|
+
extensionDetails: ExtensionDetails | null;
|
|
207
|
+
designTokens: DesignTokens | null;
|
|
133
208
|
pageSettings: PageSettings | null;
|
|
134
209
|
}
|
|
135
210
|
|
|
211
|
+
export declare type HostMessageHandler = (event: MessageEvent<ExtensionMessage>) => void;
|
|
212
|
+
|
|
136
213
|
/**
|
|
137
214
|
* Public contract for talking to the Kadanza parent frame over `postMessage`.
|
|
138
215
|
*
|
|
@@ -153,10 +230,16 @@ export declare interface IExtensionSDK {
|
|
|
153
230
|
* Opt-in proactive refresh can be enabled with
|
|
154
231
|
* `authTokenAutoRefresh: true` (optional `authTokenBufferMs`).
|
|
155
232
|
*
|
|
233
|
+
* Handshake completes when the parent sends `HANDSHAKE_ACK`. Context fields
|
|
234
|
+
* (`authToken`, `extensionDetails`, `designTokens`, `pageSettings`) are
|
|
235
|
+
* optional — omitted values are `null`. Use them only when the current host
|
|
236
|
+
* surface provides them (e.g. `spaceId` / `pageId` on Experience Pages,
|
|
237
|
+
* `designTokens` when a tenant is in context).
|
|
238
|
+
*
|
|
156
239
|
* @param options - Handshake timeout and optional auth-token auto-refresh.
|
|
157
240
|
* @throws {InvalidOriginError} When `tenantUrl` is missing or invalid.
|
|
158
241
|
* @throws When not embedded in a parent frame, destroyed, or the handshake
|
|
159
|
-
* times out
|
|
242
|
+
* times out.
|
|
160
243
|
*/
|
|
161
244
|
connect(options?: ConnectOptions): Promise<HandshakePayload>;
|
|
162
245
|
/**
|
|
@@ -168,11 +251,20 @@ export declare interface IExtensionSDK {
|
|
|
168
251
|
destroy(): void;
|
|
169
252
|
/** Whether a successful handshake has completed and not been destroyed. */
|
|
170
253
|
readonly isConnected: boolean;
|
|
171
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* Last auth token from handshake or refresh.
|
|
256
|
+
* `null` until connected, or when the host omitted it.
|
|
257
|
+
*/
|
|
172
258
|
getAuthToken(): AuthToken | null;
|
|
173
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* Extension context from handshake.
|
|
261
|
+
* `null` until connected, or when the host omitted it.
|
|
262
|
+
*/
|
|
174
263
|
getExtensionDetails(): ExtensionDetails | null;
|
|
175
|
-
/**
|
|
264
|
+
/**
|
|
265
|
+
* Tenant branding from handshake.
|
|
266
|
+
* `null` until connected, or when the host omitted it.
|
|
267
|
+
*/
|
|
176
268
|
getDesignTokens(): DesignTokens | null;
|
|
177
269
|
/**
|
|
178
270
|
* Latest page settings from handshake or `LOAD_PAGE_SETTINGS`;
|
|
@@ -190,8 +282,8 @@ export declare interface IExtensionSDK {
|
|
|
190
282
|
*/
|
|
191
283
|
getTenantUrl(): string | null;
|
|
192
284
|
/**
|
|
193
|
-
* Platform API origin derived from handshake `baseUrl
|
|
194
|
-
* `null` until connected.
|
|
285
|
+
* Platform API origin derived from handshake `baseUrl`.
|
|
286
|
+
* `null` until connected, or when `extensionDetails.baseUrl` was omitted.
|
|
195
287
|
*/
|
|
196
288
|
getApiUrl(): string | null;
|
|
197
289
|
/**
|
|
@@ -203,8 +295,9 @@ export declare interface IExtensionSDK {
|
|
|
203
295
|
* @typeParam T - Expected JSON response body.
|
|
204
296
|
* @param endpoint - Root-relative API path.
|
|
205
297
|
* @param options - Standard fetch options.
|
|
206
|
-
* @throws When not connected,
|
|
207
|
-
*
|
|
298
|
+
* @throws When not connected, handshake did not include `authToken` and
|
|
299
|
+
* `extensionDetails` (`baseUrl`, `tenantDomain`), the endpoint is invalid,
|
|
300
|
+
* the request fails, or the response is not successful JSON.
|
|
208
301
|
*/
|
|
209
302
|
apiCall<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
210
303
|
/**
|
|
@@ -247,11 +340,43 @@ export declare interface IExtensionSDK {
|
|
|
247
340
|
emitNavigationChange(payload: NavigationChangePayload): void;
|
|
248
341
|
}
|
|
249
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Parent-frame counterpart to {@link IExtensionSDK}.
|
|
345
|
+
*
|
|
346
|
+
* Listens for child messages and replies with the shared wire protocol.
|
|
347
|
+
* Create one instance per iframe.
|
|
348
|
+
*/
|
|
349
|
+
export declare interface IExtensionSDKHost {
|
|
350
|
+
/**
|
|
351
|
+
* Attaches the child message listener. Safe to call once; no-ops if already
|
|
352
|
+
* started or destroyed.
|
|
353
|
+
*/
|
|
354
|
+
start(): void;
|
|
355
|
+
/**
|
|
356
|
+
* Tears down the listener. The instance cannot be restarted after destroy.
|
|
357
|
+
*/
|
|
358
|
+
destroy(): void;
|
|
359
|
+
/**
|
|
360
|
+
* Asks the child to open page settings UI with the given values.
|
|
361
|
+
*
|
|
362
|
+
* Wire: `LOAD_PAGE_SETTINGS` (fire-and-forget).
|
|
363
|
+
*/
|
|
364
|
+
emitLoadPageSettings(settings: PageSettings | null): void;
|
|
365
|
+
}
|
|
366
|
+
|
|
250
367
|
/** Thrown when `tenantUrl` is missing or not a safe postMessage origin. */
|
|
251
368
|
export declare class InvalidOriginError extends Error {
|
|
252
369
|
constructor(message: string);
|
|
253
370
|
}
|
|
254
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Returns whether `urlRaw` is a valid HTTPS extension URL.
|
|
374
|
+
*
|
|
375
|
+
* When `checkOrigin` is provided, the URL's origin must also pass that predicate
|
|
376
|
+
* (e.g. hostname ends with `.kadanza.app`).
|
|
377
|
+
*/
|
|
378
|
+
export declare function isValidExtensionUrl(urlRaw: string | null | undefined, checkOrigin?: (origin: string) => boolean): boolean;
|
|
379
|
+
|
|
255
380
|
/** Payload for `NAVIGATION_CHANGE` (child → parent). */
|
|
256
381
|
export declare interface NavigationChangePayload {
|
|
257
382
|
path: string;
|
|
@@ -265,6 +390,16 @@ export declare interface PageSettingsUpdatedPayload {
|
|
|
265
390
|
success: boolean;
|
|
266
391
|
}
|
|
267
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Posts a typed extension message to an embedded child frame.
|
|
395
|
+
*
|
|
396
|
+
* @param contentWindow - The iframe's `contentWindow`.
|
|
397
|
+
* @param origin - Target origin for `postMessage` (extension origin).
|
|
398
|
+
* @param type - Wire event type from {@link CONNECTION_EVENTS}.
|
|
399
|
+
* @param payload - Optional message payload.
|
|
400
|
+
*/
|
|
401
|
+
export declare function postToChild(contentWindow: Window, origin: string, type: ConnectionEvent, payload?: unknown): void;
|
|
402
|
+
|
|
268
403
|
/**
|
|
269
404
|
* Reads the parent-supplied `tenantUrl` from a URL search string.
|
|
270
405
|
*
|
|
@@ -291,6 +426,15 @@ export declare interface RequestOptions {
|
|
|
291
426
|
*/
|
|
292
427
|
export declare function resolveAllowedOrigin(tenantUrl: string | null): string;
|
|
293
428
|
|
|
429
|
+
/**
|
|
430
|
+
* Subscribes to `message` events from a child frame at `origin`.
|
|
431
|
+
*
|
|
432
|
+
* Ignores events from other origins and payloads without a `type` field.
|
|
433
|
+
*
|
|
434
|
+
* @returns Unsubscribe function.
|
|
435
|
+
*/
|
|
436
|
+
export declare function subscribeToChildMessages(origin: string, handler: HostMessageHandler): () => void;
|
|
437
|
+
|
|
294
438
|
/** Payload for `UPDATE_PAGE_SETTINGS` (child → parent). */
|
|
295
439
|
export declare interface UpdatePageSettingsPayload {
|
|
296
440
|
settings: PageSettings;
|
package/dist/index.d.ts
CHANGED
|
@@ -78,24 +78,56 @@ export declare interface ConnectOptions {
|
|
|
78
78
|
*/
|
|
79
79
|
export declare const createExtensionSDK: () => IExtensionSDK;
|
|
80
80
|
|
|
81
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Tenant branding from the parent, for aligning extension UI with the host.
|
|
83
|
+
*
|
|
84
|
+
* The host should send this whenever a tenant is in context (Experience Pages
|
|
85
|
+
* and Admin Console). Handshake still succeeds if it is omitted — treat every
|
|
86
|
+
* field as optional.
|
|
87
|
+
*
|
|
88
|
+
* - `primaryColor` — tenant palette primary; accents, buttons, links
|
|
89
|
+
* - `fontFamily` — tenant font family; body and UI type
|
|
90
|
+
* - `borderRadius` — tenant roundness; controls and cards
|
|
91
|
+
*
|
|
92
|
+
* Values may be missing when the tenant has no setting configured.
|
|
93
|
+
*/
|
|
82
94
|
export declare interface DesignTokens {
|
|
83
|
-
primaryColor
|
|
84
|
-
fontFamily
|
|
85
|
-
borderRadius
|
|
95
|
+
primaryColor?: string;
|
|
96
|
+
fontFamily?: string;
|
|
97
|
+
borderRadius?: string;
|
|
86
98
|
}
|
|
87
99
|
|
|
88
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Clones `urlRaw` and sets the `tenantUrl` search param (parent origin).
|
|
102
|
+
*
|
|
103
|
+
* @param urlRaw - Absolute extension URL string.
|
|
104
|
+
* @param tenantUrl - Parent origin to embed (defaults to `window.location.origin`).
|
|
105
|
+
* @returns Enriched `URL`, or `null` when `urlRaw` is missing or unparsable.
|
|
106
|
+
*/
|
|
107
|
+
export declare function enrichExtensionUrl(urlRaw: string | null | undefined, tenantUrl?: string): URL | null;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Host context from handshake. Only set when the parent includes it.
|
|
111
|
+
*
|
|
112
|
+
* Field availability depends on where the iframe is mounted:
|
|
113
|
+
* - Experience Pages typically send `spaceId` and `pageId`.
|
|
114
|
+
* - Admin Console Pages typically omit those — there is no space page.
|
|
115
|
+
*
|
|
116
|
+
* Other identity fields are sent when the host knows them. Handshake does not
|
|
117
|
+
* require this object.
|
|
118
|
+
*/
|
|
89
119
|
export declare interface ExtensionDetails {
|
|
90
|
-
extensionId
|
|
91
|
-
tenantId
|
|
92
|
-
tenantDomain
|
|
93
|
-
/** Base URL of the parent application. */
|
|
94
|
-
baseUrl
|
|
95
|
-
|
|
96
|
-
|
|
120
|
+
extensionId?: string;
|
|
121
|
+
tenantId?: string;
|
|
122
|
+
tenantDomain?: string;
|
|
123
|
+
/** Base URL of the parent application (used to derive the Platform API origin). */
|
|
124
|
+
baseUrl?: string;
|
|
125
|
+
/** Space that owns the Experience Page. Omitted in Admin Console. */
|
|
126
|
+
spaceId?: string;
|
|
127
|
+
/** Experience Page id. Omitted in Admin Console. */
|
|
128
|
+
pageId?: string;
|
|
97
129
|
/** BCP 47 locale from the parent. */
|
|
98
|
-
locale
|
|
130
|
+
locale?: string;
|
|
99
131
|
}
|
|
100
132
|
|
|
101
133
|
/** Envelope for parent/child `postMessage` traffic. */
|
|
@@ -125,14 +157,59 @@ export declare class ExtensionSDK implements IExtensionSDK {
|
|
|
125
157
|
emitNavigationChange(payload: NavigationChangePayload): void;
|
|
126
158
|
}
|
|
127
159
|
|
|
128
|
-
/**
|
|
160
|
+
/** Default {@link IExtensionSDKHost} implementation. */
|
|
161
|
+
export declare class ExtensionSDKHost implements IExtensionSDKHost {
|
|
162
|
+
#private;
|
|
163
|
+
constructor(options: ExtensionSDKHostOptions);
|
|
164
|
+
start(): void;
|
|
165
|
+
destroy(): void;
|
|
166
|
+
emitLoadPageSettings(settings: PageSettings | null): void;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Options for {@link ExtensionSDKHost}.
|
|
171
|
+
*
|
|
172
|
+
* Platform code supplies token minting and page-settings persistence via
|
|
173
|
+
* callbacks; the host owns only the postMessage protocol.
|
|
174
|
+
*/
|
|
175
|
+
export declare interface ExtensionSDKHostOptions {
|
|
176
|
+
/** Returns the iframe `contentWindow`, or `null` if not ready. */
|
|
177
|
+
getContentWindow: () => Window | null;
|
|
178
|
+
/** Extension origin used as `postMessage` targetOrigin / source filter. */
|
|
179
|
+
origin: string;
|
|
180
|
+
/**
|
|
181
|
+
* Builds the handshake payload when the child sends `HANDSHAKE_INIT`.
|
|
182
|
+
* Context fields are optional; send `designTokens` whenever a tenant is in
|
|
183
|
+
* context. `spaceId` / `pageId` apply to Experience Pages only.
|
|
184
|
+
*/
|
|
185
|
+
resolveHandshakePayload: () => Partial<HandshakePayload> | Promise<Partial<HandshakePayload>>;
|
|
186
|
+
/**
|
|
187
|
+
* Resolves a fresh auth token when the child sends `REQUEST_TOKEN_REFRESH`.
|
|
188
|
+
*/
|
|
189
|
+
resolveAuthToken: () => AuthToken | Promise<AuthToken>;
|
|
190
|
+
/**
|
|
191
|
+
* Persists page settings from `UPDATE_PAGE_SETTINGS`.
|
|
192
|
+
* Return `true` on success; the host emits `PAGE_SETTINGS_UPDATED`.
|
|
193
|
+
*/
|
|
194
|
+
onUpdatePageSettings?: (settings: PageSettings) => boolean | Promise<boolean>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Context delivered with `HANDSHAKE_ACK`.
|
|
199
|
+
*
|
|
200
|
+
* Handshake completes as soon as the parent ACKs. Every property is optional
|
|
201
|
+
* and only populated when that host surface provides it. After `connect()`,
|
|
202
|
+
* omitted wire fields are normalized to `null`.
|
|
203
|
+
*/
|
|
129
204
|
export declare interface HandshakePayload {
|
|
130
|
-
authToken: AuthToken;
|
|
131
|
-
extensionDetails: ExtensionDetails;
|
|
132
|
-
designTokens: DesignTokens;
|
|
205
|
+
authToken: AuthToken | null;
|
|
206
|
+
extensionDetails: ExtensionDetails | null;
|
|
207
|
+
designTokens: DesignTokens | null;
|
|
133
208
|
pageSettings: PageSettings | null;
|
|
134
209
|
}
|
|
135
210
|
|
|
211
|
+
export declare type HostMessageHandler = (event: MessageEvent<ExtensionMessage>) => void;
|
|
212
|
+
|
|
136
213
|
/**
|
|
137
214
|
* Public contract for talking to the Kadanza parent frame over `postMessage`.
|
|
138
215
|
*
|
|
@@ -153,10 +230,16 @@ export declare interface IExtensionSDK {
|
|
|
153
230
|
* Opt-in proactive refresh can be enabled with
|
|
154
231
|
* `authTokenAutoRefresh: true` (optional `authTokenBufferMs`).
|
|
155
232
|
*
|
|
233
|
+
* Handshake completes when the parent sends `HANDSHAKE_ACK`. Context fields
|
|
234
|
+
* (`authToken`, `extensionDetails`, `designTokens`, `pageSettings`) are
|
|
235
|
+
* optional — omitted values are `null`. Use them only when the current host
|
|
236
|
+
* surface provides them (e.g. `spaceId` / `pageId` on Experience Pages,
|
|
237
|
+
* `designTokens` when a tenant is in context).
|
|
238
|
+
*
|
|
156
239
|
* @param options - Handshake timeout and optional auth-token auto-refresh.
|
|
157
240
|
* @throws {InvalidOriginError} When `tenantUrl` is missing or invalid.
|
|
158
241
|
* @throws When not embedded in a parent frame, destroyed, or the handshake
|
|
159
|
-
* times out
|
|
242
|
+
* times out.
|
|
160
243
|
*/
|
|
161
244
|
connect(options?: ConnectOptions): Promise<HandshakePayload>;
|
|
162
245
|
/**
|
|
@@ -168,11 +251,20 @@ export declare interface IExtensionSDK {
|
|
|
168
251
|
destroy(): void;
|
|
169
252
|
/** Whether a successful handshake has completed and not been destroyed. */
|
|
170
253
|
readonly isConnected: boolean;
|
|
171
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* Last auth token from handshake or refresh.
|
|
256
|
+
* `null` until connected, or when the host omitted it.
|
|
257
|
+
*/
|
|
172
258
|
getAuthToken(): AuthToken | null;
|
|
173
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* Extension context from handshake.
|
|
261
|
+
* `null` until connected, or when the host omitted it.
|
|
262
|
+
*/
|
|
174
263
|
getExtensionDetails(): ExtensionDetails | null;
|
|
175
|
-
/**
|
|
264
|
+
/**
|
|
265
|
+
* Tenant branding from handshake.
|
|
266
|
+
* `null` until connected, or when the host omitted it.
|
|
267
|
+
*/
|
|
176
268
|
getDesignTokens(): DesignTokens | null;
|
|
177
269
|
/**
|
|
178
270
|
* Latest page settings from handshake or `LOAD_PAGE_SETTINGS`;
|
|
@@ -190,8 +282,8 @@ export declare interface IExtensionSDK {
|
|
|
190
282
|
*/
|
|
191
283
|
getTenantUrl(): string | null;
|
|
192
284
|
/**
|
|
193
|
-
* Platform API origin derived from handshake `baseUrl
|
|
194
|
-
* `null` until connected.
|
|
285
|
+
* Platform API origin derived from handshake `baseUrl`.
|
|
286
|
+
* `null` until connected, or when `extensionDetails.baseUrl` was omitted.
|
|
195
287
|
*/
|
|
196
288
|
getApiUrl(): string | null;
|
|
197
289
|
/**
|
|
@@ -203,8 +295,9 @@ export declare interface IExtensionSDK {
|
|
|
203
295
|
* @typeParam T - Expected JSON response body.
|
|
204
296
|
* @param endpoint - Root-relative API path.
|
|
205
297
|
* @param options - Standard fetch options.
|
|
206
|
-
* @throws When not connected,
|
|
207
|
-
*
|
|
298
|
+
* @throws When not connected, handshake did not include `authToken` and
|
|
299
|
+
* `extensionDetails` (`baseUrl`, `tenantDomain`), the endpoint is invalid,
|
|
300
|
+
* the request fails, or the response is not successful JSON.
|
|
208
301
|
*/
|
|
209
302
|
apiCall<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
210
303
|
/**
|
|
@@ -247,11 +340,43 @@ export declare interface IExtensionSDK {
|
|
|
247
340
|
emitNavigationChange(payload: NavigationChangePayload): void;
|
|
248
341
|
}
|
|
249
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Parent-frame counterpart to {@link IExtensionSDK}.
|
|
345
|
+
*
|
|
346
|
+
* Listens for child messages and replies with the shared wire protocol.
|
|
347
|
+
* Create one instance per iframe.
|
|
348
|
+
*/
|
|
349
|
+
export declare interface IExtensionSDKHost {
|
|
350
|
+
/**
|
|
351
|
+
* Attaches the child message listener. Safe to call once; no-ops if already
|
|
352
|
+
* started or destroyed.
|
|
353
|
+
*/
|
|
354
|
+
start(): void;
|
|
355
|
+
/**
|
|
356
|
+
* Tears down the listener. The instance cannot be restarted after destroy.
|
|
357
|
+
*/
|
|
358
|
+
destroy(): void;
|
|
359
|
+
/**
|
|
360
|
+
* Asks the child to open page settings UI with the given values.
|
|
361
|
+
*
|
|
362
|
+
* Wire: `LOAD_PAGE_SETTINGS` (fire-and-forget).
|
|
363
|
+
*/
|
|
364
|
+
emitLoadPageSettings(settings: PageSettings | null): void;
|
|
365
|
+
}
|
|
366
|
+
|
|
250
367
|
/** Thrown when `tenantUrl` is missing or not a safe postMessage origin. */
|
|
251
368
|
export declare class InvalidOriginError extends Error {
|
|
252
369
|
constructor(message: string);
|
|
253
370
|
}
|
|
254
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Returns whether `urlRaw` is a valid HTTPS extension URL.
|
|
374
|
+
*
|
|
375
|
+
* When `checkOrigin` is provided, the URL's origin must also pass that predicate
|
|
376
|
+
* (e.g. hostname ends with `.kadanza.app`).
|
|
377
|
+
*/
|
|
378
|
+
export declare function isValidExtensionUrl(urlRaw: string | null | undefined, checkOrigin?: (origin: string) => boolean): boolean;
|
|
379
|
+
|
|
255
380
|
/** Payload for `NAVIGATION_CHANGE` (child → parent). */
|
|
256
381
|
export declare interface NavigationChangePayload {
|
|
257
382
|
path: string;
|
|
@@ -265,6 +390,16 @@ export declare interface PageSettingsUpdatedPayload {
|
|
|
265
390
|
success: boolean;
|
|
266
391
|
}
|
|
267
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Posts a typed extension message to an embedded child frame.
|
|
395
|
+
*
|
|
396
|
+
* @param contentWindow - The iframe's `contentWindow`.
|
|
397
|
+
* @param origin - Target origin for `postMessage` (extension origin).
|
|
398
|
+
* @param type - Wire event type from {@link CONNECTION_EVENTS}.
|
|
399
|
+
* @param payload - Optional message payload.
|
|
400
|
+
*/
|
|
401
|
+
export declare function postToChild(contentWindow: Window, origin: string, type: ConnectionEvent, payload?: unknown): void;
|
|
402
|
+
|
|
268
403
|
/**
|
|
269
404
|
* Reads the parent-supplied `tenantUrl` from a URL search string.
|
|
270
405
|
*
|
|
@@ -291,6 +426,15 @@ export declare interface RequestOptions {
|
|
|
291
426
|
*/
|
|
292
427
|
export declare function resolveAllowedOrigin(tenantUrl: string | null): string;
|
|
293
428
|
|
|
429
|
+
/**
|
|
430
|
+
* Subscribes to `message` events from a child frame at `origin`.
|
|
431
|
+
*
|
|
432
|
+
* Ignores events from other origins and payloads without a `type` field.
|
|
433
|
+
*
|
|
434
|
+
* @returns Unsubscribe function.
|
|
435
|
+
*/
|
|
436
|
+
export declare function subscribeToChildMessages(origin: string, handler: HostMessageHandler): () => void;
|
|
437
|
+
|
|
294
438
|
/** Payload for `UPDATE_PAGE_SETTINGS` (child → parent). */
|
|
295
439
|
export declare interface UpdatePageSettingsPayload {
|
|
296
440
|
settings: PageSettings;
|